2017-10-23 05:17:23 +00:00
|
|
|
"use strict";
|
|
|
|
|
|
|
|
const http = require("http");
|
|
|
|
|
|
|
|
const testPort = 8989;
|
|
|
|
const testUrl = `http://localhost:${testPort}`;
|
|
|
|
|
|
|
|
const staticResponse = `<!DOCTYPE "html">
|
|
|
|
<html>
|
|
|
|
<head>
|
|
|
|
<title>Test Page</title>
|
|
|
|
</head>
|
|
|
|
<body>
|
|
|
|
<p>Test Content</p>
|
|
|
|
</body>
|
|
|
|
</html>
|
|
|
|
`;
|
|
|
|
|
|
|
|
module.exports.start = function (callback) {
|
|
|
|
|
|
|
|
const httpServer = http.createServer(function (req, res) {
|
|
|
|
|
2017-10-23 08:29:59 +00:00
|
|
|
const headers = {"Content-Type": "text/html; charset=utf-8"};
|
2017-10-23 05:17:23 +00:00
|
|
|
|
|
|
|
if (callback !== undefined) {
|
|
|
|
callback(headers);
|
|
|
|
}
|
|
|
|
|
|
|
|
res.writeHead(200, headers);
|
|
|
|
res.write(staticResponse);
|
|
|
|
res.end();
|
|
|
|
});
|
|
|
|
httpServer.listen(8989);
|
|
|
|
return [httpServer, testUrl];
|
|
|
|
};
|
|
|
|
|
|
|
|
module.exports.stop = function (server) {
|
|
|
|
server.close();
|
2017-10-23 08:29:59 +00:00
|
|
|
};
|