-
Notifications
You must be signed in to change notification settings - Fork 2
/
index.js
65 lines (48 loc) · 1.63 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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
if(process.env.NODE_ENV !== 'production'){
require('dotenv').load();
}
const winston = require('winston');
require('winston-mongodb');
require('express-async-errors');
const morgan = require('morgan');
const helmet = require('helmet');
const express = require('express');
const expressLayouts = require('express-ejs-layouts')
const app = express();
app.set('view engine', 'ejs');
app.use(expressLayouts);
app.set('views', __dirname + '/views')
app.set('layout','layouts/layout')
app.use(express.static('public'));
const swaggerUi = require ('swagger-ui-express');
const swaggerDocument = require('./swagger.json');
app.use('/api-docs',swaggerUi.serve, swaggerUi.setup(swaggerDocument));
require('./startup/logging'); // this has to be added first for logging
require('./startup/routes')(app);
require('./startup/db')();
//require('./startup/config')();
require('./startup/prod')(app);
console.log("Your current environment is: " + app.get('env'))
// if (app.get('env') === 'development'){
// app.use(morgan('combined'));
// console.log("Morgan logging enabled");
// }
winston.handleExceptions(
new winston.transports.Console({
colorize: true,
prettyPrint: true
}),
new winston.transports.File({
filename: 'logUncaughtExecptions.log'
}));
process.on('unhandledRejection', (ex) => {
throw ex;
})
winston.add(winston.transports.File, {
filename: 'logfile.log'
});
winston.add(winston.transports.MongoDB, {
db: 'mongodb://localhost/lotto'
});
const port = process.env.PORT || 3000;
app.listen(port, () => winston.info(`The App is listening on port ${port} and awaiting your command, Kenny`))