-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest.js
47 lines (42 loc) · 1.18 KB
/
test.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
"use strict";
require('log-report');
console.time("Time");
var options = require("config-sets").tiny_https_server;
options.subdomains = { test: { document_root: "./public/test" } };
//var server = require("tiny-https-server");
var server = require("./server.js");
// Console log
server.on("request", function (req, res, next) {
console.timeLog("Time", `Url: ${req.headers.host}${req.url}`);
next();
});
// Test page.
server.on("request", function (req, res, next) {
if (req.url === "/test") {
res.writeHead(200, { "Content-Type": "text/plain" });
res.write("Test page.");
res.end();
}
else
next();
});
// Simulated crash ...
server.on("request", function (req, res, next) {
if (req.url === "/crash") {
throw new Error("Simulated crash ...");
}
else
next();
});
var port = options.port === 443 ? "" : ":" + options.port;
var urls = [
`http://localhost${port}/`,
`http://test.localhost${port}/`,
`http://localhost${port}/test`,
`http://test.localhost${port}/test`,
`http://localhost${port}/blacklist`
];
// Opens the URLs in the default browser.
while (urls.length) {
require("browse-url")(urls.shift());
}