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");
},
};
+16 -14
View File
@@ -2,25 +2,27 @@
// This file SHOULD be checked into source version control.
// To update this file, run `fresh routes`.
import * as $0 from "./pages/_middleware.ts";
import * as $1 from "./pages/api/get_only.ts";
import * as $2 from "./pages/books/[id].tsx";
import * as $0 from "./pages/index.tsx";
import * as $1 from "./pages/static.tsx";
import * as $2 from "./pages/intercept_args.tsx";
import * as $3 from "./pages/props/[id].tsx";
import * as $4 from "./pages/static.tsx";
import * as $5 from "./pages/intercept.tsx";
import * as $6 from "./pages/[name].tsx";
import * as $7 from "./pages/index.tsx";
import * as $4 from "./pages/_middleware.ts";
import * as $5 from "./pages/books/[id].tsx";
import * as $6 from "./pages/api/get_only.ts";
import * as $7 from "./pages/intercept.tsx";
import * as $8 from "./pages/[name].tsx";
const routes = {
pages: {
"./pages/_middleware.ts": $0,
"./pages/api/get_only.ts": $1,
"./pages/books/[id].tsx": $2,
"./pages/index.tsx": $0,
"./pages/static.tsx": $1,
"./pages/intercept_args.tsx": $2,
"./pages/props/[id].tsx": $3,
"./pages/static.tsx": $4,
"./pages/intercept.tsx": $5,
"./pages/[name].tsx": $6,
"./pages/index.tsx": $7,
"./pages/_middleware.ts": $4,
"./pages/books/[id].tsx": $5,
"./pages/api/get_only.ts": $6,
"./pages/intercept.tsx": $7,
"./pages/[name].tsx": $8,
},
baseUrl: import.meta.url,
};