Does vite base url must have trailing slash? #9485
Replies: 2 comments
-
I had to use a custom server to work around this issue. Without a trailing slash on the However, now I'm running into the same issue with a stock Storybook setup. import { createRequestHandler } from "@remix-run/express";
import { installGlobals } from "@remix-run/node";
import express from "express";
installGlobals({ nativeFetch: true });
const port = process.env.PORT ?? 3000;
const viteDevServer =
process.env.NODE_ENV === "production"
? undefined
: await import("vite").then((vite) =>
vite.createServer({
server: { middlewareMode: true },
}),
);
const app = express();
// handle asset requests
if (viteDevServer) {
app.use(viteDevServer.middlewares);
} else {
app.use(
"/assets",
express.static("build/client/assets", {
immutable: true,
maxAge: "1y",
}),
);
}
app.use(express.static("build/client", { maxAge: "1h" }));
// handle SSR requests
app.all(
"*",
createRequestHandler({
build: viteDevServer
? () => viteDevServer.ssrLoadModule("virtual:remix/server-build")
: await import("./build/server/index.js"),
}),
);
app.listen(port, () => {
console.info(`App listening on https://localhost:${port}/base`);
}); |
Beta Was this translation helpful? Give feedback.
-
This I think is issue with preview server only. vite preview server referes vite export default defineConfig(({ mode, isPreview }) => {
const env = loadEnv(mode, process.cwd(), '');
const basePath = env.BASE_PATH || '/user';
return {
// Add trailing slash only for dev or production build
base: isPreview ? basePath : `${basePath}/`,
plugins: [
remix({
ssr: false,
// Keep basename without trailing slash
basename: basePath,
}),
// ... other plugins
],
};
}); you can fix the above way or you can pass vite preview --base=/user |
Beta Was this translation helpful? Give feedback.
-
Background
I set vite's base to
/user
, remix plugin's basename set to '/user' too. It work fine in dev mode. I visitelocalhost:5173/user
andlocalhost:5173/user/
well, but after I build and start, the server can't find assets files, because the url need one slash.So I change
/user
to/user/
, then I can visitelocalhost:5173/user/
only, It's not ok for me.Then I try to set vite's base to
/user/
, remix plugin's basename set to '/user', the terminal throw one error, the error message is belowDoes anyone have the same problem?
Beta Was this translation helpful? Give feedback.
All reactions