Add meta refresh option
This commit is contained in:
parent
b8208fe50f
commit
92bf9c75ed
|
@ -26,18 +26,36 @@ $router.get(-> $request, $response {
|
|||
|
||||
$router.post(-> $request, $response {
|
||||
my Str $return-url = $request.content.{'hyperlink'};
|
||||
my Bool $meta-refresh = $request.content.<meta-refresh> ?? True !! False;
|
||||
my Str $url-scheme = $request.headers.{'X-Forwarded-Proto'} || 'http';
|
||||
my Str $url-host = $request.headers.{'Host'};
|
||||
my Str $base-url = $url-scheme ~ '://' ~ $url-host ~ '/';
|
||||
my Str $hyperlink = $base-url ~ encode-base64(gzip($return-url), :str);
|
||||
my Str %stash =
|
||||
my (Str $base-url, Str $hyperlink, Str %stash);
|
||||
|
||||
$base-url = $meta-refresh
|
||||
?? $url-scheme ~ '://' ~ $url-host ~ '/--meta-refresh/'
|
||||
!! $url-scheme ~ '://' ~ $url-host ~ '/';
|
||||
|
||||
$hyperlink = $base-url ~ encode-base64(gzip($return-url), :str);
|
||||
|
||||
%stash =
|
||||
title => 'New hyperlink created',
|
||||
hyperlink => $hyperlink;
|
||||
|
||||
$response.html($template.render: 'index', %stash);
|
||||
});
|
||||
|
||||
# Try a wildcard to catch 'all' path
|
||||
|
||||
# Process the hyperlink
|
||||
$router.get('/--meta-refresh/**', -> $request, $response {
|
||||
my Str $return-url = $request.path.subst: /^ '/--meta-refresh/'/, Empty;
|
||||
my Str $redirect-url = gunzip(decode-base64($return-url, :bin));
|
||||
my Str %stash =
|
||||
title => 'Hyperlinking...',
|
||||
redirect-url => $redirect-url;
|
||||
|
||||
$response.html($template.render: 'index', %stash);
|
||||
});
|
||||
|
||||
$router.get('/**', -> $request, $response {
|
||||
my Str $return-url = $request.path.substr(1); # Omits the leading slash
|
||||
my Str $redirect-url = gunzip(decode-base64($return-url, :bin));
|
||||
|
|
|
@ -2,6 +2,9 @@
|
|||
<html lang="en">
|
||||
<head>
|
||||
<title>{{title}}</title>
|
||||
{{#meta-refresh}}
|
||||
<meta http-equiv="Refresh" content="0; url='{{redirect-url}}'">
|
||||
{{/meta-refresh}}
|
||||
</head>
|
||||
<body>
|
||||
<h1>{{title}}</h1>
|
||||
|
|
|
@ -1,11 +1,17 @@
|
|||
{{> header}}
|
||||
{{^meta-refresh}}
|
||||
{{#hyperlink}}
|
||||
<p>Your hyperlink is: <a href="{{hyperlink}}">{{hyperlink}}</a></p>
|
||||
{{/hyperlink}}
|
||||
<form method="post">
|
||||
<label for="hyperlink">Hyperlink</label>
|
||||
<input id="hyperlink" name="hyperlink" type="text" minlength="4"
|
||||
maxlength="2097152" required>
|
||||
maxlength="2083" required>
|
||||
<label for="meta-refresh">
|
||||
<a href="https://en.wikipedia.org/wiki/Meta_refresh">Meta refresh?</a>
|
||||
</label>
|
||||
<input id="meta-refresh" name="meta-refresh" type="checkbox">
|
||||
<button type="submit">Process</button>
|
||||
</form>
|
||||
{{/meta-refresh}}
|
||||
{{> footer}}
|
||||
|
|
Loading…
Reference in a new issue