Q: Explain why you need to build your own URL shortening service.
A: The main purpose of building your own URL shortening service is to make it convenient for users to access long URLs. By shortening long URLs, users can remember and share shorter URLs, making it easier and faster to access the target page. In addition, building your own URL shortening service can also improve the security of the website, as shortened URLs can hide the real address of the target URL, preventing hackers from using the real address for attacks. Furthermore, using shortened URLs can also help websites better manage links and track traffic sources.
The following tutorial is about building a free URL shortening service on Northflank.
0/ Pre#
- Register a Maxmind account and generate an authorization code for backup.
- Register at https://northflank.com/ and link a card (to prevent abuse).
1/ Setup#
Create a free Project
Create a database
After successful creation, record the connection information for later use.
Create a service
Enter shlinkio/shlink:stable
in the Image path
field.
Fill in the Environment variables
according to the following content:
DEFAULT_DOMAIN="long.ee"
IS_HTTPS_ENABLED="true"
DB_DRIVER="postgres"
DB_HOST=""
DB_PASSWORD=""
DB_USER=""
DB_NAME=""
GEOLITE_LICENSE_KEY=""
In the above, fill in your own domain for DEFAULT_DOMAIN
, and fill in the information recorded in the previous step for DB_
, and fill in the information recorded in step 0 for GEOLITE_LICENSE_KEY
.
Click on create.
Bind a domain
Then follow the instructions to create a TXT
record to verify the domain and create a CNAME
record to bind the domain.
Create an API
Enter shlink api-key:generate
to create an API Key.
2/ Usage#
Go to the Shlink Web APP:
- Official: https://app.shlink.io
- Provided by the author: https://app.long.ee
- Or self-hosted: https://github.com/shlinkio/shlink-web-client
Click on Add a server
and enter the name, backend address, and API Key to create and use it.