-
Notifications
You must be signed in to change notification settings - Fork 2
/
index.js
67 lines (56 loc) · 2.13 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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
var express = require('express');
var cookieParser = require('cookie-parser');
var bodyParser = require('body-parser');
var cookieSession = require('cookie-session');
var colors = require('colors');
var setupAppConfig = require('./src/common/lib/helpers/appConfigHelper');
var DataContext = require('./src/server/lib/database/DataContext');
var dbUtils = require('./src/server/lib/database/dbUtils');
var expressReactViews = require('express-react-views');
var passport = require('passport');
var setupGoogleStrategy = require('./src/server/passport/googleStrategy');
var webpack = require('webpack');
var webpackMiddleware = require('webpack-dev-middleware');
var webpackHotMiddleware = require('webpack-hot-middleware');
var webpackConfig = require('./webpack.config.dev');
var appConfig = setupAppConfig(require('./app/appConfig'));
var dataContext = new DataContext(appConfig);
var app = express();
app.set('views', './src/server/views');
app.set('view engine', 'jsx');
app.engine('jsx', expressReactViews.createEngine({beautify: true}));
var webpackCompiler = webpack(webpackConfig);
passport.serializeUser(function (userId, done) {
done(null, userId);
});
passport.deserializeUser(function (userId, done) {
let repo = dataContext.getRepository('user');
repo.load({id: userId})
.then(u => done(null, u))
.catch(done);
});
passport.use(setupGoogleStrategy(dataContext));
app.use(webpackMiddleware(webpackCompiler));
app.use(webpackHotMiddleware(webpackCompiler));
app.use(express.static('./dist'));
app.use(cookieParser());
app.use(bodyParser.json());
app.use(bodyParser.urlencoded({
extended: true
}));
app.use(cookieSession({
name: 'session',
keys: ['key1', 'key2']
}));
app.use(passport.initialize());
app.use(passport.session());
// routes
var auth = require('./src/server/routes/auth');
var def = require('./src/server/routes/app');
var setupApi = require('./src/server/routes/api');
app.use('/auth', auth);
app.use('/api', setupApi(appConfig, dataContext));
app.get('*', def);
app.listen(3000, function () {
console.log(colors.green(`Hypersonic is running on port 3000. NODE_ENV: ${process.env.NODE_ENV}`));
});