11// @ts -ignore - seroval exports issue with NodeNext
2+ import { join } from "pathe" ;
23import { deserialize , toJSONAsync } from "seroval" ;
34import {
45 CustomEventPlugin ,
@@ -193,19 +194,21 @@ async function fetchServerFunction(
193194}
194195
195196export function createServerReference ( id : string ) {
196- const baseURL = import . meta. env . SERVER_BASE_URL ?? "" ;
197- const fn = ( ...args : any [ ] ) => fetchServerFunction ( `${ baseURL } /_server` , id , { } , args ) ;
197+ let baseURL = import . meta. env . BASE_URL ?? "/" ;
198+ if ( ! baseURL . endsWith ( "/" ) ) baseURL += "/"
199+
200+ const fn = ( ...args : any [ ] ) => fetchServerFunction ( `${ baseURL } _server` , id , { } , args ) ;
198201
199202 return new Proxy ( fn , {
200203 get ( target , prop , receiver ) {
201204 if ( prop === "url" ) {
202- return `${ baseURL } / _server?id=${ encodeURIComponent ( id ) } ` ;
205+ return `${ baseURL } _server?id=${ encodeURIComponent ( id ) } ` ;
203206 }
204207 if ( prop === "GET" ) {
205208 return receiver . withOptions ( { method : "GET" } ) ;
206209 }
207210 if ( prop === "withOptions" ) {
208- const url = `${ baseURL } / _server?id=${ encodeURIComponent ( id ) } ` ;
211+ const url = `${ baseURL } _server?id=${ encodeURIComponent ( id ) } ` ;
209212 return ( options : RequestInit ) => {
210213 const fn = async ( ...args : any [ ] ) => {
211214 const encodeArgs = options . method && options . method . toUpperCase ( ) === "GET" ;
@@ -217,7 +220,7 @@ export function createServerReference(id: string) {
217220 JSON . stringify ( await Promise . resolve ( toJSONAsync ( args , { plugins } ) ) )
218221 ) } `
219222 : "" )
220- : `${ baseURL } / _server` ,
223+ : `${ baseURL } _server` ,
221224 id ,
222225 options ,
223226 encodeArgs ? [ ] : args
0 commit comments