-
Notifications
You must be signed in to change notification settings - Fork 3
/
app.js
48 lines (34 loc) · 945 Bytes
/
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
44
45
46
47
48
const express = require('express');
const logger = require('morgan');
const helmet = require('helmet');
const path = require('path');
const cors = require('cors');
const rateLimit = require("express-rate-limit");
const publicPath = path.join(__dirname, '/doc');
const importer = require('./services/index');
const dataRouter = require('./routes/data');
const app = express();
// security modules
const limiter = rateLimit({
windowMs: 60 * 1000,
max: 100
});
app.use(cors({
origin: '*',
optionsSuccessStatus: 200
}));
app.use(helmet());
// Import utilities
importer.initialize();
const interval = setInterval(r => {
importer.getLatest();
}, 60000 * 60);
app.use(logger('dev'));
app.use(express.json());
app.use(express.urlencoded({extended: false}));
app.use(express.static(publicPath));
app.use('/data', limiter, dataRouter);
process.on('SIGTERM', () => {
clearInterval(interval);
});
module.exports = app;