-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp.ts
More file actions
53 lines (45 loc) · 1.45 KB
/
app.ts
File metadata and controls
53 lines (45 loc) · 1.45 KB
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
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
import express from 'express';
import cors from 'cors';
import helmet from 'helmet';
import { errorMiddleware } from './middleware/error.middleware.js';
import { rateLimitMiddleware } from './middleware/rateLimit.middleware.js';
import { authRoutes } from './routes/auth.routes.js';
import { tradingRoutes } from './routes/trading.routes.js';
import { marketRoutes } from './routes/market.routes.js';
import { leaderboardRoutes } from './routes/leaderboard.routes.js';
import { accountRoutes } from './routes/account.routes.js';
import { stressTestRoutes } from './routes/stressTest.routes.js';
export const app = express();
// Security middleware
app.use(helmet());
app.use(cors({
origin: [
'http://localhost:5173',
'http://localhost:3000',
'https://trading-sim-hl.netlify.app',
'https://tradeterm.app',
'https://www.tradeterm.app'
],
credentials: true,
}));
// Body parsing
app.use(express.json());
// Rate limiting
app.use(rateLimitMiddleware);
// Health check
app.get('/health', (req, res) => {
res.json({ status: 'ok', timestamp: Date.now() });
});
// API routes
app.use('/api/auth', authRoutes);
app.use('/api/trading', tradingRoutes);
app.use('/api/market', marketRoutes);
app.use('/api/leaderboard', leaderboardRoutes);
app.use('/api/account', accountRoutes);
app.use('/api/stress-test', stressTestRoutes);
// Error handling
app.use(errorMiddleware);
// 404 handler
app.use((req, res) => {
res.status(404).json({ error: 'Not found' });
});