-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathserver.js
59 lines (53 loc) · 1.45 KB
/
server.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
require('dotenv-safe').config();
const express = require('express');
const bodyParser = require('body-parser');
const morgan = require('morgan');
const compression = require('compression');
const helmet = require('helmet');
const cors = require('cors');
const passport = require('passport');
const app = express();
const path = require('path');
const initMongo = require('./config/mongo');
// Setup express server port from ENV, default: 3000
app.set('port', process.env.PORT || 3000);
// Enable only in development HTTP request logger middleware
if (process.env.NODE_ENV === 'development') {
app.use(morgan('dev'));
}
// for parsing json
app.use(
bodyParser.json({
limit: '20mb',
}),
);
// for parsing application/x-www-form-urlencoded
app.use(
bodyParser.urlencoded({
limit: '20mb',
extended: true,
}),
);
// Init all other stuff
app.use(cors());
app.use(passport.initialize());
app.use(compression());
app.use(helmet());
app.use(express.static(`${__dirname}/public`));
app.set('views', path.join(__dirname, 'views'));
// app.engine('html', require('ejs').renderFile)
app.set('view engine', 'html');
app.use('/api', require('./routes/api/index.js'));
// Handle Production
// if (process.env.NODE_ENV === 'production') {
// static folder
// Handle SPA
app.get(/.*/, (req, res) => {
res.sendFile(`${__dirname}/public/index.html`);
});
// }
app.listen(app.get('port'), () => {
console.log(`Running port ${app.get('port')}`);
});
// Init MongoDB
initMongo();