Skip to content

Commit bd14787

Browse files
committed
perf: use srvx.FastResponse
1 parent 2265c91 commit bd14787

File tree

2 files changed

+5
-4
lines changed

2 files changed

+5
-4
lines changed

src/cli.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
import { resolve } from "node:path";
33

44
import { log } from "srvx/log";
5-
import { serve } from "srvx";
5+
import { FastResponse, serve } from "srvx";
66
import { compileTemplate } from "./compiler.ts";
77
import { renderToResponse } from "./render.ts";
88
import { serveStatic } from "srvx/static";
@@ -28,7 +28,7 @@ serve({
2828
} catch (error) {
2929
console.error(error);
3030
const errMessage = String((error as Error).stack || error);
31-
return new Response(errMessage, { status: 500 });
31+
return new FastResponse(errMessage, { status: 500 });
3232
}
3333
return renderToResponse(htmlTemplate, {
3434
request,
@@ -40,6 +40,6 @@ serve({
4040
}),
4141
],
4242
fetch: () => {
43-
return new Response("Not Found", { status: 404 });
43+
return new FastResponse("Not Found", { status: 404 });
4444
},
4545
});

src/render.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import {
44
type CookieSerializeOptions,
55
} from "cookie-es";
66
import type { CompiledTemplate } from "./compiler.ts";
7+
import { FastResponse } from "srvx";
78

89
export interface RenderOptions {
910
request?: Request;
@@ -34,7 +35,7 @@ export async function renderToResponse(
3435
if (body instanceof Response) {
3536
return body;
3637
}
37-
return new Response(body, {
38+
return new FastResponse(body, {
3839
status: ctx.$RESPONSE.status,
3940
statusText: ctx.$RESPONSE.statusText,
4041
headers: ctx.$RESPONSE.headers,

0 commit comments

Comments
 (0)