-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
51 lines (42 loc) · 1.2 KB
/
index.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
/**
* Created by Wolke on 09.06.2017.
*/
const express = require('express');
const bodyParser = require('body-parser');
const loader = require('docker-config-loader');
const winston = require('winston');
const cors = require('cors');
const genericRouter = require('./routes/generic.router');
const rssRouter = require('./routes/rss.router');
winston.remove(winston.transports.Console);
winston.add(winston.transports.Console, {
'timestamp': true,
'colorize': true
});
let config;
try {
config = loader({secretName: 'secret_name', localPath: './config/main.json'});
} catch (e) {
winston.error(e);
winston.error('Failed to require config!');
process.exit(1);
}
let mongoose = require('mongoose');
mongoose.Promise = Promise;
mongoose.connect(config.dburl, (err) => {
if (err) {
winston.error("Unable to connect to Mongo Server!");
process.exit(1);
}
});
let app = express();
app.use((req, res, next) => {
req.config = config;
next();
});
app.use(bodyParser.json());
app.use(bodyParser.urlencoded({extended: true}));
app.use(cors());
app.use(genericRouter, rssRouter);
app.listen(config.port, config.host);
winston.info(`Server started ${config.host}:${config.port}`);