fix: ctx.render headers not working (#1927)

This commit is contained in:
Marvin Hagemeister
2023-10-12 23:30:18 +02:00
committed by GitHub
parent 8d90c0ec81
commit bb8921ac85
10 changed files with 165 additions and 2 deletions
@@ -0,0 +1,16 @@
import type { Handlers } from "$fresh/server.ts";
export const handler: Handlers<unknown, unknown> = {
GET(_, ctx) {
const headers = [["x-foo", "Hello world!"]] as [string, string][];
return ctx.render(undefined, { headers });
},
};
export default function Home() {
return (
<div>
Should have <code>X-Foo</code> header set.
</div>
);
}
@@ -0,0 +1,17 @@
import type { Handlers } from "$fresh/server.ts";
export const handler: Handlers<unknown, unknown> = {
GET(_, ctx) {
const headers = new Headers();
headers.set("x-foo", "Hello world!");
return ctx.render(undefined, { headers });
},
};
export default function Home() {
return (
<div>
Should have <code>X-Foo</code> header set.
</div>
);
}
@@ -0,0 +1,18 @@
import type { Handlers } from "$fresh/server.ts";
export const handler: Handlers<unknown, unknown> = {
GET(_, ctx) {
const headers = {
"x-foo": "Hello world!",
};
return ctx.render(undefined, { headers });
},
};
export default function Home() {
return (
<div>
Should have <code>X-Foo</code> header set.
</div>
);
}
+27
View File
@@ -0,0 +1,27 @@
import * as path from "https://deno.land/std@0.192.0/path/mod.ts";
const __dirname = path.dirname(path.fromFileUrl(import.meta.url));
const links: string[] = [];
for (const file of Deno.readDirSync(__dirname)) {
if (file.name.startsWith("index")) continue;
const name = path.basename(file.name, path.extname(file.name));
links.push(name);
}
export default function Home() {
return (
<div>
<h1>Tests</h1>
<ul>
{links.sort().map((link) => {
return (
<li key={link}>
<a href={`/${link}`}>{link}</a>
</li>
);
})}
</ul>
</div>
);
}