feat: allow passing additional args to HandlerContext.render (#82)

Co-authored-by: Luca Casonato <lucacasonato@yahoo.com>
This commit is contained in:
Leo Kettmeir
2022-02-11 01:25:47 +01:00
committed by GitHub
co-authored by Luca Casonato
parent 6abf62c832
commit 788a85c431
7 changed files with 75 additions and 18 deletions
+31
View File
@@ -0,0 +1,31 @@
/** @jsx h */
import { h } from "../deps.ts";
import { HandlerContext } from "../../../server.ts";
interface renderData extends Record<string, unknown> {
info: string;
}
export default function Page({
renderData,
}: {
renderData: renderData;
}) {
return <div>{renderData.info}</div>;
}
export const handler = {
GET({ req, render }: HandlerContext) {
if (req.headers.get("accept")?.includes("text/html")) {
return render!({
info: "intercepted",
} as renderData);
} else {
return new Response("This is plain text");
}
},
POST() {
return new Response("POST response");
},
};