Skip to content

Commit 139defd

Browse files
authored
use env.BASE_URL instead of env.SERVER_BASE_URL (#2012)
1 parent 7550f7c commit 139defd

8 files changed

Lines changed: 20 additions & 22 deletions

File tree

apps/fixtures/experiments/src/routes/index.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ export default function Home() {
2323
console.log(await v.hello);
2424
});
2525
const port = isServer ? new URL(getRequestEvent()!.request.url).port: location.port;
26-
fetch(`http://localhost:${port}/${import.meta.env.SERVER_BASE_URL}/unknown`, {
26+
fetch(`http://localhost:${port}${import.meta.env.BASE_URL}/unknown`, {
2727
headers: { Accept: "application/json" }
2828
}).then(async res => console.log(await res.json()));
2929
return (

apps/fixtures/experiments/tsconfig.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
"strict": true,
1212
"noEmit": true,
1313
"isolatedModules": true,
14+
"types": ["vite/client"],
1415
"paths": {
1516
"~/*": ["./src/*"]
1617
}

packages/start/src/server/handler.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ export function createBaseHandler(
3434
const url = new URL(event.request.url);
3535
const pathname = url.pathname;
3636

37-
const serverFunctionTest = join("/", SERVER_FN_BASE);
37+
const serverFunctionTest = join(import.meta.env.BASE_URL, SERVER_FN_BASE);
3838
if (pathname.startsWith(serverFunctionTest)) {
3939
const serverFnResponse = await handleServerFunction(e);
4040

packages/start/src/server/manifest/dev-client-manifest.ts

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,7 @@ export function getClientDevManifest() {
66
return import(/* @vite-ignore */ join("/", id))
77
},
88
async getAssets(id) {
9-
const assetsPath =
10-
join(
11-
import.meta.env.BASE_URL,
12-
`@manifest/client/${Date.now()}/assets?id=${id}`,
13-
);
9+
const assetsPath = `/@manifest/client/${Date.now()}/assets?id=${id}`;
1410

1511
const assets = (await import(/* @vite-ignore */ assetsPath)).default;
1612

packages/start/src/server/manifest/dev-ssr-manifest.ts

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,9 @@ import { join, normalize } from "pathe";
22

33
export function getSsrDevManifest(environment: "client" | "ssr") {
44
return {
5-
path: (id: string) => normalize(join("/", id)),
5+
path: (id: string) => normalize(join(import.meta.env.BASE_URL, id)),
66
async getAssets(id) {
7-
const assetsPath =
8-
join(
9-
import.meta.env.BASE_URL,
10-
`@manifest/${environment}/${Date.now()}/assets?id=${id}`,
11-
);
7+
const assetsPath = `/@manifest/${environment}/${Date.now()}/assets?id=${id}`;
128

139
const assets = (await import(/* @vite-ignore */ assetsPath)).default;
1410

packages/start/src/server/server-fns-runtime.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,13 @@ import { provideRequestEvent } from "solid-js/web/storage";
44
export function createServerReference(fn: Function, id: string) {
55
if (typeof fn !== "function")
66
throw new Error("Export from a 'use server' module must be a function");
7-
const baseURL = import.meta.env.SERVER_BASE_URL ?? "";
7+
let baseURL = import.meta.env.BASE_URL ?? "/";
8+
if(!baseURL.endsWith("/")) baseURL += "/"
9+
810
return new Proxy(fn, {
911
get(target, prop, receiver) {
1012
if (prop === "url") {
11-
return `${baseURL}/_server?id=${encodeURIComponent(id)}`;
13+
return `${baseURL}_server?id=${encodeURIComponent(id)}`;
1214
}
1315
if (prop === "GET") return receiver;
1416
return (target as any)[prop];

packages/start/src/server/server-functions-handler.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -237,7 +237,7 @@ function handleNoJS(
237237
`Location`,
238238
new URL(
239239
result.headers.get("Location")!,
240-
url.origin + import.meta.env.SERVER_BASE_URL,
240+
url.origin + import.meta.env.BASE_URL,
241241
).toString(),
242242
);
243243
statusCode = getExpectedRedirectStatus(result);
@@ -318,7 +318,7 @@ async function handleSingleFlight(
318318
url = new URL(
319319
result.headers.get("Location")!,
320320
new URL(sourceEvent.request.url).origin +
321-
import.meta.env.SERVER_BASE_URL,
321+
import.meta.env.BASE_URL,
322322
).toString();
323323
}
324324
const event = { ...sourceEvent } as PageEvent;

packages/start/src/server/server-runtime.ts

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
// @ts-ignore - seroval exports issue with NodeNext
2+
import { join } from "pathe";
23
import { deserialize, toJSONAsync } from "seroval";
34
import {
45
CustomEventPlugin,
@@ -193,19 +194,21 @@ async function fetchServerFunction(
193194
}
194195

195196
export 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

Comments
 (0)