-
Notifications
You must be signed in to change notification settings - Fork 18
/
app.js
68 lines (60 loc) · 2.1 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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
const express = require('express');
const cors = require('cors');
const helmet = require('helmet');
const morgan = require('morgan');
const compression = require('compression');
const cacheControl = require('express-cache-controller');
const { notFound, errorHandler } = require('./middlewares');
require('dotenv').config();
const app = express();
app.use(express.json());
app.use(cors());
app.use(helmet());
app.use(morgan('dev'));
app.use(cacheControl({ maxAge: 60, sMaxAge: 60 }));
app.use(compression());
const indonesiaRoutes = require('./Routes/index');
const indonesiaCSVRoutes = require('./Routes/csvRouter');
app.use('/api/indonesia', indonesiaRoutes);
app.use('/api/indonesia/csv', indonesiaCSVRoutes);
app.get('/', (req, res) => {
res.redirect('/api');
});
app.get('/api', (req, res) => {
const url = `${req.protocol}://${req.hostname}${req.hostname == 'localhost' ? `:${PORT}` : ''}`;
res.json({
"message": "Selamat Datang di API COVID-19 INDONESIA - Enjoy My Work",
"projects source": "https://github.com/Reynadi531/api-covid19-indonesia-v2",
"endpoints": {
"kumulatif": [
`${url}/api/indonesia`,
`${url}/api/indonesia/more`
],
"harian": [
`${url}/api/indonesia/harian`,
],
"provinsi": [
`${url}/api/indonesia/provinsi`,
`${url}/api/indonesia/provinsi/alt`,
`${url}/api/indonesia/provinsi/more`,
`${url}/api/indonesia/provinsi/harian`
],
"csv": {
"kumulatif": [
`${url}/api/indonesia/csv`,
],
"harian": [
`${url}/api/indonesia/csv/harian`,
],
"provinsi": [
`${url}/api/indonesia/csv/provinsi`,
`${url}/api/indonesia/csv/provinsi/alt`,
]
}
}
});
});
app.use(notFound);
app.use(errorHandler);
const PORT = process.env.PORT || 3000;
app.listen(PORT, () => console.log(`Listening at PORT ${PORT}`));