Skip to content

gazedreamily/short-url

Repository files navigation

short_url

maven maven maven

An asynchronous short link backend written in Python based on fastapi and aiomysql

简体中文 | English

Run

Clone code and enter the dir

git clone https://github.com/gazedreamily/short-url.git
cd short-url

Connect to your mysql database

mysql -u [your mysql username] -p

Create table

use [database name]
source [project dir]/surl.sql;

Change configuration file

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

Install the operating environment

Linux

pip3 install -r requirements.txt

Windows

pip install -r requirements.txt

just run it!

Linux

python3 main.py

Windows

python main.py

Usage

Visit

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.

ExpireTime

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

Insert a link

When inserting a link, the post carries target_url, current timestamp, signature based on timestamp and secret key, and expiration time (optional).

About

short url on fastapi

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published