This repository was archived by the owner on Jul 6, 2025. It is now read-only.
File tree Expand file tree Collapse file tree 1 file changed +6
-0
lines changed Expand file tree Collapse file tree 1 file changed +6
-0
lines changed Original file line number Diff line number Diff line change @@ -24,10 +24,12 @@ export type SSRContext = {
24
24
export type SSR = {
25
25
suspense : true ;
26
26
cacheControl ?: "private" | "public" ;
27
+ csp ?: string | string [ ] ;
27
28
render ( ssr : SSRContext ) : Promise < ReadableStream > | ReadableStream ;
28
29
} | {
29
30
suspense ?: false ;
30
31
cacheControl ?: "private" | "public" ;
32
+ csp ?: string | string [ ] ;
31
33
render ( ssr : SSRContext ) : Promise < string | ReadableStream > | string | ReadableStream ;
32
34
} | ( ( ssr : SSRContext ) => Promise < string | ReadableStream > | string | ReadableStream ) ;
33
35
@@ -59,6 +61,7 @@ export default {
59
61
const isFn = typeof ssr === "function" ;
60
62
const suspense = isFn ? false : ! ! ssr . suspense ;
61
63
const cc = isFn ? "public" : ssr . cacheControl ?? "public" ;
64
+ const csp = isFn ? undefined : ssr . csp ;
62
65
const render = isFn ? ssr : ssr . render ;
63
66
try {
64
67
const [ url , routeModules , suspenseData , errorBoundaryHandler ] = await initSSR (
@@ -137,6 +140,9 @@ export default {
137
140
} else {
138
141
headers . append ( "Cache-Control" , `${ cc } , max-age=0, must-revalidate` ) ;
139
142
}
143
+ if ( csp ) {
144
+ headers . append ( "Content-Security-Policy" , [ csp ] . flat ( ) . join ( "; " ) ) ;
145
+ }
140
146
ssrRes = {
141
147
context : ssrContext ,
142
148
errorBoundaryHandlerFilename : errorBoundaryHandler ?. filename ,
You can’t perform that action at this time.
0 commit comments