2021-04-08 18:34:15 -04:00
|
|
|
// Copyright 2018-2021 the Deno authors. All rights reserved. MIT license.
|
|
|
|
|
|
|
|
const addr = Deno.args[0] || "127.0.0.1:4500";
|
|
|
|
const [hostname, port] = addr.split(":");
|
|
|
|
const listener = Deno.listen({ hostname, port: Number(port) });
|
|
|
|
console.log("Server listening on", addr);
|
|
|
|
|
2021-05-02 19:23:19 -04:00
|
|
|
const encoder = new TextEncoder();
|
|
|
|
const body = encoder.encode("Hello World");
|
2021-04-08 18:34:15 -04:00
|
|
|
|
|
|
|
for await (const conn of listener) {
|
|
|
|
(async () => {
|
2021-04-09 11:54:27 -04:00
|
|
|
const requests = Deno.serveHttp(conn);
|
2021-04-08 18:34:15 -04:00
|
|
|
for await (const { respondWith } of requests) {
|
2021-05-11 18:06:58 -04:00
|
|
|
try {
|
|
|
|
respondWith(new Response(body));
|
|
|
|
} catch {
|
|
|
|
// Ignore.
|
|
|
|
}
|
2021-04-08 18:34:15 -04:00
|
|
|
}
|
|
|
|
})();
|
|
|
|
}
|