feat(server): trailing slash configuration (#1291)

This commit is contained in:
Reed von Redwitz
2023-06-15 19:01:07 +02:00
committed by GitHub
parent 80306563d2
commit f5f8928c89
8 changed files with 106 additions and 1 deletions
+32
View File
@@ -0,0 +1,32 @@
import { ServerContext, Status } from "../server.ts";
import { assert, assertEquals } from "./deps.ts";
import manifest from "./fixture_router/fresh.gen.ts";
const ctx = await ServerContext.fromManifest(manifest, {
router: {
trailingSlash: true,
},
});
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("forwards slash placed at the end of url", async () => {
const targetUrl = "https://fresh.deno.dev/about";
const resp = await router(new Request(targetUrl));
assert(resp);
assertEquals(resp.status, Status.PermanentRedirect);
// forwarded location should be with trailing slash
assertEquals(resp.headers.get("location"), targetUrl + "/");
});