Sign inSign up

mja00/shortener

By mja00

•Updated over 1 year ago

A Python based url shortener

Image
Web servers
Content management system
0

905

mja00/shortener repository overview

⁠shortener

Docker Pulls GitHub Workflow Status

Python based URL shortener using Flask, written in an afternoon.

⁠Setup

You'll want to clone the repo into a folder, doesn't really matter where.
git clone https://github.com/mja00/shortener/

Once cloned you just need to start up the containers with docker-compose -f docker-compose.prod.yml up -d --build. This will build and deploy the containers. Since this uses a DB migration system we'll need to setup the DB with all needed tables, run docker-compose -f docker-compose.prod.yml exec web flask db upgrade.

You now have a running instance. Port 5000 is exposted only to the local host and not accessible over the internet. You'll need some form of reverse proxy or change the exposed ports.

Once on the site you'll need to register an account at the /register path. Create an account and login, you're all ready to create links. I highly recommend putting the /register and /login paths behind some form of firewall. This'll ensure only you can create an account and login. There's no protection from other logged in users from editing each other's links since I mostly wrote this for myself.

If you ever need to access the DB you can do so through docker-compose -f docker-compose.prod.yml exec db psql --username=shortener --db=shortener_prod, replacing any info if you changed it in the env files.

⁠Development

Clone the repo and cd in. Then you want to run docker-compose up -d --build this'll build and start the containers needed and bind to port 5000. Like above run docker-compose exec web flask db upgrade to setup the development DB. Enjoy!

⁠Environment variables

VariableDefaultDescription
DATABASE_URLNoneThe database connection string. See SQLALCHEMY_DATABASE_URI @ https://flask-sqlalchemy.palletsprojects.com/en/2.x/config/⁠
DISABLE_REGISTRATIONFalseDisables the registration on the site
SECRET_KEYCHANGEMEA secret key that will be used for securely signing the session cookie and can be used for any other security related needs
ROOT_REDIRECTNoneA page to re-direct the root url to.
THEMEdarklyA Bootswatch⁠ theme name
API_KEYCHANGEMEThe API key to use for the API.
ENABLE_APITrueEnables the API.
API_USER_IDNoneThe user ID to use for the API.

⁠API

The API is currently very basic. The routes are listed below along with their parameters and responses.

⁠GET /api/links/active

Returns a list of all active links.

⁠GET /api/links/expired

Returns a list of all expired links.

⁠GET /api/links/deleted

Returns a list of all deleted links.

Returns the link with the given ID.

⁠POST /api/links

Creates a new link. Use the following json body:

{
    "url": "https://google.com/api",
    "alias": "api-test-expire-date",
    "max_click_count": 5, // Optional
    "expiration_date": 1675399834 // Optional
}

Updates the link with the given ID. Use the following json body:

{
    "url": "https://google.com/api",
    "alias": "api-test-expire-date",
    "max_click_count": 5, // Optional
    "expiration_date": 1675399834 // Optional
}

Deletes the link with the given ID.

Restores the link with the given ID.

Hard deletes the link with the given ID.

⁠Contributing

Feel free to make PRs or open issues. I don't know how much I'll be adding things, kinda wrote this for myself and felt like opening it up.

Tag summary

Content type

Image

Digest

sha256:5337c54d4…

Size

76.2 MB

Last updated

over 1 year ago

docker pull mja00/shortener