feat: top-level-for-await (#3212)

This commit is contained in:
Andy Hayden 2019-10-27 06:04:42 -07:00 committed by Ry Dahl
parent 51dd91a3cc
commit aec5a646c9
18 changed files with 257 additions and 263 deletions

View file

@ -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);
}