redirector/README.md

63 lines
1.4 KiB
Markdown
Raw Normal View History

2023-07-07 08:24:11 +02:00
# Redirector
Simple redirection service.
2024-03-08 10:09:15 +01:00
Runs on [Bun](https://bun.sh) and uses [Hono](https://hono.dev).
2023-07-07 08:24:11 +02:00
2024-03-08 10:12:33 +01:00
Can be adapted to run on Node, Cloudflare Workers, or any other serverless platform.
2023-07-07 08:24:11 +02:00
Available as a [Docker image](https://hub.docker.com/r/nzambello/redirector).
2023-07-07 08:28:25 +02:00
Repository: [nzambello/redirector](https://git.nzambello.dev/nzambello/redirector).
2023-07-07 08:24:11 +02:00
## Usage
2023-07-07 08:28:25 +02:00
```sh
2023-07-07 08:24:11 +02:00
yarn install
2024-03-08 10:09:15 +01:00
REDIRECT_URL=https://nzambello.dev PERMANENT=true PRESERVE_PATH=false bun start
2023-07-07 08:15:37 +02:00
```
2023-07-07 08:36:31 +02:00
Then, open http://localhost:8787/ in your browser.
2023-07-07 08:24:11 +02:00
2023-07-07 08:28:25 +02:00
```sh
2023-07-07 08:36:31 +02:00
open http://localhost:8787
2023-07-07 08:15:37 +02:00
```
2023-07-07 08:24:11 +02:00
and you will be redirected to `REDIRECT_URL` from your env.
2023-07-07 08:25:39 +02:00
### Configuration
2023-07-07 08:24:11 +02:00
It loads configuration from environment variables:
2023-07-07 08:25:39 +02:00
- `REDIRECT_URL`: (**required**) the url to redirect to
2023-07-07 08:24:11 +02:00
- `PERMANENT`: if true, it will return a 301 status code, otherwise 302
2024-03-07 17:39:15 +01:00
- `PRESERVE_PATH`: if true, it will preserve the path of the original request
2023-07-07 08:24:11 +02:00
2023-07-07 08:28:25 +02:00
### Docker example
2023-07-07 08:25:39 +02:00
2023-07-07 08:28:25 +02:00
```sh
2024-03-08 10:09:15 +01:00
docker run -p 8787:8787 -e REDIRECT_URL=https://nzambello.dev -e PERMANENT=true -e PRESERVE_PATH=false nzambello/redirector:latest
2023-07-07 08:25:39 +02:00
```
2023-07-07 08:28:25 +02:00
### Docker compose example
2023-07-07 08:24:11 +02:00
```yaml
version: "3.8"
services:
redirector:
image: nzambello/redirector:latest
environment:
- REDIRECT_URL=https://nzambello.dev
- PERMANENT=true
2024-03-07 17:41:31 +01:00
- PRESERVE_PATH=false
2023-07-07 08:24:11 +02:00
ports:
2023-07-07 08:35:51 +02:00
- 8787:8787
2023-07-07 08:15:37 +02:00
```
2023-07-07 08:28:25 +02:00
## Development
To update the Docker image:
```sh
docker buildx build --platform linux/amd64,linux/arm64 -t nzambello/redirector:latest --push .
```