@@ -16,7 +16,13 @@ import {
16
16
import { sharedConfig } from "solid-js" ;
17
17
import { renderToString } from "solid-js/web" ;
18
18
import { provideRequestEvent } from "solid-js/web/storage" ;
19
- import { eventHandler , parseCookies , setHeader , setResponseStatus , type HTTPEvent } from "vinxi/http" ;
19
+ import {
20
+ eventHandler ,
21
+ parseCookies ,
22
+ setHeader ,
23
+ setResponseStatus ,
24
+ type HTTPEvent
25
+ } from "vinxi/http" ;
20
26
import invariant from "vinxi/lib/invariant" ;
21
27
import { cloneEvent , getFetchEvent , mergeResponseHeaders } from "../server/fetchEvent" ;
22
28
import { getExpectedRedirectStatus } from "../server/handler" ;
@@ -87,14 +93,23 @@ async function handleServerFunction(h3Event: HTTPEvent) {
87
93
} else {
88
94
functionId = url . searchParams . get ( "id" ) ;
89
95
name = url . searchParams . get ( "name" ) ;
90
- if ( ! functionId || ! name ) return new Response ( "Server function not found" , { status : 404 } ) ;
96
+
97
+ if ( ! functionId || ! name ) {
98
+ return process . env . NODE_ENV === "development"
99
+ ? new Response ( "Server function not found" , { status : 404 } )
100
+ : new Response ( null , { status : 404 } ) ;
101
+ }
91
102
}
92
103
93
104
const serverFnInfo = serverFnManifest [ functionId ] ;
94
105
let fnModule : undefined | { [ key : string ] : any } ;
95
106
96
- if ( ! serverFnInfo ) return new Response ( "Server function not found" , { status : 404 } ) ;
97
-
107
+ if ( ! serverFnInfo ) {
108
+ return process . env . NODE_ENV === "development"
109
+ ? new Response ( "Server function not found" , { status : 404 } )
110
+ : new Response ( null , { status : 404 } ) ;
111
+ }
112
+
98
113
if ( process . env . NODE_ENV === "development" ) {
99
114
// In dev, we use Vinxi to get the "server" server-side router
100
115
// Then we use that router's devServer.ssrLoadModule to get the serverFn
@@ -118,19 +133,19 @@ async function handleServerFunction(h3Event: HTTPEvent) {
118
133
const json = JSON . parse ( args ) ;
119
134
( json . t
120
135
? ( fromJSON ( json , {
121
- plugins : [
122
- CustomEventPlugin ,
123
- DOMExceptionPlugin ,
124
- EventPlugin ,
125
- FormDataPlugin ,
126
- HeadersPlugin ,
127
- ReadableStreamPlugin ,
128
- RequestPlugin ,
129
- ResponsePlugin ,
130
- URLSearchParamsPlugin ,
131
- URLPlugin
132
- ]
133
- } ) as any )
136
+ plugins : [
137
+ CustomEventPlugin ,
138
+ DOMExceptionPlugin ,
139
+ EventPlugin ,
140
+ FormDataPlugin ,
141
+ HeadersPlugin ,
142
+ ReadableStreamPlugin ,
143
+ RequestPlugin ,
144
+ ResponsePlugin ,
145
+ URLSearchParamsPlugin ,
146
+ URLPlugin
147
+ ]
148
+ } ) as any )
134
149
: json
135
150
) . forEach ( ( arg : any ) => parsed . push ( arg ) ) ;
136
151
}
@@ -148,7 +163,8 @@ async function handleServerFunction(h3Event: HTTPEvent) {
148
163
const isReadableStream = h3Request instanceof ReadableStream ;
149
164
const hasReadableStream = ( h3Request as EdgeIncomingMessage ) . body instanceof ReadableStream ;
150
165
const isH3EventBodyStreamLocked =
151
- ( isReadableStream && h3Request . locked ) || ( hasReadableStream && ( ( h3Request as EdgeIncomingMessage ) . body as ReadableStream ) . locked ) ;
166
+ ( isReadableStream && h3Request . locked ) ||
167
+ ( hasReadableStream && ( ( h3Request as EdgeIncomingMessage ) . body as ReadableStream ) . locked ) ;
152
168
const requestBody = isReadableStream ? h3Request : h3Request . body ;
153
169
154
170
if (
@@ -272,13 +288,15 @@ function handleNoJS(result: any, request: Request, parsed: any[], thrown?: boole
272
288
if ( result ) {
273
289
headers . append (
274
290
"Set-Cookie" ,
275
- `flash=${ encodeURIComponent ( JSON . stringify ( {
276
- url : url . pathname + url . search ,
277
- result : isError ? result . message : result ,
278
- thrown : thrown ,
279
- error : isError ,
280
- input : [ ...parsed . slice ( 0 , - 1 ) , [ ...parsed [ parsed . length - 1 ] . entries ( ) ] ]
281
- } ) ) } ; Secure; HttpOnly;`
291
+ `flash=${ encodeURIComponent (
292
+ JSON . stringify ( {
293
+ url : url . pathname + url . search ,
294
+ result : isError ? result . message : result ,
295
+ thrown : thrown ,
296
+ error : isError ,
297
+ input : [ ...parsed . slice ( 0 , - 1 ) , [ ...parsed [ parsed . length - 1 ] . entries ( ) ] ]
298
+ } )
299
+ ) } ; Secure; HttpOnly;`
282
300
) ;
283
301
}
284
302
return new Response ( null , {
@@ -302,7 +320,7 @@ function createSingleFlightHeaders(sourceEvent: FetchEvent) {
302
320
useH3Internals = true ;
303
321
sourceEvent . nativeEvent . node . req . headers . cookie = "" ;
304
322
}
305
- SetCookies . forEach ( ( cookie ) => {
323
+ SetCookies . forEach ( cookie => {
306
324
if ( ! cookie ) return ;
307
325
const keyValue = cookie . split ( ";" ) [ 0 ] ! ;
308
326
const [ key , value ] = keyValue . split ( "=" ) ;
@@ -311,7 +329,7 @@ function createSingleFlightHeaders(sourceEvent: FetchEvent) {
311
329
Object . entries ( cookies ) . forEach ( ( [ key , value ] ) => {
312
330
headers . append ( "cookie" , `${ key } =${ value } ` ) ;
313
331
useH3Internals && ( sourceEvent . nativeEvent . node . req . headers . cookie += `${ key } =${ value } ;` ) ;
314
- } )
332
+ } ) ;
315
333
316
334
return headers ;
317
335
}
0 commit comments