-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathapp.js
33 lines (23 loc) · 1.01 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
const express = require('express');
const cors = require('cors');
const logger = require('./src/logger');
const updateChangefilesExample = require('./src/controllers/changefiles');
const routerSnapshots = require('./src/routers/snapshots');
const routerChangeFiles = require('./src/routers/changefiles');
const routerPing = require('./src/routers/ping');
// start server
const app = express();
app.use('/snapshots', cors());
app.use(express.json());
app.use(routerSnapshots);
app.use(routerChangeFiles);
app.use(routerPing);
// Errors and unknown routes
app.use((req, res, next) => res.status(404).json({ message: `Cannot ${req.method} ${req.originalUrl} - this route does not exist.` }));
app.use((error, req, res, next) => res.status(500).json({ message: error.message }));
app.listen(3000, async () => {
logger.info(`[express]: fakeUnpaywall service listening on 3000 in [${process.uptime().toFixed(2)}]s`);
await updateChangefilesExample('day');
await updateChangefilesExample('week');
});
module.exports = app;