-
Notifications
You must be signed in to change notification settings - Fork 1
/
server.js
67 lines (58 loc) · 2 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
60
61
62
63
64
65
66
67
//imports
import express from 'express';
import bodyParser from 'body-parser';
import mongoose from 'mongoose';
import passport from 'passport';
import session from 'express-session';
import flash from 'connect-flash';
import webpack from 'webpack'
import config from './config/config';
import webpackConfig from './webpack.config';
import routes from './config/routes';
import b from './config/bootstrapping';
const app = express();
const port = process.env.PORT || 1337;
mongoose.Promise = Promise;
app.use(bodyParser.json());
app.use(bodyParser.urlencoded({extended: true}));
// required for passport
// session secret
app.use(session({
secret: 'js4life',
resave: false,
saveUninitialized: false
})
);
app.use(passport.initialize());
app.use(passport.session()); // persistent login sessions
app.use(flash()); // use connect-flash for flash messages stored in session
//to be removed
app.use(express.static(__dirname + '/public')); // set the static files location /public/img will be /img for users
const compiler = new webpack(webpackConfig)
if (process.env.NODE_ENV == 'development') {
app.use(require("webpack-dev-middleware")(compiler, {
noInfo: true,stats: {colors: true},
publicPath: webpackConfig.output.publicPath,
}));
app.use(require("webpack-hot-middleware")(compiler));
}
//routes
app.use(routes);
//kickstart server
app.listen(port, () => {
mongoose.connect(config.db, config.dbOptions, (err) =>{
if(err){
console.log(err);
}
console.log(`Magic is happening on http://localhost:${port}`);
});
});
/* NB: This is considered bad practise because if something uncaught happens the state of the
server may have serious issues and should be restarted with fresh state.
Do not use this in production. For now, in very early alpha, this is useful for discovering the uncaught exceptions to later
handle these in the propper matter.
*/
process.on('uncaughtException', err => {
console.log(err);
});
export default app;