summaryrefslogtreecommitdiff
path: root/tools/deno_http_proxy.ts
diff options
context:
space:
mode:
authorAndy Hayden <andyhayden1@gmail.com>2019-10-27 06:04:42 -0700
committerRy Dahl <ry@tinyclouds.org>2019-10-27 09:04:42 -0400
commitaec5a646c9218a0a0da62cbcd1f28bc23c242540 (patch)
treee052f0263eb2abc4915dc3710ec44ee34e9ad621 /tools/deno_http_proxy.ts
parent51dd91a3ccfd9554bcf69b539f2f748da81c5b12 (diff)
feat: top-level-for-await (#3212)
Diffstat (limited to 'tools/deno_http_proxy.ts')
-rw-r--r--tools/deno_http_proxy.ts12
1 files changed, 4 insertions, 8 deletions
diff --git a/tools/deno_http_proxy.ts b/tools/deno_http_proxy.ts
index 728e4fd3f..5f601723a 100644
--- a/tools/deno_http_proxy.ts
+++ b/tools/deno_http_proxy.ts
@@ -5,13 +5,6 @@ const addr = Deno.args[1] || "127.0.0.1:4500";
const originAddr = Deno.args[2] || "127.0.0.1:4501";
const server = serve(addr);
-async function main(): Promise<void> {
- console.log(`Proxy listening on http://${addr}/`);
- for await (const req of server) {
- proxyRequest(req);
- }
-}
-
async function proxyRequest(req: ServerRequest): Promise<void> {
const url = `http://${originAddr}${req.url}`;
const resp = await fetch(url, {
@@ -21,4 +14,7 @@ async function proxyRequest(req: ServerRequest): Promise<void> {
req.respond(resp);
}
-main();
+console.log(`Proxy listening on http://${addr}/`);
+for await (const req of server) {
+ proxyRequest(req);
+}