oh cool, there's a miniflare channel ๐Ÿ™‚ I just worked on a prototype for developing multiple workers

oh cool, there's a miniflare channel ๐Ÿ™‚ I just worked on a prototype for developing multiple workers but had to use express. Tried to use the
workers
array but the contents of /scripts/ can change during dev, and this way the latest script is used for each request. is this an ok approach?
app.use('/:name/*', async (req, res) => {
  const mf = new Miniflare({
    scriptPath: `./scripts/${req.params.name}/index.js`,
    bindings: process.env,
  })
  const url = `http://localhost:8787${req.originalUrl}`
  const queryRes = await mf.dispatchFetch(url, {
    method: req.method,
    headers: req.headers,
    body: req.body,
  })
  res.send(await queryRes.text())
  await mf.dispose()
})
Was this page helpful?