-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbackend.js
51 lines (35 loc) · 1.03 KB
/
backend.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
require('dotenv').config();
var express = require('express');
var basicAuth = require('express-basic-auth');
var cors = require('cors');
var agendash = require('agendash');
var scheduler = require('./scheduler/scheduler');
var apiRoutes = require('./api/routes');
var mongoose = require('mongoose');
var dbProvider = require('./utils/dbConfig');
var dbConnectionString = dbProvider.getDBUrl().concat("/" , dbProvider.getEnv());
// Main routine
// start express
var app = express()
var port = process.env.PORT;
// start db
mongoose.connect(dbConnectionString, { useNewUrlParser: true });
// start scheduler
scheduler.run();
// start routes
app.use(cors());
app.get('/', (req, res) => {
res.send("Welcome to the Backend");
});
app.use('/dashboard', basicAuth({
users: {
admin: process.env.PASSWORD,
},
challenge: true,
realm: 'stuvbackendadmin',
}), agendash(scheduler.get()));
app.use('/api', apiRoutes);
// init express
app.listen(parseInt(port), () => {
console.log("Backend running on port: " + port);
});