forked from CybexDex/cybex-web
-
Notifications
You must be signed in to change notification settings - Fork 0
/
server.js
83 lines (72 loc) · 2.22 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
77
78
79
80
81
82
83
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 feathers = require("feathers");
const https = require("https");
const fs = require("fs");
const compress = require("compression");
const expressproxy = require('express-http-proxy');
// let proxyUrl = 'http://ieo-apitest.nbltrust.com:3049/';
let proxyUrl = 'https://ieo-apitest.cybex.io/';
// https://ieo-apitest.nbltrust.com/api/cybex/projects?limit=4&offset=0
var ProgressPlugin = require("webpack/lib/ProgressPlugin");
var config = require("./config/webpack.dev.js");
var app = express();
app.use(compress());
app.use('/api/', expressproxy(proxyUrl, {
proxyReqPathResolver: function(req,res) {
return '/api' + require('url').parse(req.url).path;
}
}));
var compiler = webpack(config);
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
})
);
app.use(hotMiddleware(compiler));
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();
});
});
app.listen(8080, function(err) {
if (err) {
return console.error(err);
}
console.log("Listening at http://localhost:8080/");
});
const options = {
key: fs.readFileSync(path.resolve(__dirname, "ssl/private.pem")),
cert: fs.readFileSync(path.resolve(__dirname, "ssl/cert.crt"))
};
const httpsServer = https.createServer(options, app);
httpsServer.listen(8081);
// 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');
// });