feat: add render function (#2454)

This commit is contained in:
Luca Casonato
2024-05-24 18:31:34 +02:00
committed by GitHub
parent 82d027cbcd
commit f2162d24bf
14 changed files with 123 additions and 64 deletions
+2 -2
View File
@@ -9,7 +9,7 @@ import {
import { delay, FakeServer } from "../../test_utils.ts";
import { createFakeFs } from "../../test_utils.ts";
import { expect } from "@std/expect";
import type { HandlerByMethod, HandlerFn } from "../../handlers.ts";
import { type HandlerByMethod, type HandlerFn, page } from "../../handlers.ts";
import type { Method } from "../../router.ts";
import { parseHtml } from "../../../tests/test_utils.tsx";
@@ -544,7 +544,7 @@ Deno.test("fsRoutes - handler return data", async () => {
const server = await createServer({
"routes/index.tsx": {
handler: () => {
return { data: "foo", status: 404 };
return page("foo", { status: 404 });
},
default: (ctx) => {
// deno-lint-ignore no-explicit-any
+2 -2
View File
@@ -1,6 +1,6 @@
import { type AnyComponent, h, type RenderableProps, type VNode } from "preact";
import type { MiddlewareFn } from "../../middlewares/mod.ts";
import type { HandlerFn, Render } from "../../handlers.ts";
import type { HandlerFn, PageResponse } from "../../handlers.ts";
import type { PageProps } from "../../runtime/server/mod.tsx";
export type AsyncAnyComponent<P> = {
@@ -22,7 +22,7 @@ export function renderMiddleware<State>(
handler: HandlerFn<unknown, State> | undefined,
): MiddlewareFn<State> {
return async (ctx) => {
let result: Render<unknown> | undefined;
let result: PageResponse<unknown> | undefined;
if (handler !== undefined) {
const res = await handler(ctx);