Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion apps/fixtures/experiments/src/routes/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ export default function Home() {
console.log(await v.hello);
});
const port = isServer ? new URL(getRequestEvent()!.request.url).port: location.port;
fetch(`http://localhost:${port}/${import.meta.env.SERVER_BASE_URL}/unknown`, {
fetch(`http://localhost:${port}${import.meta.env.BASE_URL}/unknown`, {
headers: { Accept: "application/json" }
}).then(async res => console.log(await res.json()));
return (
Expand Down
1 change: 1 addition & 0 deletions apps/fixtures/experiments/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
"strict": true,
"noEmit": true,
"isolatedModules": true,
"types": ["vite/client"],
"paths": {
"~/*": ["./src/*"]
}
Expand Down
2 changes: 1 addition & 1 deletion packages/start/src/server/handler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ export function createBaseHandler(
const url = new URL(event.request.url);
const pathname = url.pathname;

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

Expand Down
6 changes: 1 addition & 5 deletions packages/start/src/server/manifest/dev-client-manifest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,7 @@ export function getClientDevManifest() {
return import(/* @vite-ignore */ join("/", id))
},
async getAssets(id) {
const assetsPath =
join(
import.meta.env.BASE_URL,
`@manifest/client/${Date.now()}/assets?id=${id}`,
);
const assetsPath = `/@manifest/client/${Date.now()}/assets?id=${id}`;

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

Expand Down
8 changes: 2 additions & 6 deletions packages/start/src/server/manifest/dev-ssr-manifest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,9 @@ import { join, normalize } from "pathe";

export function getSsrDevManifest(environment: "client" | "ssr") {
return {
path: (id: string) => normalize(join("/", id)),
path: (id: string) => normalize(join(import.meta.env.BASE_URL, id)),
async getAssets(id) {
const assetsPath =
join(
import.meta.env.BASE_URL,
`@manifest/${environment}/${Date.now()}/assets?id=${id}`,
);
const assetsPath = `/@manifest/${environment}/${Date.now()}/assets?id=${id}`;

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

Expand Down
6 changes: 4 additions & 2 deletions packages/start/src/server/server-fns-runtime.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,13 @@ import { provideRequestEvent } from "solid-js/web/storage";
export function createServerReference(fn: Function, id: string) {
if (typeof fn !== "function")
throw new Error("Export from a 'use server' module must be a function");
const baseURL = import.meta.env.SERVER_BASE_URL ?? "";
let baseURL = import.meta.env.BASE_URL ?? "/";
if(!baseURL.endsWith("/")) baseURL += "/"

return new Proxy(fn, {
get(target, prop, receiver) {
if (prop === "url") {
return `${baseURL}/_server?id=${encodeURIComponent(id)}`;
return `${baseURL}_server?id=${encodeURIComponent(id)}`;
}
if (prop === "GET") return receiver;
return (target as any)[prop];
Expand Down
4 changes: 2 additions & 2 deletions packages/start/src/server/server-functions-handler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -237,7 +237,7 @@ function handleNoJS(
`Location`,
new URL(
result.headers.get("Location")!,
url.origin + import.meta.env.SERVER_BASE_URL,
url.origin + import.meta.env.BASE_URL,
).toString(),
);
statusCode = getExpectedRedirectStatus(result);
Expand Down Expand Up @@ -318,7 +318,7 @@ async function handleSingleFlight(
url = new URL(
result.headers.get("Location")!,
new URL(sourceEvent.request.url).origin +
import.meta.env.SERVER_BASE_URL,
import.meta.env.BASE_URL,
).toString();
}
const event = { ...sourceEvent } as PageEvent;
Expand Down
13 changes: 8 additions & 5 deletions packages/start/src/server/server-runtime.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
// @ts-ignore - seroval exports issue with NodeNext
import { join } from "pathe";
import { deserialize, toJSONAsync } from "seroval";
import {
CustomEventPlugin,
Expand Down Expand Up @@ -193,19 +194,21 @@ async function fetchServerFunction(
}

export function createServerReference(id: string) {
const baseURL = import.meta.env.SERVER_BASE_URL ?? "";
const fn = (...args: any[]) => fetchServerFunction(`${baseURL}/_server`, id, {}, args);
let baseURL = import.meta.env.BASE_URL ?? "/";
if(!baseURL.endsWith("/")) baseURL += "/"

const fn = (...args: any[]) => fetchServerFunction(`${baseURL}_server`, id, {}, args);

return new Proxy(fn, {
get(target, prop, receiver) {
if (prop === "url") {
return `${baseURL}/_server?id=${encodeURIComponent(id)}`;
return `${baseURL}_server?id=${encodeURIComponent(id)}`;
}
if (prop === "GET") {
return receiver.withOptions({ method: "GET" });
}
if (prop === "withOptions") {
const url = `${baseURL}/_server?id=${encodeURIComponent(id)}`;
const url = `${baseURL}_server?id=${encodeURIComponent(id)}`;
return (options: RequestInit) => {
const fn = async (...args: any[]) => {
const encodeArgs = options.method && options.method.toUpperCase() === "GET";
Expand All @@ -217,7 +220,7 @@ export function createServerReference(id: string) {
JSON.stringify(await Promise.resolve(toJSONAsync(args, { plugins })))
)}`
: "")
: `${baseURL}/_server`,
: `${baseURL}_server`,
id,
options,
encodeArgs ? [] : args
Expand Down
Loading