2021-01-11 12:13:41 -05:00
|
|
|
// Copyright 2018-2021 the Deno authors. All rights reserved. MIT license.
|
2021-02-02 06:05:46 -05:00
|
|
|
import { serve, ServerRequest } from "../test_util/std/http/server.ts";
|
2019-06-06 12:44:35 -04:00
|
|
|
|
2020-01-09 13:37:01 -05:00
|
|
|
const addr = Deno.args[0] || "127.0.0.1:4500";
|
|
|
|
const originAddr = Deno.args[1] || "127.0.0.1:4501";
|
2019-06-06 12:44:35 -04:00
|
|
|
const server = serve(addr);
|
|
|
|
|
2019-09-16 17:25:32 -04:00
|
|
|
async function proxyRequest(req: ServerRequest): Promise<void> {
|
2019-06-06 12:44:35 -04:00
|
|
|
const url = `http://${originAddr}${req.url}`;
|
|
|
|
const resp = await fetch(url, {
|
|
|
|
method: req.method,
|
2020-03-28 13:03:49 -04:00
|
|
|
headers: req.headers,
|
2019-06-06 12:44:35 -04:00
|
|
|
});
|
|
|
|
req.respond(resp);
|
|
|
|
}
|
|
|
|
|
2019-10-27 09:04:42 -04:00
|
|
|
console.log(`Proxy listening on http://${addr}/`);
|
|
|
|
for await (const req of server) {
|
|
|
|
proxyRequest(req);
|
|
|
|
}
|