95 lines
2.5 KiB
Markdown
95 lines
2.5 KiB
Markdown
# urls-txt
|
|
|
|
a _really_ simple url shortener: less than 200 lines of Rust and one dependency (tokio).
|
|
there is no database, just a text file.
|
|
|
|
## usage
|
|
|
|
0. clone and install:
|
|
|
|
```
|
|
git clone https://git.alv.cx/alvierahman90/urls-txt.git
|
|
cd urls-txt
|
|
cargo install --path .
|
|
```
|
|
1. create a list of links:
|
|
|
|
```
|
|
lines that don't start with a slash (/) are ignore (they're comments)
|
|
shortlink followed by redirect link, separated by a space character
|
|
/ http://alv.cx everything after the link is ignored (they're comments)
|
|
/urls-txt http://git.alv.cx/alvierahman90/urls-txt
|
|
```
|
|
|
|
2. run:
|
|
|
|
```
|
|
urls-txt path/to/urls.txt
|
|
```
|
|
|
|
the default bind address is `127.0.0.0:3000`.
|
|
this can be changed using the environment variable `URLS_TXT_BIND_ADDRESS`.
|
|
|
|
3. restart to apply changes.
|
|
|
|
## usage (docker)
|
|
|
|
a working [dockerfile](./Dockerfile) and [compose file](./compose.yaml) are provided.
|
|
|
|
## a note on case insensitivity
|
|
|
|
all shortlinks are case insenitive,
|
|
due to the lack of [urlencoding/decoding](#a-note-on-urlencoded-characters).
|
|
|
|
## a note on urlencoded characters
|
|
|
|
this program does not decode urlencoded strings before checking if strings match.
|
|
this is a deliberate choice to keep things as simple as possible.
|
|
|
|
avoid using links that may be encoded.
|
|
|
|
for links that will necessarily get encoded (still discouraged) (such as emojis),
|
|
put the urlencoded string.
|
|
for example, for the link <http://pls.cx/🤬> the following line is in my urls.txt:
|
|
|
|
```
|
|
/🤬 https://en.wikipedia.org/wiki/Controversies_of_Nestl%C3%A9 you may want the non-encoded version in case a client does not encode it? idk
|
|
/%f0%9f%a4%ac https://en.wikipedia.org/wiki/Controversies_of_Nestl%C3%A9
|
|
```
|
|
|
|
## why?
|
|
|
|
all url shorteners i've come across are too complicated:
|
|
they have account management and remote APIs and whatnot.
|
|
too complicated.
|
|
|
|
this includes my own [sus url shortener](https://pls.cx/sus),
|
|
which for some reason i decided should use redis for its database and have a HTTP API for
|
|
updating it.
|
|
|
|
### why not just configure your reverse proxy?
|
|
|
|
good question.
|
|
i'm not sure, but i think i want to separate my concerns?
|
|
you might just want to configure your reverse proxy instead:
|
|
|
|
#### caddy
|
|
|
|
```
|
|
pls.cx {
|
|
redir / http://alv.cx
|
|
redir /urls-txt https://git.alv.cx/alvierahman90/urls-txt
|
|
}
|
|
```
|
|
|
|
#### nginx
|
|
|
|
```
|
|
location / { return 301 http://alv.cx; }
|
|
location /urls-txt { return 301 https://git.alv.cx/alvierahman90/urls-txt; }
|
|
```
|
|
|
|
#### apache
|
|
|
|
there's probably a way ¯\_(ツ)_/¯
|