workers-sdk icon indicating copy to clipboard operation
workers-sdk copied to clipboard

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

Open cloudkite opened this issue 7 months ago • 0 comments

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

cloudkite avatar Jun 12 '25 08:06 cloudkite