Implement meta refresh
This commit is contained in:
parent
92bf9c75ed
commit
190a148b9c
|
@ -25,10 +25,10 @@ $router.get(-> $request, $response {
|
||||||
});
|
});
|
||||||
|
|
||||||
$router.post(-> $request, $response {
|
$router.post(-> $request, $response {
|
||||||
my Str $return-url = $request.content.{'hyperlink'};
|
my Str $return-url = $request.content.<hyperlink>;
|
||||||
my Bool $meta-refresh = $request.content.<meta-refresh> ?? True !! False;
|
my Bool $meta-refresh = $request.content.<meta-refresh>.defined;
|
||||||
my Str $url-scheme = $request.headers.{'X-Forwarded-Proto'} || 'http';
|
my Str $url-scheme = $request.headers.<X-Forwarded-Proto> || 'http';
|
||||||
my Str $url-host = $request.headers.{'Host'};
|
my Str $url-host = $request.headers.<Host>;
|
||||||
my (Str $base-url, Str $hyperlink, Str %stash);
|
my (Str $base-url, Str $hyperlink, Str %stash);
|
||||||
|
|
||||||
$base-url = $meta-refresh
|
$base-url = $meta-refresh
|
||||||
|
@ -37,21 +37,16 @@ $router.post(-> $request, $response {
|
||||||
|
|
||||||
$hyperlink = $base-url ~ encode-base64(gzip($return-url), :str);
|
$hyperlink = $base-url ~ encode-base64(gzip($return-url), :str);
|
||||||
|
|
||||||
%stash =
|
%stash = title => 'New hyperlink created', :$hyperlink;
|
||||||
title => 'New hyperlink created',
|
|
||||||
hyperlink => $hyperlink;
|
|
||||||
|
|
||||||
$response.html($template.render: 'index', %stash);
|
$response.html($template.render: 'index', %stash);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
# Process the hyperlink
|
# Process the hyperlink
|
||||||
$router.get('/--meta-refresh/**', -> $request, $response {
|
$router.get('/--meta-refresh/**', -> $request, $response {
|
||||||
my Str $return-url = $request.path.subst: /^ '/--meta-refresh/'/, Empty;
|
my Str $return-url = $request.path.subst: /^ '/--meta-refresh/'/, Empty;
|
||||||
my Str $redirect-url = gunzip(decode-base64($return-url, :bin));
|
my Str $redirect-url = gunzip(decode-base64($return-url, :bin));
|
||||||
my Str %stash =
|
my Str %stash = title => 'Hyperlinking...', :$redirect-url;
|
||||||
title => 'Hyperlinking...',
|
|
||||||
redirect-url => $redirect-url;
|
|
||||||
|
|
||||||
$response.html($template.render: 'index', %stash);
|
$response.html($template.render: 'index', %stash);
|
||||||
});
|
});
|
||||||
|
|
|
@ -2,9 +2,9 @@
|
||||||
<html lang="en">
|
<html lang="en">
|
||||||
<head>
|
<head>
|
||||||
<title>{{title}}</title>
|
<title>{{title}}</title>
|
||||||
{{#meta-refresh}}
|
{{#redirect-url}}
|
||||||
<meta http-equiv="Refresh" content="0; url='{{redirect-url}}'">
|
<meta http-equiv="Refresh" content="0; url='{{redirect-url}}'">
|
||||||
{{/meta-refresh}}
|
{{/redirect-url}}
|
||||||
</head>
|
</head>
|
||||||
<body>
|
<body>
|
||||||
<h1>{{title}}</h1>
|
<h1>{{title}}</h1>
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
{{> header}}
|
{{> header}}
|
||||||
{{^meta-refresh}}
|
{{^redirect-url}}
|
||||||
{{#hyperlink}}
|
{{#hyperlink}}
|
||||||
<p>Your hyperlink is: <a href="{{hyperlink}}">{{hyperlink}}</a></p>
|
<p>Your hyperlink is: <a href="{{hyperlink}}">{{hyperlink}}</a></p>
|
||||||
{{/hyperlink}}
|
{{/hyperlink}}
|
||||||
|
@ -13,5 +13,5 @@
|
||||||
<input id="meta-refresh" name="meta-refresh" type="checkbox">
|
<input id="meta-refresh" name="meta-refresh" type="checkbox">
|
||||||
<button type="submit">Process</button>
|
<button type="submit">Process</button>
|
||||||
</form>
|
</form>
|
||||||
{{/meta-refresh}}
|
{{/redirect-url}}
|
||||||
{{> footer}}
|
{{> footer}}
|
||||||
|
|
Loading…
Reference in a new issue