Hyperlink-Redirect/lib/Hyperlink-Redirect.rakumod

34 lines
878 B
Raku
Raw Normal View History

2023-09-23 04:44:32 +00:00
use Humming-Bird::Core;
2023-09-24 04:45:18 +00:00
use Template6;
use Base64;
use Libarchive::Filter :gzip;
2023-09-23 04:44:32 +00:00
# Normally would 'use' local libs here for Controller and Model and
# what not but keeping it simple for now...
2023-09-24 04:52:15 +00:00
# Set things up (config stuff would go here?)
2023-09-24 04:45:18 +00:00
my $templates = Template6.new;
$templates.add-path: 'templates';
2023-09-23 04:44:32 +00:00
# Must set the root path lest yet miss setting $!root
my $router = Router.new(root => '/');
$router.get(-> $request, $response {
2023-09-24 04:45:18 +00:00
$response.html($templates.process: 'index');
2023-09-23 04:44:32 +00:00
});
2023-10-07 19:15:55 +00:00
$router.post(-> $request, $response {
my $hyperlink = $request.content.{'hyperlink'};
say encode-base64(gzip($hyperlink), :str);
$response.html($templates.process: 'index', :$hyperlink);
2023-10-07 19:15:55 +00:00
});
# Try a wildcard to catch 'all' path
$router.get('/**', -> $request, $response {
my $url = $request.path.substr(1); # Omits the leading slash
$response.redirect($url);
});