feat: allow passing additional args to HandlerContext.render (#82)
Co-authored-by: Luca Casonato <lucacasonato@yahoo.com>
This commit is contained in:
co-authored by
Luca Casonato
parent
6abf62c832
commit
788a85c431
@@ -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");
|
||||
},
|
||||
};
|
||||
Reference in New Issue
Block a user