#!/usr/bin/env perl
use Mojolicious::Lite;
get '/' => sub {
my ($c) = @_;
my $hostHeader = $c->req->headers->host();
if ($hostHeader =~ /www.wethepeople.win(|:[0-9]{1,5})/) {
$c->render()
}
else {
$c->redirect_to('http://www.wethepeople.win')
}
} => 'index';
app->start();
# Testing with curl:
# daniel@graymember:~/misc/mojo$ curl -I http://localhost:3000 -H 'Host: www.wethepeople.win'
# HTTP/1.1 200 OK
# Content-Length: 2709
# Date: Sat, 23 Jan 2021 00:47:54 GMT
# Server: Mojolicious (Perl)
# Content-Type: text/html;charset=UTF-8
#
# daniel@graymember:~/misc/mojo$ curl -I http://localhost:3000 -H 'Host: www.wethepeople.win:3000'
# HTTP/1.1 200 OK
# Date: Sat, 23 Jan 2021 00:47:58 GMT
# Content-Length: 2709
# Content-Type: text/html;charset=UTF-8
# Server: Mojolicious (Perl)
#
# daniel@graymember:~/misc/mojo$ curl -I http://localhost:3000
# HTTP/1.1 302 Found
# Content-Length: 0
# Date: Sat, 23 Jan 2021 00:48:05 GMT
# Location: http://www.wethepeople.win
# Server: Mojolicious (Perl)