Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/lblod/api-proxy-service
Proxy calls while adding headers
https://github.com/lblod/api-proxy-service
Last synced: 23 days ago
JSON representation
Proxy calls while adding headers
- Host: GitHub
- URL: https://github.com/lblod/api-proxy-service
- Owner: lblod
- License: mit
- Created: 2024-05-27T07:00:22.000Z (7 months ago)
- Default Branch: master
- Last Pushed: 2024-10-28T08:34:09.000Z (2 months ago)
- Last Synced: 2024-10-28T09:23:34.230Z (2 months ago)
- Language: TypeScript
- Size: 63.5 KB
- Stars: 0
- Watchers: 5
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# API Proxy Service
Yes, this is yet another proxy service in LBLOD stack.
This particular proxy service proxies all calls made to `/` to the configured `API_URL`, while adding the configured `API_KEY` to the header and checking if the session has allowed roles assigned.
## Configuration
The following environment variables can be set to configure the service:
- `API_URL`: The URL to which all calls are proxied.
- `API_KEY`: The API key to be used for the proxied calls.
- `API_KEY_HEADER`: The header to which the API key is added. Default is `X-Api-Key`.
- `REQUIRED_ROLES`: A comma-separated list of roles that are required to access the service. Default is empty. If set, the service will check if the session has any of the roles assigned before proxying the call. If not set or empty, no check is performed.
- `ALLOWED_ORIGIN`: A static override for the access-control-allow-origin header to be set for every response. Defaults to not setting this header.## Setup in a `mu-semtech` Docker stack
### `dispatcher.ex`
Service relies on the `mu-identifier` and `mu-dispatcher` service to forward requests to the proxy service.
```elixir
match "/api-proxy-service/*path" do
forward conn, path, "http://api-proxy-service/"
end
```### `docker-compose.yml`
```yaml
api-proxy-service:
image: lblod/api-proxy-service:latest
links:
- database:database
environment:
API_URL: "https://SOME_URL.COM"
API_KEY: "SOME_KEY"
REQUIRED_ROLES: "ONE,OR_MORE,ROLES"
restart: always
```## Setup without a `mu-semtech` stack
It is possible to use this service without a `mu-identifier` or `mu-dispatcher`, but this is not recommended for production use.
You will need to publish port `80` somehow, either in the docker-compose config for the service or by using a reverse proxy in a docker network.
If your frontend is not running on the same domain as `api-proxy-service`, then you will need to set the `ALLOWED_ORIGIN` environment variable to match that of your frontend, or `*`.