-
Notifications
You must be signed in to change notification settings - Fork 1
/
app.js
43 lines (33 loc) · 1.11 KB
/
app.js
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
/* eslint-disable global-require */
/* eslint-disable no-console */
const express = require('express');
const app = express();
const path = require('path');
const { socket } = require('./socket');
const { rateLimiter } = require('./utils/utils');
app.use(express.json());
app.use(express.urlencoded({ extended: false }));
app.use(express.static('public'));
const { NODE_ENV, PORT_TEST, PORT } = process.env;
const port = NODE_ENV === 'test' ? PORT_TEST : PORT;
const server = app.listen(port, () => {
console.log(`app running on port ${port}`);
});
socket.init(server);
const apiVersion = process.env.API_VERSION;
app.use(`/${apiVersion}`, rateLimiter,
[
require('./server/route/user_route'),
require('./server/route/share_route'),
require('./server/route/automation_route'),
require('./server/route/trip_route'),
]);
// eslint-disable-next-line no-unused-vars
app.use((err, req, res, next) => {
console.log(err);
res.status(500).send('server error, please try again later');
});
app.use((req, res) => {
res.status(404).sendFile(path.join(__dirname, './public', '404.html'));
});
module.exports = app;