-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdev-server.js
More file actions
46 lines (38 loc) · 1.11 KB
/
dev-server.js
File metadata and controls
46 lines (38 loc) · 1.11 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
45
46
var appBase = './game'
var __PORT__ = 9001;
var path = require('path');
var request = require('request');
var webpack = require('webpack');
var webpackConfig = require('./webpack.config');
var proxy = require('express-http-proxy');
var express = require('express');
var url = require('url');
var app = express();
var compiler = webpack(webpackConfig);
var publicPath = webpackConfig[0].output.publicPath;
app.use(require('webpack-dev-middleware')(compiler, {
publicPath: publicPath,
contentBase: path.resolve(__dirname, 'build/' + appBase.path),
hot: true,
quiet: false,
noInfo: false,
lazy: false,
stats: true,
}));
app.use(require('webpack-hot-middleware')(compiler));
app.use(function (req, res, next) {
var urlPath = url.parse(req.url).pathname;
var ext = path.extname(urlPath);
if ((ext === '' || ext === '.html') && req.url !== '/') {
req.pipe(request('http://' + req.hostname + ':' + __PORT__)).pipe(res);
} else {
next();
}
});
app.listen(__PORT__, function (err, result) {
if (err) {
console.log(err);
return null;
}
console.log('Listening at localhost:' + __PORT__);
});