-
Notifications
You must be signed in to change notification settings - Fork 2
/
server.js
57 lines (46 loc) · 1.15 KB
/
server.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
const express = require('express');
const logger = require('morgan');
const cors = require('cors');
const helmet = require('helmet');
const basicAuth = require('express-basic-auth');
const Agendash = require('agendash');
const config = require('./config');
const errorHandler = require('./utils/errorHandler');
const agenda = require('./agenda');
require('./utils/database');
// Express App
const app = express();
// parse application/json
app.use(express.json());
// Use default logger for now
app.use(logger('combined'));
app.use(cors());
app.use(
helmet({
contentSecurityPolicy: false,
frameguard: false,
}),
);
app.use(
'/dash',
basicAuth({
users: {
admin: config.AGENDA_CRON_PASSWORD,
},
challenge: true,
}),
Agendash(agenda),
);
// This is to check if the service is online or not
app.use('/ping', function (req, res) {
res.json({ reply: 'pong' });
res.end();
});
app.use(errorHandler);
// Here you set the PORT and IP of the server
const port = config.PORT || 8001;
const ip = config.IP || '127.0.0.1';
app.listen({ port, ip }, () =>
console.log(`🚀 Server ready at http://${ip}:${port}`),
);
module.exports = app;