feat: pass ConnInfo to various handler contexts (#121)
This commit is contained in:
+22
-1
@@ -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");
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user