Skip to content

n2o/url-shortener

Repository files navigation

Shorty — The URL Shortener

GitHub Container Registry

A simple URL shortener written in Java. Create shortened links, store them in Redis, and redirect visitors to the original URLs.

Shorty

Only authenticated admins can create or delete short links.

Installation

Note

You need JDK 25+ to build this project. The bundled Gradle wrapper provides Gradle 9.5, so no separate Gradle installation is required — just run ./gradlew.

A running Redis instance is required. Start one with:

docker run -p 6379:6379 redis:alpine

Then start the application. The admin password must be supplied via SHORTY_ADMIN_PASSWORD — there is no default and the application will not start without it:

SHORTY_ADMIN_PASSWORD=change-me ./gradlew bootRun

Usage

Open http://localhost:8080 and log in as an admin. The admin username (SHORTY_ADMIN, default admin) and password (SHORTY_ADMIN_PASSWORD, required) are configured via environment variables. The password is stored hashed (BCrypt), never in plain text.

In the admin menu you can add new short links. Redirect to the original URL by visiting:

http://localhost:8080/<your-short-link>

Important

Open redirect by design. A URL shortener forwards visitors to whatever destination an admin stored, so any short link is an open redirect to an arbitrary site. Destinations are constrained to the http/https schemes — javascript:, data:, file: and the like are rejected both when a link is created and again before each redirect — but the target host itself is not restricted. Only trusted admins can create links.

Docker

We automatically build a Docker image for Shorty.

docker pull ghcr.io/n2o/url-shortener:latest

Browse available versions on the GitHub Container Registry.

Deployment

Tip

Copy skeleton.env to production.env and adjust the values before starting.

Use Docker Compose for a production setup:

docker compose up

This starts a Redis server with persistent storage and exposes the application on port 8080.

Contributing

About

Shorty: The URL Shortener

Topics

Resources

License

Code of conduct

Stars

18 stars

Watchers

2 watching

Forks

Releases

No releases published

Packages

 
 
 

Contributors