feat: add render function (#2454)
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -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);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user