mirror of
https://github.com/denoland/deno.git
synced 2024-11-01 09:24:20 -04:00
cd21cff299
Co-authored-by: Bartek Iwańczuk <biwanczuk@gmail.com> Co-authored-by: Ben Noordhuis <info@bnoordhuis.nl> Co-authored-by: crowlkats <crowlkats@toaxl.com> Co-authored-by: Ryan Dahl <ry@tinyclouds.org>
37 lines
905 B
JavaScript
37 lines
905 B
JavaScript
// Copyright 2018-2022 the Deno authors. All rights reserved. MIT license.
|
|
|
|
// deno-lint-ignore-file
|
|
|
|
const {
|
|
core: {
|
|
opAsync,
|
|
ops: { op_flash_make_request, op_flash_serve },
|
|
encode,
|
|
},
|
|
} = Deno;
|
|
const addr = Deno.args[0] || "127.0.0.1:4500";
|
|
const [hostname, port] = addr.split(":");
|
|
const serverId = op_flash_serve({ hostname, port });
|
|
const serverPromise = opAsync("op_flash_drive_server", serverId);
|
|
|
|
const fastOps = op_flash_make_request();
|
|
function nextRequest() {
|
|
return fastOps.nextRequest();
|
|
}
|
|
function respond(token, response) {
|
|
return fastOps.respond(token, response, true);
|
|
}
|
|
|
|
const response = encode(
|
|
"HTTP/1.1 200 OK\r\nContent-Length: 11\r\n\r\nHello World",
|
|
);
|
|
while (true) {
|
|
let token = nextRequest();
|
|
if (token === 0) token = await opAsync("op_flash_next_async", serverId);
|
|
for (let i = 0; i < token; i++) {
|
|
respond(
|
|
i,
|
|
response,
|
|
);
|
|
}
|
|
}
|