Skip to main content
Module

x/fresh/tests/trailing_slash_test.ts

The next-gen web framework.
Extremely Popular
Go to Latest
File
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 + "/");});