A lightweight URL shortener built with Go. 中文版本
Edit the config/redirects.toml
file and Shorts will automatically reload the configuration.
# config/redirects.toml
[temporary]
"discord" = "https://discord.gg/9yYtgA4HXz"
[permanent]
"google" = "https://www.google.com"
Add experimental redirects as temporary redirects (307) and change them to permanent redirects (301) for faster redirection.
With the above configuration:
curl -v localhost:8080/discord
< HTTP/1.1 302 Found
< Content-Type: text/html; charset=utf-8
< Location: https://discord.gg/9yYtgA4HXz
< Date: Sun, 08 Sep 2024 14:28:11 GMT
< Content-Length: 52
<
<a href="https://discord.gg/9yYtgA4HXz">Found</a>.
curl -v localhost:8080/google
< HTTP/1.1 301 Moved Permanently
< Content-Type: text/html; charset=utf-8
< Location: https://www.google.com
< Date: Mon, 09 Sep 2024 08:38:22 GMT
< Content-Length: 57
<
<a href="https://www.google.com">Moved Permanently</a>.
Shorts records the number of visitors and the last visited time for each redirect in config/stats.json
.
{
"discord": {
"visitors": 1,
"last_visited": "2024-09-08T22:28:11.894270007+08:00"
},
"google": {
"visitors": 1,
"last_visited": "2024-09-09T16:38:22.113075596+08:00"
}
}
We recommend deploying Shorts using Docker.
docker run -d -p 8080:8080 \
-v $PWD/config:/config \
ghcr.io/ntut-npc/shorts
See docs/compose.yaml for an example Docker Compose configuration.
To set up Shorts for local development:
-
Clone the repository:
git clone https://github.com/ntut-npc/shorts.git cd shorts
-
Run the dev script:
scripts/dev.sh
The server will start on http://localhost:8080
. Remember to create and configure your config/redirects.toml
file as described in the Hot-Reloading Configuration section to set up your redirects.