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
8 changes: 7 additions & 1 deletion packages/plugin-vite/src/plugins/dev_server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,13 @@ export function devServer(): Plugin[] {
publicDir = config.publicDir;
},
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) => {
const serverCfg = server.config.server;
Expand Down
18 changes: 18 additions & 0 deletions packages/plugin-vite/tests/dev_server_test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -536,6 +536,24 @@ Deno.test({
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({
name: "vite dev - source mapped stack traces",
fn: async () => {
Expand Down
8 changes: 8 additions & 0 deletions packages/plugin-vite/tests/fixtures/basepath/main.ts
Original file line number Diff line number Diff line change
@@ -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" },
}));
7 changes: 7 additions & 0 deletions packages/plugin-vite/tests/fixtures/basepath/vite.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import { defineConfig } from "vite";
import { fresh } from "@fresh/plugin-vite";

export default defineConfig({
base: "/ui/",
plugins: [fresh()],
});
Loading