Small app making short urls.
-
Clone the repository
-
go build
-
Set the environment variables:
SHORTURL_POSTGRES_USER
(f.eadmin
)SHORTURL_POSTGRES_PASSWORD
(f.eadmin
)SHORTURL_SERVER_ADDRESS
(f.elocalhost:8000
)
For HTTPS support:
SHORTURL_HTTPS_ADDRESS
(f.elocalhost:8080
)SHORTURL_CERTFILE
(public key, path to the .crt/.pem file)SHORTURL_KEYFILE
(private key, path to the .key file)
-
./shorturl
-
Create short link
Item Value required? URL shorturl.space/api/new
yes Request type POST yes Request body(JSON) {urlOriginal: $url}
, where$url
is the URL to be shortened.yes Headers Content-Type: application/json
yes Further request requirements:
$url
must be a valid URL link (parsable by golang url.ParseRequestURI)- The URL Host in
$url
must not beshorturl.space
- Request body must not exceed 8192 bytes
$url
length must not exceed 2048 bytes
Examples (TODO):
Request Result POST /api/new
,Content-Type: application/json
, Request Body:{"urlOriginal": "https://example.com"}
{"urlOriginal":"https://example.com","urlCode":"RML25P","expiresOn":"2024-06-19T20:10:14.006018-04:00"}
-
Short link access
Item Value required? URL shorturl.space/$code
, where$code
follows regex[1-9A-Z]{6}
yes Request type GET yes Further request requirements:
$code
must be valid (obtained through/api/new
request and not expired)
Response:
- Static HTML page that redirects to the original URL linked to the $code.
- Status code 200
Errors:
404 Not Found
if the code isn't valid.
-
Static files
File Request ./index.html
GET shorturl.space/
./index.css
GET shorturl.space/index.css
./index.js
GET shorturl.space/index.js