feat(server): trailing slash configuration (#1291)
This commit is contained in:
@@ -0,0 +1,5 @@
|
||||
#!/usr/bin/env -S deno run -A --watch=static/,routes/
|
||||
|
||||
import dev from "$fresh/dev.ts";
|
||||
|
||||
await dev(import.meta.url, "./main.ts");
|
||||
@@ -0,0 +1,17 @@
|
||||
// DO NOT EDIT. This file is generated by fresh.
|
||||
// This file SHOULD be checked into source version control.
|
||||
// This file is automatically updated during development when running `dev.ts`.
|
||||
|
||||
import * as $0 from "./routes/about.tsx";
|
||||
import * as $1 from "./routes/index.tsx";
|
||||
|
||||
const manifest = {
|
||||
routes: {
|
||||
"./routes/about.tsx": $0,
|
||||
"./routes/index.tsx": $1,
|
||||
},
|
||||
islands: {},
|
||||
baseUrl: import.meta.url,
|
||||
};
|
||||
|
||||
export default manifest;
|
||||
@@ -0,0 +1,10 @@
|
||||
/// <reference no-default-lib="true" />
|
||||
/// <reference lib="dom" />
|
||||
/// <reference lib="dom.asynciterable" />
|
||||
/// <reference lib="deno.ns" />
|
||||
/// <reference lib="deno.unstable" />
|
||||
|
||||
import { start } from "$fresh/server.ts";
|
||||
import manifest from "./fresh.gen.ts";
|
||||
|
||||
await start(manifest);
|
||||
@@ -0,0 +1,7 @@
|
||||
export default function About() {
|
||||
return (
|
||||
<div>
|
||||
About
|
||||
</div>
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
export default function Home() {
|
||||
return (
|
||||
<div>
|
||||
Hello
|
||||
</div>
|
||||
);
|
||||
}
|
||||
@@ -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 + "/");
|
||||
});
|
||||
Reference in New Issue
Block a user