fix: dev server intercepts Vite URLs when basePath is configured (#3730)
Co-authored-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Opus 4.6
parent
14cff12fcc
commit
e0ee53d458
@@ -14,7 +14,13 @@ export function devServer(): Plugin[] {
|
|||||||
publicDir = config.publicDir;
|
publicDir = config.publicDir;
|
||||||
},
|
},
|
||||||
configureServer(server) {
|
configureServer(server) {
|
||||||
const IGNORE_URLS = /^\/(@(vite|fs|id)|\.vite)\//;
|
// Build the ignore pattern accounting for the configured base path.
|
||||||
|
// Vite prefixes virtual module URLs with the base (e.g. /ui/@id/...),
|
||||||
|
// so we need to match both /@ and /base/@.
|
||||||
|
const base = server.config.base.replace(/\/$/, "");
|
||||||
|
const IGNORE_URLS = new RegExp(
|
||||||
|
`^(${base})?/(@(vite|fs|id)|\\.vite)/`,
|
||||||
|
);
|
||||||
|
|
||||||
server.middlewares.use(async (nodeReq, nodeRes, next) => {
|
server.middlewares.use(async (nodeReq, nodeRes, next) => {
|
||||||
const serverCfg = server.config.server;
|
const serverCfg = server.config.server;
|
||||||
|
|||||||
@@ -536,6 +536,24 @@ Deno.test({
|
|||||||
sanitizeResources: false,
|
sanitizeResources: false,
|
||||||
});
|
});
|
||||||
|
|
||||||
|
// issue: https://github.com/denoland/fresh/issues/3666
|
||||||
|
Deno.test({
|
||||||
|
name: "vite dev - basePath does not intercept Vite URLs",
|
||||||
|
fn: async () => {
|
||||||
|
const fixture = path.join(FIXTURE_DIR, "basepath");
|
||||||
|
await launchDevServer(fixture, async (address) => {
|
||||||
|
// `address` already includes the base path (e.g. http://localhost:PORT/ui)
|
||||||
|
// Vite's /@vite/client should be accessible at {base}/@vite/client
|
||||||
|
// Without the fix, Fresh's dev server intercepted this and returned 404.
|
||||||
|
const viteClientRes = await fetch(`${address}/@vite/client`);
|
||||||
|
await viteClientRes.body?.cancel();
|
||||||
|
expect(viteClientRes.status).toEqual(200);
|
||||||
|
});
|
||||||
|
},
|
||||||
|
sanitizeOps: false,
|
||||||
|
sanitizeResources: false,
|
||||||
|
});
|
||||||
|
|
||||||
Deno.test({
|
Deno.test({
|
||||||
name: "vite dev - source mapped stack traces",
|
name: "vite dev - source mapped stack traces",
|
||||||
fn: async () => {
|
fn: async () => {
|
||||||
|
|||||||
@@ -0,0 +1,8 @@
|
|||||||
|
import { App, staticFiles } from "@fresh/core";
|
||||||
|
|
||||||
|
export const app = new App({ basePath: "/ui" })
|
||||||
|
.use(staticFiles())
|
||||||
|
.get("/", () =>
|
||||||
|
new Response("<h1>ok</h1>", {
|
||||||
|
headers: { "Content-Type": "text/html" },
|
||||||
|
}));
|
||||||
@@ -0,0 +1,7 @@
|
|||||||
|
import { defineConfig } from "vite";
|
||||||
|
import { fresh } from "@fresh/plugin-vite";
|
||||||
|
|
||||||
|
export default defineConfig({
|
||||||
|
base: "/ui/",
|
||||||
|
plugins: [fresh()],
|
||||||
|
});
|
||||||
Reference in New Issue
Block a user