Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Miniflare is not responding once #63

Closed
Kikobeats opened this issue Oct 13, 2021 · 4 comments
Closed

Miniflare is not responding once #63

Kikobeats opened this issue Oct 13, 2021 · 4 comments
Labels
fixed-in-next Fixed in next release

Comments

@Kikobeats
Copy link
Contributor

Kikobeats commented Oct 13, 2021

Current behavior

const { Miniflare } = require('miniflare')

;(async () => {
  const mf = new Miniflare({
    script: `
    addEventListener('fetch', async event => {
      event.respondWith(new Response('one'))
      event.respondWith(new Response('two'))
    })
    `
  })
  const res = await mf.dispatchFetch('http://localhost:8787/')
  console.log(await res.text()) // 'two', wrong!
})()

Expected behavior

CleanShot 2021-10-13 at 16 11 12@2x

@mrbbot
Copy link
Contributor

mrbbot commented Oct 13, 2021

Hey! 👋 When I try this with wrangler dev or on the playground, I actually get an exception thrown by the second respondWith. This behaviour has been implemented in Miniflare 2:

if (this[kResponse]) {
throw new DOMException(
"FetchEvent.respondWith() has already been called; it can only be called once.",
"InvalidStateError"
);
}

I agree that Miniflare 1's behaviour here is incorrect though. Could you try your playground example again?

@Kikobeats
Copy link
Contributor Author

oh, first notice about v2. Is it available at npm?

@mrbbot
Copy link
Contributor

mrbbot commented Oct 13, 2021

Not yet, will hopefully be able to get a beta out in the next few weeks. 🤞

@mrbbot mrbbot added the fixed-in-next Fixed in next release label Oct 19, 2021
@mrbbot
Copy link
Contributor

mrbbot commented Oct 27, 2021

Hey! 👋 The first pre-release of Miniflare 2 has just been released, including this change. You can find the full changelog here and install it with npm i miniflare@next -D. Please let me know if you have any other issues, and feel free to ask questions in the #miniflare channel of the Cloudflare Workers Discord server.

@mrbbot mrbbot closed this as completed Oct 27, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
fixed-in-next Fixed in next release
Projects
None yet
Development

No branches or pull requests

2 participants