-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathserver.js
43 lines (36 loc) · 1.23 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
const express = require('express');
const app = express();
const path = require('path');
const expressHandlebars = require('express-handlebars');
const handlebars = expressHandlebars.create({
defaultLayout: 'main',
partialsDir: [
'views/components/',
],
});
// Webpack configuration
const webpackConfig = require('./webpack.config.js');
const webpack = require('webpack');
const webpackDevMiddleware = require('webpack-dev-middleware');
const webpackHotMiddleware = require('webpack-hot-middleware');
const compiler = webpack(webpackConfig);
// Configure handlebars
app.engine('handlebars', handlebars.engine);
app.set('view engine', 'handlebars');
// App options
app.set('strict routing', true);
app.disable('x-powered-by');
// Webpack injection
app.use(webpackDevMiddleware(compiler, {
noInfo: true,
publicPath: webpackConfig.output.publicPath,
}));
app.use(webpackHotMiddleware(compiler));
// Static assets
app.use(express.static(path.resolve(__dirname, 'static/')));
// Routing
app.use(require('./routes/router.js'));
// Start listening
app.listen(3000, () => {
console.log('Server listening on port 3000');
});