-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathserver.js
More file actions
44 lines (36 loc) · 1.09 KB
/
Copy pathserver.js
File metadata and controls
44 lines (36 loc) · 1.09 KB
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
const express = require('express');
const webpack = require('webpack');
const webpackDevMiddleware = require('webpack-dev-middleware');
const app = express();
const config = require('./webpack.config.js');
const compiler = webpack(config);
// Configure view engine and directory
app.set('view engine', 'ejs');
app.set('views', './templates');
app.use('/public', express.static('public'));
const model = {
mainJS: '',
mainCSS: '',
};
// Tell express to use the webpack-dev-middleware and use the webpack.config.js
// configuration file as a base.
app.use(
webpackDevMiddleware(compiler, {
publicPath: config.output.publicPath,
writeToDisk: true,
}),
);
// *****************************************
// ** Configure route here
// *****************************************
app.get('/', function(req, res) {
res.render('pages/home', model);
});
app.get('/:page', function(req, res) {
res.render('pages/' + req.params.page, model);
});
const PORT = process.env.PORT || 3000;
// Serve the files on port 3000.
app.listen(PORT, function() {
console.log('Example app listening on port 3000!\n');
});