/shrt

Modern link shortener service written in Rust [WIP]

Primary LanguageRustGNU Affero General Public License v3.0AGPL-3.0

shrt

Rust Build Status Docker Build Status GNU AGPL v3 licensed

Shrt is a modern link shortener service written in Rust. It is designed to be fast, secure, and easy to use. It is composed of two parts: the backend, which is a RESTful API, and the frontend, which is a single-page application.

Development

The project is written purely in Rust, both its backend and frontend.

Backend

To run the development server, execute:

cd shrt-backend
cargo run

This will start the server at localhost:8000.

To build a release version, execute:

cargo build --release

The target binary will be put at target/release/shrt-backend.

Frontend

Frontend uses the yew framework. The code is compiled into a WebAssembly binary and then statically served.

First, install the Trunk bundler and add wasm32 target support to your Rust toolchain.

rustup target add wasm32-unknown-unknown
cargo install trunk

Then, you can use:

cd shrt-frontend
trunk serve

to start local server at localhost:8080. It assumes that the backend is running at localhost:8000.

To build a distributable version of the frontend, execute:

trunk build --release

This will build a website in frontend/dist/ directory that can be statically served by a server such as nginx. You can override th backend URL by providing it as the SHRT_API_URL environment variable, like so:

export SHRT_API_URL=http://api.shrt.example.com
trunk build --release

pre-commit

We encourage contributors to use predefined pre-commit hooks — to install them in your local repo, make sure you have pre-commit installed and run:

pre-commit install

Deployment

The easiest way to try locally or deploy shrt is to use auto-generated Docker images. There is a separate image for backend, frontend, and a reverse proxy (that exposes both the backend and frontend under the same server), all of which are published on the GitHub Container Registry. There is an example docker-compose.yml file provided in the repository root.

In the project root directory, execute:

docker compose up -d

After that, the website will be available on at localhost:8000.