-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
50 lines (40 loc) · 1.34 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
const express = require('express');
const path = require('path');
const cookieParser = require('cookie-parser');
const session = require('express-session');
const bodyParser = require('body-parser');
const jwt = require('jsonwebtoken');
var flash = require('connect-flash');
const passport = require('passport');
const localStrategy = require('passport-local').Strategy;
const app = express();
// ENV setup
require('./config');
const appConfig = require('./config/config');
//App configuration and middleware
app.use(bodyParser.json());
app.use(bodyParser.urlencoded({extended: false}));
app.use(cookieParser());
app.use(session(appConfig.expressSession));
app.use(flash());
app.use(passport.initialize());
app.use(passport.session());
// passport auth
require('./config/passport')(passport, localStrategy);
// Static / public path
app.use(express.static('dist'))
// Router setup
require('./server/router/')(app, passport, localStrategy, jwt);
// Catch 404 and forward to error handler
app.use((req, res, next) => {
const err = new Error('404 Page Not Found');
err.status = 404;
next(err);
});
// Error handler
app.use((err, req, res, next) => { // eslint-disable-line no-unused-vars
res.status(err.status || 500).json({ error: err.message });
});
// app listen
const port = process.env.PORT || 3000;
app.listen(port);