Got the basic thing doing the thing

This commit is contained in:
swagg boi 2023-10-07 22:48:48 -04:00
parent 4bfa6b1b0f
commit 5b0db04d34
2 changed files with 9 additions and 7 deletions

View file

@ -14,5 +14,4 @@ A "useful" tool for turning hyperlinks into redirects in the name of shortening
## TODO ## TODO
1. Process the form input 1. Why does 'hyperlink' linger even for subsequent GET requests from different clients??
1. Make the return url gzip/base64'd

View file

@ -18,16 +18,19 @@ $router.get(-> $request, $response {
}); });
$router.post(-> $request, $response { $router.post(-> $request, $response {
my $hyperlink = $request.content.{'hyperlink'}; my $return-url = $request.content.{'hyperlink'};
my $url-scheme = $request.headers.{'X-Forwarded-Proto'} || 'http';
say encode-base64(gzip($hyperlink), :str); my $url-host = $request.headers.{'Host'};
my $base-url = $url-scheme ~ '://' ~ $url-host ~ '/';
my $hyperlink = $base-url ~ encode-base64(gzip($return-url), :str);
$response.html($templates.process: 'index', :$hyperlink); $response.html($templates.process: 'index', :$hyperlink);
}); });
# Try a wildcard to catch 'all' path # Try a wildcard to catch 'all' path
$router.get('/**', -> $request, $response { $router.get('/**', -> $request, $response {
my $url = $request.path.substr(1); # Omits the leading slash my $return-url = $request.path.substr(1); # Omits the leading slash
my $redirect-url = gunzip(decode-base64($return-url, :bin));
$response.redirect($url); $response.redirect($redirect-url);
}); });