2.5 KiB
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
-
clone and install:
git clone https://git.alv.cx/alvierahman90/urls-txt.git cd urls-txt cargo install --path . -
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 -
run:
urls-txt path/to/urls.txtthe default bind address is
127.0.0.0:3000. this can be changed using the environment variableURLS_TXT_BIND_ADDRESS. -
restart to apply changes.
usage (docker)
a working dockerfile and compose file are provided.
a note on case insensitivity
all shortlinks are case insenitive, due to the lack of urlencoding/decoding.
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, 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 ¯_(ツ)_/¯