-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
43 lines (33 loc) · 904 Bytes
/
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
'use strict';
const fs = require('fs');
const path = require('path');
const express = require('express');
const bodyParser = require('body-parser');
const morgan = require('morgan');
const cors = require('cors');
const config = require('./config');
const api = require('./api');
const app = express();
app.use(express.urlencoded({ extended: false }));
app.use(cors());
app.use(bodyParser.json());
// log to file
app.use(morgan('combined', {
stream: fs.createWriteStream(
path.join(__dirname, 'access.log'),
{ flags: 'a' }
)
}));
// log to console
app.use(morgan('dev'));
app.use('/', express.static(path.join(__dirname, 'client')));
app.use('/api', api);
app.use(function (err, req, res, next) {
console.error(err.stack);
res.status(500).end();
});
app.listen(config.PORT, () => {
console.log(
`listening at http://localhost:${config.PORT} (${config.MODE} mode)`
);
});