forked from firefox-devtools/debugger
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdevelopment-server.js
More file actions
executable file
·99 lines (81 loc) · 2.56 KB
/
development-server.js
File metadata and controls
executable file
·99 lines (81 loc) · 2.56 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
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
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
#!/usr/bin/env node
"use strict";
require("babel-register");
const path = require("path");
const webpack = require("webpack");
const express = require("express");
const webpackDevMiddleware = require("webpack-dev-middleware");
const webpackHotMiddleware = require("webpack-hot-middleware");
const http = require("http");
const serveIndex = require("serve-index");
// Setup Config
const getConfig = require("../config/config").getConfig;
const feature = require("../config/feature");
const config = getConfig();
feature.setConfig(config);
if (!feature.getValue("firefox.webSocketConnection")) {
const firefoxProxy = require("./firefox-proxy");
firefoxProxy({ logging: feature.getValue("logging.firefoxProxy") });
}
function httpGet(url, onResponse) {
return http.get(url, (response) => {
if (response.statusCode !== 200) {
console.error(`error response: ${response.statusCode} to ${url}`);
response.emit("statusCode", new Error(response.statusCode));
return onResponse("{}");
}
let body = "";
response.on("data", function(d) {
body += d;
});
response.on("end", () => onResponse(body));
});
}
const app = express();
// Webpack middleware
const webpackConfig = require("../webpack.config");
const compiler = webpack(webpackConfig);
app.use(webpackDevMiddleware(compiler, {
publicPath: webpackConfig.output.publicPath,
noInfo: true,
stats: { colors: true }
}));
if (feature.getValue("hotReloading")) {
app.use(webpackHotMiddleware(compiler));
} else {
console.log("Hot Reloading can be enabled by adding " +
"\"hotReloading\": true to your local.json config");
}
// Static middleware
app.use(express.static("public"));
// Routes
app.get("/", function(req, res) {
res.sendFile(path.join(__dirname, "../index.html"));
});
app.get("/get", function(req, res) {
const httpReq = httpGet(
req.query.url,
body => {
try {
return res.json(JSON.parse(body));
} catch (e) {
throw Error(e);
}
}
);
httpReq.on("error", err => res.status(500).send(err.code));
httpReq.on("statusCode", err => res.status(err.message).send(err.message));
});
// Listen
app.listen(8000, "0.0.0.0", function(err, result) {
if (err) {
console.log(err);
}
console.log("Development Server Listening at http://localhost:8000");
});
const examples = express();
examples.use(express.static("public/js/test/examples"));
examples.use(serveIndex("public/js/test/examples", { icons: true }));
examples.listen(7999, "0.0.0.0", function(err, result) {
console.log("View debugger examples at http://localhost:7999");
});