forked from ryansolid/isomorphic-ui-benchmarks
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathserver.js
89 lines (71 loc) · 2.19 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
84
85
86
87
88
89
require("./init");
var express = require("express");
var serveStatic = require("serve-static");
var path = require("path");
var compression = require("compression");
var benchmarks = require("./benchmarks");
var benchmarkClientCreateRoute = require("./benchmark-client/createRoute");
var indexTemplate = require("./index.marko");
var isProduction = process.env.NODE_ENV === "production";
var minify = isProduction;
var urlPrefix = process.env.URL_PREFIX || "";
var app = express();
app.use(compression());
benchmarks.forEach(benchmark => {
var benchmarkName = benchmark.name;
benchmark.benches.forEach(bench => {
var libName = bench.name;
var jsBundle = `${urlPrefix}/bundles/${benchmarkName}/${libName}${
minify ? ".min" : ""
}.js`;
var routeOptions = {
jsBundle: jsBundle
};
app.get(
`/${benchmarkName}/${libName}`,
benchmark.createRoute(libName, routeOptions)
);
app.get(
`/benchmark/${benchmarkName}`,
benchmarkClientCreateRoute(benchmark, routeOptions)
);
});
});
app.use("/static", serveStatic(path.join(__dirname, "static")));
app.use(
"/isomorphic-ui-benchmarks/static",
serveStatic(path.join(__dirname, "static"))
);
app.use(require("lasso/middleware").serveStatic());
// app.get('/react', require('./src/react/pages/search-results'));
app.use("/bundles", serveStatic(path.join(__dirname, "build/bundles")));
app.use(
"/isomorphic-ui-benchmarks/bundles",
serveStatic(path.join(__dirname, "build/bundles"))
);
app.get("/", function(req, res) {
res.marko(indexTemplate, {
benchmarks
});
});
// app.get('/', require('./src/shared/pages/index'));
var port = process.env.PORT ? parseInt(process.env.PORT, 10) : 8080;
module.exports = new Promise((resolve, reject) => {
app.listen(port, function(err) {
if (err) {
return reject(err);
}
console.log("Listening on port " + port);
if (process.send) {
console.log("Server online");
process.send("online"); // Let browser-refresh know we are ready to serve traffic
}
resolve(port);
});
}).catch(err => {
console.error("Failed to start server:", err);
process.exit(1);
});
process.on("SIGTERM", function() {
process.exit(0);
});