Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/pkarpovich/env-driven-static-server
Create and assign dynamic environment variables to your SPA at runtime through environment variables. This is ideal for reusing containers across various environments
https://github.com/pkarpovich/env-driven-static-server
docker environment-variables react spa vue
Last synced: 24 days ago
JSON representation
Create and assign dynamic environment variables to your SPA at runtime through environment variables. This is ideal for reusing containers across various environments
- Host: GitHub
- URL: https://github.com/pkarpovich/env-driven-static-server
- Owner: pkarpovich
- License: mit
- Created: 2024-03-25T19:28:34.000Z (11 months ago)
- Default Branch: main
- Last Pushed: 2024-04-10T20:46:09.000Z (10 months ago)
- Last Synced: 2024-11-14T06:30:40.472Z (3 months ago)
- Topics: docker, environment-variables, react, spa, vue
- Language: Shell
- Homepage:
- Size: 8.79 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# env-driven-static-server
## Introduction
`env-driven-static-server` is a flexible solution that enhances the deployment process of frontend applications by dynamically assigning environment-specific variables. With this, you can create a single, reusable container build for different environments, each with their own configurations. Instead of hard-coding variables into your build, this tool allows them to be assigned at the container start, making your deployment process much more flexible
## Usage
To use `env-driven-static-server`, start the container with the necessary environment variables prefixed with `VITE_`. For example:
```sh
docker run -e VITE_API_BASE_URL=http://api.example.com env-driven-static-server
```An example `Dockerfile` for deploying a React application using `env-driven-static-server`:
```Dockerfile
FROM ghcr.io/pkarpovich/env-driven-static-server:latest
COPY --from=builder /app/dist/ /public
```This Dockerfile uses the `env-driven-static-server` as a base image and copies the build artifacts from the `builder` stage into the `/public` directory of the container.
This will inject the environment variables into the frontend application, making them accessible as follows:
```javascript
export const Config = {
API_BASE_URL: import.meta.env.VITE_API_BASE_URL || window._env_.VITE_API_BASE_URL,
};
```## Features
- **Dynamic Environment Variables**: Injects environment variables directly into the frontend application at runtime.
- **Single Build for Multiple Environments**: Eliminates the need for multiple builds for different environments, streamlining the deployment process.
- **Easy Configuration**: Simple and intuitive setup process, requiring minimal changes to existing projects.## License
Project is released under the MIT License. See the [LICENSE](LICENSE) file for more details.