material-svelte / vite-web-test-runner-plugin

MIT License
39 stars 13 forks source link

substitute proxy for redirect #16

Open a-laughlin opened 3 years ago

a-laughlin commented 3 years ago

Love the plugin! Thanks for your effort on it!

It works seamlessly for many cases. Recently I found a blocking issue attempting to use it with mockserviceworker to intercept tests. The plugin uses a 302 redirect which prevents mockserviceworker from working. Here:

// redirect requests from web dev server to the vite server for the transpiled code
app.use((ctx, next) => {
  ctx.redirect(`${protocol}://localhost:${port}${ctx.originalUrl}`)
})

I attempted writing a patch that substitutes a proxy for the redirect, but haven't been able to get it to work. Any thoughts on what I'm missing? Here's the replaced code using koa-proxies.

app.use(
  proxy('.*', {
    target: `${protocol}://localhost:${port}`,
    changeOrigin: true,
  }),
)

Thanks!

Edit: Also tried the proxy as middleware per https://modern-web.dev/guides/dev-server/proxy-to-other-servers/#add-a-proxy-to-your-server-config ... no luck yet.

Adam

betaboon commented 3 years ago

when i initially hacked this together i tried all sorts of proxy stuff first but couldnt get it to work either. I'm currently out of ideas and time ;)

a-laughlin commented 3 years ago

Gotcha. Thanks for considering. Did you have any threads discussing options with the modern-web folks? I'd be curious to see any dialog from what you tried. If you haven't reached out to them yet, I can give it a shot. Getting a proxy for it will solve a number of problems for my team.

a-laughlin commented 3 years ago

Created a PR