forked from RafaelCasuso/vue-workshop-kairos
-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.js
65 lines (50 loc) · 1.55 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
const express = require('express');
const bodyParser = require('body-parser');
const bunyan = require('bunyan');
const history = require('connect-history-api-fallback');
// Logging everything
const logfilePath = __dirname + "/stay-bot-admin.log";
const loggerOpts = {
name: 'Stay Bot Admin',
serializers: {
req: bunyan.stdSerializers.req,
res: bunyan.stdSerializers.res,
err: bunyan.stdSerializers.err
},
streams: [{
stream: process.stdout,
level: 'info'
}, {
type: 'rotating-file',
path: logfilePath,
period: '1d',
count: 3,
level: 'info'
}]
};
const logger = require('bunyan')(loggerOpts);
process.on('SIGHUP', function () {
logger.reopenFileStreams();
});
const app = express();
app.use(history());
//Request logger
app.use(bodyParser.json());
app.use(bodyParser.urlencoded({extended: false}));
// Attaching app locals and utils to request
app.use(function (req, res, next) {
// Uncomment the next two lines to allow external API.
res.set('Access-Control-Allow-Origin', '*');
res.set('Access-Control-Expose-Headers', 'X-Requested-With, Content-Type, Accept, Origin, Authorization');
res.set('Access-Control-Allow-Methods', 'HEAD, OPTIONS, GET, POST, DELETE, PUT, PATCH');
res.set('X-Powered-By', 'Lightning-bolt');
logger.info({req: req, res: res});
req.logger = logger;
next();
});
app.use(express.static('dist'));
module.exports = app;
let server = null;
server = app.listen(process.env.PORT || 8080, function(){
logger.info('PWA is listening at ' + server.address().port + '/');
})