chela/README.md

108 lines
3.7 KiB
Markdown
Raw Normal View History

2024-04-07 17:40:10 +00:00
[![Build and Push Docker Image](https://github.com/secondary-smiles/chela/actions/workflows/docker-image.yml/badge.svg)](https://github.com/secondary-smiles/chela/actions/workflows/docker-image.yml)
[![Docker Image Size](https://img.shields.io/docker/image-size/secondsmiles/chela)](https://hub.docker.com/r/secondsmiles/chela)
2024-04-06 15:00:15 +00:00
# Chela
Chela is a minimal URL shortener built in Rust. It is named after the small claw on crustaceans.
## Usage
2024-04-06 16:55:32 +00:00
You can create a redirect by navigating to the `/create` page and filling out the form. By default, every path passed to Chela will be treated as a redirect except `/` and `/create`.
2024-04-06 15:00:15 +00:00
## Install and Run
### With Docker
#### CLI
```bash
2024-04-07 18:44:03 +00:00
$ docker run -d \
2024-04-06 15:00:15 +00:00
-p 3000:3000 \
-e DATABASE_URL=postgres://chela:password@dbhost/postgres?sslmode=disable \
2024-04-07 17:35:59 +00:00
-e CHELA_HOST=a.com \
2024-04-06 15:00:15 +00:00
secondsmiles/chela
```
#### Docker Compose
```yaml
services:
chela-postgres:
image: postgres:15
environment:
- POSTGRES_USER=chela
- POSTGRES_PASSWORD=password
volumes:
- chela-db:/var/lib/postgresql/data
2024-04-06 16:45:47 +00:00
restart: unless-stopped
2024-04-06 15:00:15 +00:00
chela:
image: secondsmiles/chela
ports:
- 3000:3000
environment:
2024-04-06 16:45:47 +00:00
- DATABASE_URL=postgres://chela:password@chela-postgres/postgres?sslmode=disable
2024-04-07 17:35:59 +00:00
- CHELA_HOST=a.com
- CHELA_MAIN_PAGE_REDIRECT='https://example.com'
2024-04-07 18:44:03 +00:00
- CHELA_BEHIND_PROXY=1
2024-04-06 15:00:15 +00:00
depends_on:
2024-04-06 16:45:47 +00:00
- chela-postgres
restart: unless-stopped
2024-04-06 15:00:15 +00:00
volumes:
chela-db:
```
#### Environment Variables
##### `DATABASE_URL`
Used to define the database connection for Chela to use.
##### `CHELA_HOST`
2024-04-06 16:51:08 +00:00
The hostname that Chela should refer to itself as. Defaults to `localhost`.
##### `CHELA_LISTEN_ADDRESS`
The address that Chela should listen on. Defaults to `0.0.0.0`.
2024-04-06 15:00:15 +00:00
2024-04-07 17:35:59 +00:00
##### `CHELA_MAIN_PAGE_REDIRECT`
A page that Chela will redirect to when `/` is requested instead of replying with the default homepage.
2024-04-07 18:44:03 +00:00
##### `CHELA_BEHIND_PROXY`
If this variable is set, Chela will use the `X-Real-IP` header as the client IP address rather than the connection address.
##### `CHELA_UNIX_SOCKET`
If you would like Chela to listen for HTTP requests over a Unix socket, set this variable to the socket path that it should use. By default, Chela will listen via a Tcp socket.
##### `CHELA_ALPHABET`
2024-04-08 00:40:44 +00:00
If this variable is set, Chela will use the characters in `CHELA_ALPHABET` to create IDs for URLs. The default alphabet is `abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ`. See [here](https://sqids.org/faq#unique) for more information on Sqids alphabets.
2024-04-06 15:00:15 +00:00
### Manually
#### Build
```bash
$ git clone https://github.com/secondary-smiles/chela.git
$ cd chela
$ cargo build -r
```
#### Run
```bash
$ export DATABASE_URL=postgres://chela:password@dbhost/postgres?sslmode=disable
2024-04-07 17:35:59 +00:00
$ export CHELA_HOST=a.com
2024-04-06 16:51:08 +00:00
$ export CHELA_LISTEN_ADDRESS=127.0.0.1
2024-04-06 15:00:15 +00:00
$ ./target/release/chela
```
## Hosting
Chela uses the [axum](https://crates.io/crates/axum) to manage HTTP requests, so it is possible to expose it directly to the outer internet. However, there is no authentication for the `/create` endpoint so anyone will be able to create redirects.
If you would prefer to be the only one able to create redirects, then you can proxy Chela through Nginx with http-basic-auth. Refer to [this](https://docs.nginx.com/nginx/admin-guide/security-controls/configuring-http-basic-authentication/) documentation for more information.
```nginx
server {
server_name example.com;
location / {
proxy_pass http://localhost:3000/;
2024-04-07 18:44:03 +00:00
proxy_set_header X-Real-IP $remote_addr;
2024-04-06 15:00:15 +00:00
limit_except GET HEAD {
auth_basic 'Restricted';
auth_basic_user_file /path/to/your/.htpasswd;
}
}
}
```