Skip to content

Calling fetch service binding requires a request object with 'host' header in vite-plugin runtime #9569

Open
@niba

Description

@niba

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

No response

Describe the Bug

You need to have

  1. Two workers with a service binding between them
  2. Run the worker using vite dev with cloudflare-vite-plugin
  3. Try to call fetch using a service binding

Code in the worker

export default {
  async fetch(request, env) {
      await env.WORKER_API.fetch(request); <-- works
      await env.WORKER_API.fetch(new Request("http://internal/api")); <- doesn't work
  }
}

this code works when you try to run it using wrangler dev,

I found out that if you don't have the "host" header specified in a custom request instance then the request fails with status: 400 and text: "Bad Request".

Please provide any relevant error logs

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    awaiting Cloudflare responseAwaiting response from workers-sdk maintainer teambugSomething that isn't workingvite-pluginRelating to the `@cloudflare/vite-plugin` package

    Type

    Projects

    Status

    Untriaged

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions