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
46 changes: 46 additions & 0 deletions .github/instructions/adding_route.md.instructions.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
# Checklist for Adding a New Route

## Core Handler & Logic
- [ ] Create handler file in `src/handlers/` (e.g., `delete_game.ts`)
- Import required dependencies (StatusCodes, MongoClient, Env, shared utilities)
- Create database operation function
- Create handler function with proper signature: `(req: Request, env: Env, origin: string | null, getCorsHeaders: (...) => HeadersInit)`
- Add parameter validation
- Implement try-catch with proper error handling
- Return JSON responses with appropriate status codes and CORS headers

## Tests
- [ ] Create test file in `src/tests/` (e.g., `delete_game.test.ts`)
- Mock MongoDB utilities
- Define getCorsHeaders and mockEnv
- Add parameter validation tests
- Add successful request tests
- Add CORS header tests
- Add error handling tests
- Add edge case tests

## Validators (if needed)
- [ ] Add validation function to `src/shared/validators.ts` (e.g., `validateGameParameters`)
- [ ] Add validator tests to `src/tests/validators.test.ts`
- [ ] Export validator from `src/shared/index.ts`

## Routing
- [ ] Export handler from `src/handlers/index.ts`
- [ ] Import handler in `src/router.ts`
- [ ] Add route handler in `src/router.ts` with proper method and path
- [ ] Update CORS methods in `getCorsHeaders` if using new HTTP method
- [ ] Update router tests in `src/tests/router.test.ts` (especially CORS tests)

## Scripts (optional)
- [ ] Create script file in `scripts/` (e.g., `delete-game.ts`)
- Add argument parsing
- Add safety confirmations for destructive operations
- Include error handling and connection cleanup
- [ ] Add script to `package.json` scripts section
- [ ] Load environment variables with dotenv if needed

## Verification
- [ ] Run `npm test` - all tests passing
- [ ] Run `npm run lint` - no linting errors
- [ ] Test manually with script or API client
- [ ] Verify CORS headers work correctly
10 changes: 10 additions & 0 deletions .github/workflows/deploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,16 @@ jobs:
run: echo "$API_AUTH_TOKEN" | npx wrangler secret put API_AUTH_TOKEN --env $ENV
env:
API_AUTH_TOKEN: ${{ secrets.API_AUTH_TOKEN }}

- name: Set MongoDB URI secret
run: echo "$MONGODB_URI" | npx wrangler secret put MONGODB_URI --env $ENV
env:
MONGODB_URI: ${{ secrets.MONGODB_URI }}

- name: Set MongoDB Database secret
run: echo "$MONGODB_DATABASE" | npx wrangler secret put MONGODB_DATABASE --env $ENV
env:
MONGODB_DATABASE: ${{ secrets.MONGODB_DATABASE }}

- name: Deploy Worker
run: |
Expand Down
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,4 @@
.env
node_modules/
node_modules/
scripts/config.ts
.wrangler
Loading