-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.ts
More file actions
30 lines (23 loc) · 934 Bytes
/
index.ts
File metadata and controls
30 lines (23 loc) · 934 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
import express from "express";
import cors from "cors";
import authRoutes from "./routes/auth";
import expenseRoutes from "./routes/expenses";
import reportRoutes from "./routes/reports";
const app = express();
const PORT = process.env.PORT || 3001;
// BUG: Wildcard CORS — allows any origin to make authenticated requests
app.use(cors());
app.use(express.json());
app.use("/api/auth", authRoutes);
app.use("/api/expenses", expenseRoutes);
app.use("/api/reports", reportRoutes);
// BUG: No rate limiting on any endpoints — susceptible to brute-force attacks
// BUG: Global error handler leaks stack traces to the client in production
app.use((err: any, _req: express.Request, res: express.Response, _next: express.NextFunction) => {
console.error(err);
res.status(500).json({ error: err.message, stack: err.stack });
});
app.listen(PORT, () => {
console.log(`Server running on port ${PORT}`);
});
export default app;