You can deploy it on any PaaS provider like Heroku, Vercel, etc.
Clone this repository and install the dependencies.
git clone https://github.com/mitian233/py-url-shortener.git
cd py-url-shortener
pip install -r requirements.txt
This project uses MongoDB Atlas as the database, so you need to create a MongoDB Atlas account and a database cluster.
Copy the .env.example
file to .env
and fill in the environment variables.
cp .env.example .env
The .env
file should look like this:
MONGO_URL = mongodb+srv://<username>:<password>@<cluster-url>/<database>?retryWrites=true&w=majority
MONGO_DB = Cluster0
MONGO_COLLECTION = ShortenedURLs
URL_LENGTH = 5
SITE_URL = https://s.mikan.ac.cn
Then run the following command to start the server.
gunicorn -b 0.0.0.0:5000 index:app
Set up your reverse proxy like Nginx to forward requests to the server.
✨Your site is on live now!
Click the button below to deploy it on Vercel.
Following the introduction of the environment variables descriped above and edit the Environment Variables in the Vercel dashboard.
Live demo: https://py-url-shortener.vercel.app/