2024-01-01 14:58:21 -05:00
|
|
|
// Copyright 2018-2024 the Deno authors. All rights reserved. MIT license.
|
2021-04-08 18:34:15 -04:00
|
|
|
|
|
|
|
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-10-25 12:51:17 -04:00
|
|
|
for await (const event of requests) {
|
|
|
|
event.respondWith(new Response(body))
|
2021-08-30 12:40:00 -04:00
|
|
|
.catch((e) => console.log(e));
|
2021-04-08 18:34:15 -04:00
|
|
|
}
|
|
|
|
})();
|
|
|
|
}
|