-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathindex.js
More file actions
41 lines (32 loc) · 848 Bytes
/
index.js
File metadata and controls
41 lines (32 loc) · 848 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
32
33
34
35
36
37
38
39
40
41
require('dotenv').config();
const express = require('express');
const cors = require('cors');
const bodyParser = require('body-parser');
const { statuses } = require(`./handlers/configs/${process.env.CONFIG}`);
const { prewarmHandler } = require('./handlers');
const app = express();
const port = 8000;
app.use(bodyParser.json());
app.use(
cors({
origin: '*',
headers: '*',
methods: '*',
})
);
app.use((error, req, res, next) => {
if (error instanceof SyntaxError) {
res.status(400).json({ error: statuses[400] });
} else {
next();
}
});
const routes = require('./routes');
app.use(Object.values(routes));
app.use((req, res) => {
res.status(405).json({ error: statuses[405] });
});
app.listen(port, () => {
console.log(`API running at http://localhost:${port}`);
setInterval(prewarmHandler, 60000);
});