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

Commit f13c677

Browse files
committed
Add csp option for ssr
1 parent 6f8cd73 commit f13c677

File tree

1 file changed

+6
-0
lines changed

1 file changed

+6
-0
lines changed

server/renderer.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,10 +24,12 @@ export type SSRContext = {
2424
export type SSR = {
2525
suspense: true;
2626
cacheControl?: "private" | "public";
27+
csp?: string | string[];
2728
render(ssr: SSRContext): Promise<ReadableStream> | ReadableStream;
2829
} | {
2930
suspense?: false;
3031
cacheControl?: "private" | "public";
32+
csp?: string | string[];
3133
render(ssr: SSRContext): Promise<string | ReadableStream> | string | ReadableStream;
3234
} | ((ssr: SSRContext) => Promise<string | ReadableStream> | string | ReadableStream);
3335

@@ -59,6 +61,7 @@ export default {
5961
const isFn = typeof ssr === "function";
6062
const suspense = isFn ? false : !!ssr.suspense;
6163
const cc = isFn ? "public" : ssr.cacheControl ?? "public";
64+
const csp = isFn ? undefined : ssr.csp;
6265
const render = isFn ? ssr : ssr.render;
6366
try {
6467
const [url, routeModules, suspenseData, errorBoundaryHandler] = await initSSR(
@@ -137,6 +140,9 @@ export default {
137140
} else {
138141
headers.append("Cache-Control", `${cc}, max-age=0, must-revalidate`);
139142
}
143+
if (csp) {
144+
headers.append("Content-Security-Policy", [csp].flat().join("; "));
145+
}
140146
ssrRes = {
141147
context: ssrContext,
142148
errorBoundaryHandlerFilename: errorBoundaryHandler?.filename,

0 commit comments

Comments
 (0)