serve-handler icon indicating copy to clipboard operation
serve-handler copied to clipboard

Allow serving virtual files

Open lmeysel opened this issue 8 months ago • 0 comments

We just stumbled across the issue where we needed to create a file dynamically and serve it.

Our usecase: We need to inject environment variables from the server prefixed by REACT_APP_. I guess the normal case is, that these env vars cannot be known at built time, thus are not baked into the assets. We need to supply them dynamically. We used to handle this using the react-inject-env package, but now we have an environment where the file system is readonly, thus it cannot create the env.js and therefore this approach becomes useless.

It would be nice to have an additional configuration option, e.g.

handler(request, response, {
  virtualFiles: [
    { source: 'env.js', content: myPreComputedEnvJs, type: 'application/json' }
  ]
})

which should also integrate nicely with e.g. the headers field.

lmeysel avatar Apr 22 '25 12:04 lmeysel