refactor: Move backend to typescript

This commit is contained in:
2026-06-06 23:36:54 +05:30
parent 012db524cb
commit a1e01cfdc3
6 changed files with 817 additions and 42 deletions

View File

@@ -55,10 +55,10 @@ The codebase is split into two main sections:
- [package.json](file:///home/sortedcord/Projects/brew/package.json) (dependencies and scripts)
- [src/App.jsx](file:///home/sortedcord/Projects/brew/src/App.jsx) (routing and layout)
- [src/AuthContext.jsx](file:///home/sortedcord/Projects/brew/src/AuthContext.jsx) (authentication state and backend communication)
- **Backend**: An Express application located in the [server/](file:///home/sortedcord/Projects/brew/server/) directory. Key files include:
- **Backend**: An Express application located in the [server/](file:///home/sortedcord/Projects/brew/server/) directory, written in TypeScript. Key files include:
- [server/package.json](file:///home/sortedcord/Projects/brew/server/package.json) (backend dependencies and scripts)
- [server/index.js](file:///home/sortedcord/Projects/brew/server/index.js) (Express application setup, routes, and authentication middleware)
- [server/db.js](file:///home/sortedcord/Projects/brew/server/db.js) (PostgreSQL connection and table initialization)
- [server/src/index.ts](file:///home/sortedcord/Projects/brew/server/src/index.ts) (Express application setup, routes, and authentication middleware)
- [server/src/db.ts](file:///home/sortedcord/Projects/brew/server/src/db.ts) (PostgreSQL connection and table initialization)
## Prerequisites
@@ -194,16 +194,19 @@ When deploying the Brew application to a production environment, follow these gu
- `PORT=8080` (or whichever port is provided by your host)
- `DATABASE_URL=postgresql://<db_user>:<db_password>@<db_host>:<db_port>/<db_name>?sslmode=require`
- `JWT_SECRET=your_long_random_production_secret` (generate a secure 32-byte key using `openssl rand -base64 32`)
- **Process Management**: Use a process manager like **PM2** to run the backend node process, keep it alive, and handle automatic clustering or restarts:
- **Process Management**: Compile TypeScript and use a process manager like **PM2** to run the backend node process, keep it alive, and handle automatic clustering or restarts:
```bash
# Install PM2 globally
npm install -g pm2
# Build the project
npm run build --prefix server
# Start the backend server
pm2 start server/index.js --name "brew-backend"
pm2 start server/dist/index.js --name "brew-backend"
```
- **Restrict CORS**: In [server/index.js](file:///home/sortedcord/Projects/brew/server/index.js), configure the `cors` middleware to only accept requests from your frontend production domain:
```javascript
- **Restrict CORS**: In [server/src/index.ts](file:///home/sortedcord/Projects/brew/server/src/index.ts), configure the `cors` middleware to only accept requests from your frontend production domain:
```typescript
app.use(cors({ origin: 'https://yourfrontenddomain.com' }));
```