Skip to content

Request url received by worker is incorrect when using vite plugin + base option #9567

@cloudkite

Description

@cloudkite

What versions & operating system are you using?

vite: 6.3.5, wrangler: 4.19.2, @cloudflare/vite-plugin: ^1.5.1,

Please provide a link to a minimal reproduction

https://github.com/cloudkite/vite-plugin-test

Describe the Bug

When specifying the base option:

// vite.config.ts
import { cloudflare } from "@cloudflare/vite-plugin";
import react from "@vitejs/plugin-react";
import { defineConfig } from "vite";

export default defineConfig({
  base: "/subpath",
  plugins: [react(), cloudflare()],
});
// worker.ts
export default {
  fetch(request: Request) {
    console.log(request.url);
    return new Response(null, { status: 200 });
  },
};
// main.tsx
import { StrictMode } from "react";
import { createRoot } from "react-dom/client";

function App() {
  return (
    <button
      type="button"
      onClick={() => {
        fetch("/subpath/api/")
      }}
    >
      Click me
    </button>
  );
}

createRoot(document.getElementById("root")).render(
  <StrictMode>
    <App />
  </StrictMode>,
);

When the button is clicked and fetch("/subpath/api/") is invoked, the base seems to be stripped from the URL. The worker console.log prints:
http://localhost/api

I would expect the worker to receive the full url http://localhost/subpath/api

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething that isn't workingvite-pluginRelating to the `@cloudflare/vite-plugin` package

    Type

    Projects

    Status

    Backlog

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions