Skip to content
This repository was archived by the owner on Jul 6, 2025. It is now read-only.

Commit dd27778

Browse files
committed
Update types
1 parent c515bf5 commit dd27778

File tree

4 files changed

+32
-6
lines changed

4 files changed

+32
-6
lines changed

server/mod.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import { getContentType } from "../lib/mime.ts";
66
import util from "../lib/util.ts";
77
import { VERSION } from "../version.ts";
88
import { initModuleLoaders, loadImportMap, loadJSXConfig } from "./config.ts";
9-
import renderer from "./renderer.ts";
9+
import renderer, { type HTMLRewriterHandlers } from "./renderer.ts";
1010
import { content, json } from "./response.ts";
1111
import { importRouteModule, initRoutes } from "./routing.ts";
1212
import clientModuleTransformer from "./transformer.ts";

server/renderer.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,10 @@ import type { DependencyGraph } from "./graph.ts";
66
import { importRouteModule } from "./routing.ts";
77
import type { RenderModule, Route, SSRContext } from "./types.ts";
88

9+
export type HTMLRewriterHandlers = {
10+
element?: (element: Element) => void;
11+
};
12+
913
export type RenderOptions = {
1014
indexHtml: string;
1115
routes: Route[];

server/response.ts

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,19 @@ export type CacheControl = {
1818

1919
export function content(
2020
content: BodyInit,
21-
contentType: string,
22-
cacheContorl?: CacheControl | "immutable" | "no-cache",
21+
init?: ResponseInit & {
22+
contentType?: string;
23+
cacheContorl?: CacheControl | "immutable" | "no-cache";
24+
},
2325
): Response {
24-
const headers = new Headers({ "Content-Type": contentType });
26+
const headers = new Headers(init?.headers);
27+
28+
const contentType = init?.contentType;
29+
if (contentType) {
30+
headers.set("Content-Type", contentType);
31+
}
32+
33+
const cacheContorl = init?.cacheContorl;
2534
if (cacheContorl) {
2635
if (cacheContorl === "no-cache") {
2736
headers.set("Cache-Control", "no-cache, no-store, must-revalidate");
@@ -42,5 +51,6 @@ export function content(
4251
);
4352
}
4453
}
45-
return new Response(content, { headers });
54+
55+
return new Response(content, { ...init, headers });
4656
}

types.d.ts

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,25 @@ declare type HTMLRewriterHandlers = {
66
end?: (end: import("https://deno.land/x/[email protected]/types.d.ts").DocumentEnd) => void;
77
};
88

9-
declare interface FetchContext extends Record<string, unknown> {
9+
declare interface Context extends Record<string, unknown> {
1010
readonly params: Record<string, string>;
1111
readonly HTMLRewriter: {
1212
on: (selector: string, handlers: HTMLRewriterHandlers) => void;
1313
};
1414
}
1515

16+
declare interface Data {
17+
get?(request: Request, context: Context): Promise<Response> | Response;
18+
post?(request: Request, context: Context): Promise<Response> | Response;
19+
put?(request: Request, context: Context): Promise<Response> | Response;
20+
patch?(request: Request, context: Context): Promise<Response> | Response;
21+
delete?(request: Request, context: Context): Promise<Response> | Response;
22+
}
23+
24+
declare interface Middleware {
25+
fetch(request: Request, context: Context): Promise<Response | void> | Response | void;
26+
}
27+
1628
declare interface ImportMeta {
1729
readonly hot?: {
1830
accept: (callback?: (module: unknown) => void) => void;

0 commit comments

Comments
 (0)