feat: pass ConnInfo to various handler contexts (#121)

This commit is contained in:
Leo Kettmeir
2022-03-09 19:16:08 +01:00
committed by GitHub
parent 8d689938cb
commit 67b3eb470e
7 changed files with 92 additions and 36 deletions
+22 -1
View File
@@ -3,7 +3,20 @@ import { assert, assertEquals, assertStringIncludes } from "./deps.ts";
import manifest from "./fixture/fresh.gen.ts";
const ctx = await ServerContext.fromManifest(manifest);
const router = ctx.handler();
const router = (req: Request) => {
return ctx.handler()(req, {
localAddr: {
transport: "tcp",
hostname: "127.0.0.1",
port: 80,
},
remoteAddr: {
transport: "tcp",
hostname: "127.0.0.1",
port: 80,
},
});
};
Deno.test("/ page prerender", async () => {
const resp = await router(new Request("https://fresh.deno.dev/"));
@@ -194,3 +207,11 @@ Deno.test("/params/:path*", async () => {
const body = await resp.text();
assertEquals(body, "bar/baz");
});
Deno.test("/connInfo", async () => {
const resp = await router(new Request("https://fresh.deno.dev/connInfo"));
assert(resp);
assertEquals(resp.status, 200);
const body = await resp.text();
assertEquals(body, "127.0.0.1");
});