SPA (Single-page application) runtimes for portable builds.
A Sparse runtime replaces Environment Variable references in the SPA entrypoint HTML with their values from the Environment.
- Clone this repository OR create an
index.html
entrypoint
<!DOCTYPE html>
<html lang="en">
<body>
<script type="text/javascript">
window.config = {
API: "$API_URL",
};
</script>
</body>
</html>
- Launch the sparse runtime, e.g: docker-nginx
docker run \
--volume $(PWD):/srv \
--publish 8080:8080 \
--env API_URL="https://api.example.com" \
ghcr.io/pr-mpt/sparse-docker-nginx
- Observe Environment Variable replacement in page source at localhost:8080⇗
open http://localhost:8080
<!DOCTYPE html>
<html lang="en">
<body>
<script type="text/javascript">
window.config = {
API: "https://api.example.com",
};
</script>
</body>
</html>
- Environment Variables are strings
- Default to empty string value
- Replacement must be performed at startup, may be performed on each request
index.html
is the application Entrypoint where variables are replaced- Passthrough all other paths to the filesystem
- Allow port specification, default to 8080
- Docker + nginx
- Netlify
- Fly
- Cloudflare Functions
- Binary