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
·82 lines (66 loc) · 1.89 KB
/
development-server.js
File metadata and controls
executable file
·82 lines (66 loc) · 1.89 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
#!/usr/bin/env node
"use strict";
require("babel-register");
const path = require("path");
const fs = require("fs");
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 _ = require("lodash");
// Setup Config
const getConfig = require("../config/config").getConfig;
const feature = require("../config/feature");
const config = getConfig();
feature.setConfig(config);
if (!feature.isEnabled("firefox.webSocketConnection")) {
const firefoxProxy = require("./firefox-proxy");
firefoxProxy({ logging: feature.isEnabled("logging.firefoxProxy") });
}
function httpGet(url, onResponse) {
return http.get(url, (response) => {
let body = '';
response.on('data', function(d) {
body += d;
});
response.on('end', function() {
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.isEnabled("hotReloading")) {
app.use(webpackHotMiddleware(compiler));
}
// Static middleware
app.use(express.static("public/js/test/examples"));
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 => res.json(JSON.parse(body))
);
httpReq.on('error', function (err) {
res.status(500).send(err.code);
});
})
// Listen
app.listen(8000, "localhost", function(err, result) {
if (err) {
console.log(err);
}
console.log("Development Server Listening at http://localhost:8000");
});