Because I can't find a good short url generator online, I wrote one myself. Based on the Flask framework, using mongoDB as the database, you can use docker-compose to deploy it.
The principle of generating short links is to use the self-increasing ID generated by mongoDB, convert it to 62 binary, and then use it as the suffix of the short link. When using the short URL to access, convert the short link suffix to 10 binary, then query the database according to the ID to obtain the original link, and finally 302 redirect to the original link.
- Edit the
config.docker.ini
file and modifybase_url
to your domain name, and other configurations do not need to be modified. - Run
docker-compose up -d
.
-
Install mongoDB
-
Edit the
config.ini
file, see the file comments for specific configuration. -
Install dependencies
pip install -r requirements.txt
-
Run
python main.py