Skip to content

Commit bb8fa3f

Browse files
authored
Merge branch 'main' into codex/fix-backend-issues-for-sponsor-system
2 parents f750d0f + 02043b6 commit bb8fa3f

26 files changed

Lines changed: 619 additions & 244 deletions

.github/workflows/backend.yml

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
name: Backend CI
2+
3+
on:
4+
pull_request:
5+
paths:
6+
- 'backend/**'
7+
8+
jobs:
9+
backend-check:
10+
runs-on: ubuntu-latest
11+
12+
steps:
13+
- name: Checkout repo
14+
uses: actions/checkout@v4
15+
16+
- name: Setup Node
17+
uses: actions/setup-node@v4
18+
with:
19+
node-version: 20
20+
21+
- name: Install backend dependencies
22+
run: npm install
23+
working-directory: backend
24+
25+
- name: Start backend briefly
26+
run: |
27+
node backend/server.js &
28+
sleep 5
29+
kill $! || true
30+
31+
- name: Run security audit
32+
run: npm audit || true

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,3 +27,6 @@ dist-ssr
2727
*.njsproj
2828
*.sln
2929
*.sw?
30+
31+
# Local backend datastore
32+
backend/data/

README.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,9 @@ BroCode Spot is a full-stack web application designed to streamline group orderi
8383
VITE_SUPABASE_URL=your_supabase_project_url
8484
VITE_SUPABASE_ANON_KEY=your_supabase_anon_key
8585
```
86+
### Environment Validation
87+
The backend validates environment variables at startup.
88+
If required variables are missing or invalid, the server will stop immediately with a clear error message.
8689

8790
4. **Set up Supabase**
8891

backend/README.md

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# Backend API
22

3-
A minimal Node.js backend for BroCode Spot backed by a persistent SQLite database.
3+
A minimal Node.js backend for BroCode Spot backed by a persistent JSON file database.
44

55
## Start
66

@@ -14,8 +14,8 @@ Server starts at `http://localhost:4000` by default.
1414

1515
### Issue #26: Move from in-memory store to persistent DB
1616

17-
- Uses `node:sqlite` with a local database file at `backend/data/brocode.sqlite`.
18-
- You can override the location with `BROCODE_DB_PATH=/custom/path.sqlite npm run backend`.
17+
- Uses a local JSON database file at `backend/data/brocode.json`.
18+
- You can override the location with `BROCODE_DB_PATH=/custom/path.json npm run backend`.
1919
- On first start, seed data is inserted for users, spots, catalog items, and a sample order.
2020
- New orders are validated against DB data (known `spotId`, `userId`, `productId`) and item pricing is always derived from catalog prices in the database.
2121

@@ -24,6 +24,16 @@ Server starts at `http://localhost:4000` by default.
2424
- Passwords are stored as salted `scrypt` hashes (not plaintext).
2525
- Legacy plaintext user passwords are auto-migrated to hashed values on successful login.
2626

27+
### Issue #29: Protect login endpoint from brute-force attempts
28+
29+
- Login is now rate-limited per `IP + username` key.
30+
- Defaults: 5 failed attempts within 15 minutes triggers a 15 minute temporary block (`429`).
31+
- Configure via env vars:
32+
- `LOGIN_RATE_LIMIT_MAX_ATTEMPTS`
33+
- `LOGIN_RATE_LIMIT_WINDOW_MS`
34+
- `LOGIN_RATE_LIMIT_BLOCK_MS`
35+
36+
2737
## Available endpoints
2838

2939
- `GET /api/health`
@@ -34,6 +44,7 @@ Server starts at `http://localhost:4000` by default.
3444
- `GET /api/orders?spotId=...&userId=...`
3545
- `POST /api/orders`
3646
- `GET /api/bills/:spotId`
47+
- `DELETE /api/users/:userId` (removes the user and all related records)
3748

3849
## Example login payload
3950

backend/data/brocode.sqlite

4 KB
Binary file not shown.

backend/data/brocode.sqlite-shm

32 KB
Binary file not shown.

backend/data/brocode.sqlite-wal

161 KB
Binary file not shown.

0 commit comments

Comments
 (0)