Allow serving virtual files

Open
#223 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Assessment

Difficulty
4/5
Estimated time
3-5 days
Newbie friendliness
42/100
Issue type
Feature
Clarity
Mostly clear
Activity status
Stale
Tech stack
javascript
Domain
api, backend

Research direction

Start at the handler configuration and the existing headers handling, then trace how requested paths are resolved to served files. Done means a configured virtual file can be served from a read-only filesystem and its response headers integrate with the headers option, with behavior verified for the proposed env.js use case.

Written by the indexing model from the issue text.

Description

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.

Dominant language
JavaScript
Stars
618
Forks
117
PR merge metrics
No merged PRs in 30d

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from vercel/serve-handler

All issues in vercel/serve-handler

Similar issues

More JavaScript issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.