-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.js
More file actions
32 lines (24 loc) · 843 Bytes
/
index.js
File metadata and controls
32 lines (24 loc) · 843 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
31
const express = require('express');
const cors = require('cors');
const metricsRouter = require('./routes/metrics');
const twist = require('./lib/twist-config');
const app = express();
const PORT = process.env.PORT || 3001;
app.use(cors());
app.use(express.json());
// Apply rate limiting if enabled
app.use(twist.applyRateLimit);
app.use('/api/metrics', metricsRouter);
app.get('/health', (req, res) => {
res.json({ status: 'ok' });
});
app.use((err, req, res, next) => {
console.error(err.stack);
res.status(500).json({ error: 'Something went wrong!' });
});
app.listen(PORT, () => {
console.log(`API server running on http://localhost:${PORT}`);
console.log(`Available endpoints:`);
console.log(` GET http://localhost:${PORT}/api/metrics/dau`);
console.log(` GET http://localhost:${PORT}/api/metrics/top-orgs`);
});