File tree Expand file tree Collapse file tree 4 files changed +14
-22
lines changed
server-functions-plugin/src
start-server-functions-client/src
start-server-functions-server/src Expand file tree Collapse file tree 4 files changed +14
-22
lines changed Original file line number Diff line number Diff line change @@ -8,11 +8,7 @@ import type {
8
8
ReplacerFn ,
9
9
} from '@tanstack/directive-functions-plugin'
10
10
11
- export type CreateRpcFn = (
12
- functionId : string ,
13
- serverBase : string ,
14
- splitImportFn ?: string ,
15
- ) => any
11
+ export type CreateRpcFn = ( functionId : string , splitImportFn ?: string ) => any
16
12
17
13
export type ServerFnPluginOpts = {
18
14
/**
Original file line number Diff line number Diff line change @@ -307,15 +307,13 @@ export function TanStackStartVitePluginCore(
307
307
client : {
308
308
getRuntimeCode : ( ) =>
309
309
`import { createClientRpc } from '@tanstack/${ corePluginOpts . framework } -start/server-functions-client'` ,
310
- replacer : ( d ) =>
311
- `createClientRpc('${ d . functionId } ', '${ startConfig . serverFns . base } ')` ,
310
+ replacer : ( d ) => `createClientRpc('${ d . functionId } ')` ,
312
311
envName : VITE_ENVIRONMENT_NAMES . client ,
313
312
} ,
314
313
server : {
315
314
getRuntimeCode : ( ) =>
316
315
`import { createServerRpc } from '@tanstack/${ corePluginOpts . framework } -start/server-functions-server'` ,
317
- replacer : ( d ) =>
318
- `createServerRpc('${ d . functionId } ', '${ startConfig . serverFns . base } ', ${ d . fn } )` ,
316
+ replacer : ( d ) => `createServerRpc('${ d . functionId } ', ${ d . fn } )` ,
319
317
envName : VITE_ENVIRONMENT_NAMES . server ,
320
318
} ,
321
319
} ) ,
Original file line number Diff line number Diff line change @@ -5,11 +5,12 @@ function sanitizeBase(base: string) {
5
5
return base . replace ( / ^ \/ | \/ $ / g, '' )
6
6
}
7
7
8
- export const createClientRpc : CreateRpcFn = ( functionId , serverBase ) => {
9
- const sanitizedAppBase = sanitizeBase ( process . env . TSS_APP_BASE || '/' )
10
- const sanitizedServerBase = sanitizeBase ( serverBase )
8
+ const sanitizedAppBase = sanitizeBase ( process . env . TSS_APP_BASE || '/' )
9
+ const sanitizedServerBase = sanitizeBase ( process . env . TSS_SERVER_FN_BASE ! )
10
+ const baseUrl = ` ${ sanitizedAppBase ? `/ ${ sanitizedAppBase } ` : '' } / ${ sanitizedServerBase } /`
11
11
12
- const url = `${ sanitizedAppBase ? `/${ sanitizedAppBase } ` : `` } /${ sanitizedServerBase } /${ functionId } `
12
+ export const createClientRpc : CreateRpcFn = ( functionId ) => {
13
+ const url = baseUrl + functionId
13
14
14
15
const clientFn = ( ...args : Array < any > ) => {
15
16
return serverFnFetcher ( url , args , fetch )
Original file line number Diff line number Diff line change @@ -5,20 +5,17 @@ function sanitizeBase(base: string) {
5
5
return base . replace ( / ^ \/ | \/ $ / g, '' )
6
6
}
7
7
8
- export const createServerRpc : CreateRpcFn = (
9
- functionId ,
10
- serverBase ,
11
- splitImportFn ,
12
- ) => {
8
+ const sanitizedAppBase = sanitizeBase ( process . env . TSS_APP_BASE || '/' )
9
+ const sanitizedServerBase = sanitizeBase ( process . env . TSS_SERVER_FN_BASE ! )
10
+ const baseUrl = ` ${ sanitizedAppBase ? `/ ${ sanitizedAppBase } ` : '' } / ${ sanitizedServerBase } /`
11
+
12
+ export const createServerRpc : CreateRpcFn = ( functionId , splitImportFn ) => {
13
13
invariant (
14
14
splitImportFn ,
15
15
'🚨splitImportFn required for the server functions server runtime, but was not provided.' ,
16
16
)
17
17
18
- const sanitizedAppBase = sanitizeBase ( process . env . TSS_APP_BASE || '/' )
19
- const sanitizedServerBase = sanitizeBase ( serverBase )
20
-
21
- const url = `${ sanitizedAppBase ? `/${ sanitizedAppBase } ` : `` } /${ sanitizedServerBase } /${ functionId } `
18
+ const url = baseUrl + functionId
22
19
23
20
return Object . assign ( splitImportFn , {
24
21
url,
You can’t perform that action at this time.
0 commit comments