LinkRouter is a lightweight, configurable routing application that directs incoming requests to designated target URLs based on a user-defined configuration file.
- Path-based Redirection: Reads a config file that maps paths to redirect URLs. When a request hits a registered path, the router issues an HTTP redirect to the corresponding target.
- Hot Reloading: The config is cached at startup and automatically reloaded when the file changes — no restart required. Example config
- Low Resource Usage: Uses less than 50MB of RAM, making it ideal for constrained environments.
- Metrics Endpoint: Exposes Prometheus-compatible metrics at
:5000/metrics
for easy observability and monitoring. How to use - Docker-Deployable: Comes with a minimal Dockerfile for easy containerized deployment.
Routes are managed via a configuration file, /data/config.json
. You can define paths and their corresponding URLs in this file. The application automatically normalizes routes to handle both trailing and non-trailing slashes.
Every route must start with a slash
{
"RootRoute": "https://example.com", // route on the root on the app (eg: yourdomain.com)
"NotFoundBehavior": { // the behavior when the requested path was not found in the routes below
"RedirectOn404": false, // if it should redirect on 404
"RedirectUrl": "https://example.com/404" // where it should redirect to
},
"Routes": [
{
"Route": "/instagram", // has to start with a slash
"RedirectUrl": "https://instagram.com/{yourname}"
},
{
"Route": "/example", // has to start with a slash
"RedirectUrl": "https://example.com"
}
]
}
Docker is required to deploy this project. Install docker
- Create a
docker-compose.yml
file with the following content:
services:
linkrouter:
image: ghcr.io/mxritzdev/linkrouter:latest
ports:
- "80:8080"
volumes:
- ./data:/app/data
- Run
docker compose up -d
to start the container - Configure your routes in
./data/config.json
- Run this command:
docker run -p 80:8080 -v ./data:/app/data ghcr.io/mxritzdev/linkrouter:latest
- Configure your routes in
./data/config.json
Prometheus-compatible metrics are exposed on :5000/metrics
‼️ Do not expose port5000
to the public internet, instead use internal docker networking
The following metrics are currently exported:
-
linkrouter_requests{route="..."}
— Counter of total redirects served, labeled by route. -
linkrouter_404_requests{route="..."}
— Counter of requests that resulted in a 404 Not Found, labeled by the originally requested route.
Metrics follow the Prometheus exposition format, and can be scraped directly by Prometheus or queried via tools like Grafana. Example Grafana Dashboard
scrape_configs:
- job_name: 'linkrouter'
static_configs:
- targets: ['{linkrouter host}:5000']
Contributions are welcome! Please submit a pull request or open an issue to discuss improvements or new features.
This project is licensed under the MIT License - see the LICENSE file for details.
For questions or support, please reach out via discord at mxritzdev