http server:
Код: Выделить всё
const http_server = http.createServer(function (req, res) {
console.log("http", req.method, req.url, req.headers);
const url_path = url.parse(req.url, true).pathname;
const query = url.parse(req.url, true).query;
if (req.method === "GET" && req.headers["host"] !== undefined) {
// force create session
const session = getSession(req);
console.log(`HOST === ${req.headers["host"]}`)
res.removeHeader("Date");
res.removeHeader("Transfer-Encoding");
res.writeHead(302, {
Location: getNewLocation(req.headers["host"], url_path, query),
Connection: "close",
});
res.end();
return;
}
handler(req, res);
});
< /code>
test < /p>
it("should return index.html", (done) => {
request(http_server)
.get("/")
.unset("Host")
.expect(200)
.expect("Connection", "close")
.expect("Etag", '"167-110-5f0633df"')
.expect("Last-Modified", "Wed, 08 Jul 2020 21:00:15 GMT")
.expect("Date", date_regex)
.expect("Cache-Control", "no-cache")
.expect("Expires", "0")
.expect("Content-Type", "text/html")
.expect("Content-Length", `
`.length)
.expect(res => assert.strictEqual(res.text, `
`))
.end(done)
})
Подробнее здесь: https://stackoverflow.com/questions/797 ... -supertest