Last active
January 9, 2017 05:04
-
-
Save mche/a5670e5fd5b932409d184ea718a1581b to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
use Mojolicious::Lite; | |
=pod | |
Usage: | |
perl script/redirect.pl daemon --listen http://*:80 | |
Or uncomment listen option below and | |
perl script/redirect.pl daemon | |
=cut | |
my $conf = { | |
listen => 'http://*:80', | |
scheme => 'https', | |
#~ port => '443', !!! https scheme not need | |
host => 'mydomain.com', | |
code=> '301',# Moved code status | |
server => 'Redirector 0.01', | |
mode => 'production', | |
}; | |
push @ARGV, '--listen', $conf->{listen} | |
if $conf->{listen}; | |
hook before_dispatch => sub { | |
my $c = shift; | |
my $url = $c->req->url->to_abs; | |
$url->can($_) && $url->$_($conf->{$_}) | |
for keys %$conf; | |
#~ warn $url->to_string if $url->userinfo; | |
$c->tx->res->headers->server($conf->{server}); | |
$c->res->code($conf->{code}); | |
$c->redirect_to($url); | |
}; | |
app->mode($conf->{mode})->start; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment