Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions .eslintrc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
module.exports = {
extends: ['react-app', 'react-app/jest', 'prettier'],
rules: {
'no-console': 'warn',
},
ignorePatterns: ['build/', 'node_modules/', '/*.config.js'],
};
101 changes: 101 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
name: CI

on:
push:
branches:
- main
- 'feature/**'
- 'fix/**'
pull_request:
branches:
- main
workflow_dispatch:

jobs:
lint:
name: Lint
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v4

- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: '20.x'
cache: 'npm'

- name: Install dependencies
run: npm ci

- name: Run ESLint
run: npm run lint

format:
name: Format Check
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v4

- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: '20.x'
cache: 'npm'
Comment thread
BenGWeeks marked this conversation as resolved.

- name: Install dependencies
run: npm ci

- name: Check Prettier formatting
run: npm run format:check

build:
name: Build
runs-on: ubuntu-latest
needs: [lint, format, typecheck]
steps:
- name: Checkout repository
uses: actions/checkout@v4

- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: '20.x'
cache: 'npm'

- name: Install dependencies
run: npm ci

- name: Build application
run: npm run build
env:
# CI=false prevents React from treating warnings as errors
# This is necessary because react-scripts exits with error on any warning in CI mode
CI: false
Comment thread
BenGWeeks marked this conversation as resolved.

- name: Upload build artifacts
uses: actions/upload-artifact@v4
with:
name: build
path: build/
retention-days: 7

typecheck:
name: TypeScript Check
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v4

- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: '20.x'
cache: 'npm'

- name: Install dependencies
run: npm ci

- name: Run TypeScript compiler
run: npx tsc --noEmit
41 changes: 41 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,34 @@ The page will reload when you make changes.

You may also see any lint errors in the console.

### Linting

Run ESLint to check for code quality issues:

```
npm run lint
```

To automatically fix linting issues:

```
npm run lint:fix
```

### Formatting

Check if code is properly formatted with Prettier:

```
npm run format:check
```

To automatically format all files:

```
npm run format
```

### Testing

To run the app in the interactive watch mode, run:
Expand All @@ -66,3 +94,16 @@ This builds the app for production to the `build` folder. It correctly bundles R
The build is minified and the filenames include the hashes. Your app is ready to be deployed!

See the section about [deployment](https://facebook.github.io/create-react-app/docs/deployment) for more information.

## CI/CD

This project uses GitHub Actions for continuous integration. On every push and pull request to `main`, the following checks are automatically run:

| Check | Description |
|-------|-------------|
| **Lint** | ESLint checks for code quality issues |
| **Format** | Prettier formatting verification |
| **TypeScript** | Type checking with `tsc --noEmit` |
| **Build** | Verifies the application builds successfully |

All checks must pass before merging pull requests.
34 changes: 17 additions & 17 deletions backend/authMiddleware.js
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
// filepath: /c:/projects/ZapVibes/tabs/backend/authMiddleware.js
const authMiddleware = (req, res, next) => {
// Example: Check for a token in the request headers
const token = req.headers['authorization'];
if (!token) {
return res.status(401).json({ message: 'Unauthorized' });
}
// Verify the token (this is a placeholder, replace with actual token verification logic)
if (token !== 'your-secret-token') {
return res.status(401).json({ message: 'Unauthorized' });
}
// If token is valid, proceed to the next middleware or route handler
next();
};
module.exports = authMiddleware;
// Example: Check for a token in the request headers
const token = req.headers['authorization'];

if (!token) {
return res.status(401).json({ message: 'Unauthorized' });
}

// Verify the token (this is a placeholder, replace with actual token verification logic)
if (token !== 'your-secret-token') {
return res.status(401).json({ message: 'Unauthorized' });
}

// If token is valid, proceed to the next middleware or route handler
next();
};

module.exports = authMiddleware;
9 changes: 6 additions & 3 deletions backend/server.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,17 +20,17 @@
const data = fs.readFileSync(dataFilePath, 'utf8');
return JSON.parse(data);
} catch (error) {
console.error('Error reading data file:', error);

Check warning on line 23 in backend/server.js

View workflow job for this annotation

GitHub Actions / Lint

Unexpected console statement
return { rewardName: 'sats' }; // Default reward name
}
};

// Function to write data to the JSON file
const writeData = (data) => {
const writeData = data => {
try {
fs.writeFileSync(dataFilePath, JSON.stringify(data, null, 2));
} catch (error) {
console.error('Error writing data file:', error);

Check warning on line 33 in backend/server.js

View workflow job for this annotation

GitHub Actions / Lint

Unexpected console statement
}
};

Expand All @@ -50,7 +50,10 @@
const data = readData();
data.rewardName = newRewardName;
writeData(data);
res.send({ message: 'Reward name updated successfully', rewardName: data.rewardName });
res.send({
message: 'Reward name updated successfully',
rewardName: data.rewardName,
});
} else {
res.status(400).send({ message: 'Invalid reward name' });
}
Expand All @@ -64,5 +67,5 @@
});

app.listen(port, () => {
console.log(`Server is running on http://localhost:${port}`);

Check warning on line 70 in backend/server.js

View workflow job for this annotation

GitHub Actions / Lint

Unexpected console statement
});
});
Loading
Loading