An asynchronous short link backend written in Python based on fastapi and aiomysql
简体中文 | English
git clone https://github.com/gazedreamily/short-url.git
cd short-url
mysql -u [your mysql username] -p
use [database name]
source [project dir]/surl.sql;
default content of configuration file
database: # configuration of database
host: # servername of database server
port: # port of database server
user: # username of database server
password: # password of database server
database: # name of database on database server
sign: # configuration of authentication
secret: # secret when adding new url
server: # configuration of web server
host: # servername of web server
port: # port of web server
fill in the configuration file according to your own situation before running
Linux
pip3 install -r requirements.txt
Windows
pip install -r requirements.txt
Linux
python3 main.py
Windows
python main.py
Use this server configuration like this
server:
host: a.com
port: 80
protocol: http
The domain name in the database is recorded as
id | source | target | createTime | expireTime |
---|---|---|---|---|
1 | AbcdEfg | https://google.com/ |
When accessing http://a.com/AbcdEfg
, the target will be redirected to https://google.com/
.
The server will return 404
if there is no source record in the database.
When accessing a link, the backend will judge whether the current link has expired. If the link expires, it will delete the link from the database and return 404
When inserting a link, the post carries target_url, current timestamp, signature based on timestamp and secret key, and expiration time (optional).