OPEN SOURCE
An OS Software by
Marco Introini
Open source (MIT license) project for creating a self-hosted URL shortener using Docker container
There is a preconfigured .env.docker file you can customize if you want. The Dockerfile install PHP 8.1 with Apache2 and NodeJS.
To use it simply execute:
docker compose up
To create the first environment inside the container terminal go in /var/www/html directory and execute make first_production
Now you can use admin area and APIs
http://localhost:8005/admin
You can use this program in any directory you want.
make first_production
This will create the database and download every composer package needed
There is a console command for creating users (both administrators and normal users)
php artisan user:create
In the env file you can configure:
You can control everything using the provided administration area, located at /admin
route.
You can list and create the complete URLs for your user in this panel:
Inside the Url detail you can see the complete log calls
For users which are super administration is also possible to create, edit and delete users
You can see the OpenApi version of this APIs in OpenAPI.json file
To register a new user (normal, not administration user)
/api/register
For obtaining the Bearer Token:
/api/login
Example Input
curl --request POST \
--url http://short-url.test/api/login \
--header 'Content-Type: application/x-www-form-urlencoded' \
--data email=mint.dev@pm.me \
--data password=password
Protected with Sanctum, so it needs the bearer token obtained via login
| Method | Url | Note | Result Status | |--------|---------------|------------------------------------|---------------| | GET | /api/url | List all user Urls | 200 | | POST | /api/url | Create a new Url and get short url | 201 | | PUT | /api/url/<ID> | Modify the Url | 200 | | GET | /api/url/<ID> | Get information about a single Url | 200 | | DELETE | /api/url/<ID> | Delete a single Url | 204 |
Input:
{
"url":"http://test.com/test"
}