Skip to content

brass75/shorty

Repository files navigation

Shorty - The Spiderweb URL Shortener

Ruff Actions status Mastodon Follow

My friend, Joe Kaufeld decided he wanted to understand how web frameworks actually work. So he wrote one. I decided I would be a good guinea pig for it and that it would be a fun project for me to play with - and give me a reason to take UV out for a spin - for me to use Spiderweb to write a URL shortener. So I did. And that's what this is.

You should be aware that I am not, at my core, a web developer. I know the basics and that's about it. I'm not a DB person, I know the basics and that's about it. My initial goal was to write something that would shorten a URL and give that shortened URL back and that when you clicked on that link it would take you where you want to go. So I did and that's what this is.

For now, I decided, since this is a weekend project, to keep it simple. Just get something that works. The data store is a JSON file. There is no good handling of hash collisions. But it works. And it only took me a couple of hours of tinkering to get it there.

Right now it:

  • Allows you to add a URL.
  • Redirects properly to a known shortened URL.
  • Uses persistent storage (in the form of a JSON file.)
  • Gives an error on hash collision.
  • Redirects back to the add route page for an unknown short code.
  • Add methods to see what URLs are stored.
  • Add a method for a custom short URL.

Future plans:

  • Handle hash collision.
  • Use an actual DB as a data store.

If you want to run this locally

All you need to do is:

git clone [email protected]:brass75/shorty.git
cd shorty
uv run src/app.py

NOTE: This is my first time playing with uv as I noted above. You might need to run:

uv python install 3.12

before the uv run line (and you definitely need to install uv but I've linked to them above so you can pick how you want to do it from there) to install the correct version of Python for the venv, but I'm not 100% sure.

Using Docker

Support for Docker has been added.

docker compose up --build

The Docker container will mount ./data for persistent storage of config and the data store. You can also use this to update the templates without restarting by declaring an alternate path for the templates in the config file.

The Docker implementation will bind to port 80 so simply going to http://localhost should be enough for initial access.

About

URL Shortener created using Spiderweb Framework

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published