-
Notifications
You must be signed in to change notification settings - Fork 0
/
server.js
76 lines (64 loc) · 1.99 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
68
69
70
71
72
73
74
75
76
var path = require("path");
var webpack = require("webpack");
var express = require("express");
var devMiddleware = require("webpack-dev-middleware");
var hotMiddleware = require("webpack-hot-middleware");
var fs = require("fs");
const perf_dev = process.argv[2] === "perf-dev";
var ProgressPlugin = require("webpack/lib/ProgressPlugin");
var config = require("./webpack.config.js")({prod: false, perf_dev});
var app = express();
var compiler = webpack(config);
var https = require("https");
var http = require("http");
compiler.apply(
new ProgressPlugin(function(percentage, msg) {
process.stdout.write(
(percentage * 100).toFixed(2) +
"% " +
msg +
" \033[0G"
);
})
);
app.use(
devMiddleware(compiler, {
publicPath: config.output.publicPath,
historyApiFallback: true
})
);
app.use(hotMiddleware(compiler));
// app.get("*", function(req, res) {
// res.sendFile(path.join(__dirname, "app/assets/index.html"));
// });
app.use("*", function(req, res, next) {
var filename = path.join(compiler.outputPath, "index.html");
compiler.outputFileSystem.readFile(filename, function(err, result) {
if (err) {
return next(err);
}
res.set("content-type", "text/html");
res.send(result);
res.end();
});
});
var options = {
key: fs.readFileSync("./ssl/server.key"),
cert: fs.readFileSync("./ssl/server.crt")
};
http.createServer(app).listen(8080);
https.createServer(options, app).listen(8085);
console.log("Listening at http://localhost:8080/ or https://localhost:8085/");
// new WebpackDevServer(compiler, {
// publicPath: config.output.publicPath,
// hot: true,
// historyApiFallback: true,
// quiet: false,
// stats: {colors: true},
// port: 8080
// }).listen(8080, '0.0.0.0', function (err, result) {
// if (err) {
// console.log(err);
// }
// console.log('Listening at 0.0.0.0:8080');
// });