/
mojolicious.pl
executable file
·55 lines (40 loc) · 1.9 KB
/
mojolicious.pl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
#!/usr/bin/env perl
use Mojolicious::Lite -signatures;
use FindBin;
BEGIN { unshift @INC, "$FindBin::Bin/lib" }
plugin Fortune => {path => app->home->child('fortune.txt')};
plugin Mount => {'docs.mojolicious.org' => app->home->child('mojodocs.pl')};
# Redirect "mojolicio.us" to "mojolicious.org"
hook before_dispatch => sub ($c) {
return unless ($c->req->url->base->host // '') =~ /^(.*)mojolicio.us$/;
$c->res->code(301);
$c->redirect_to($c->req->url->to_abs->host("$1mojolicious.org"));
};
# Redirect old documentation links to "docs.mojolicious.org"
any '/perldoc/:module' => {module => 'Mojolicious/Guides'} => [module => qr/[^.]+/] => sub ($c) {
my $module = $c->param('module');
$c->redirect_to("https://docs.mojolicious.org/$module");
};
# Welcome to Mojolicious
get '/' => sub ($c) {
if ((my $host = $c->req->url->base->host // '') ne 'mojolicious.org') {
# Shortcut for "book.mojolicious.org"
return $c->redirect_to('https://leanpub.com/mojo_web_clients/') if $host =~ /^book\./;
# Shortcut for "blogs.mojolicious.org"
return $c->redirect_to('https://dev.to/t/mojolicious/latest') if $host =~ /^blogs?\./;
# Shortcut for "forum.mojolicious.org"
return $c->redirect_to('https://github.com/mojolicious/mojo/discussions') if $host =~ /^forum\./;
# Shortcut for "conduct.mojolicious.org"
return $c->redirect_to('https://mojolicious.org/perldoc/Mojolicious/Guides/Contributing#CODE-OF-CONDUCT')
if $host =~ /^conduct\./;
# Shortcut for "mojojs.org"
return $c->redirect_to('https://github.com/mojolicious/mojo.js') if $host =~ /mojojs.org$/;
# Shortcut for "kraih.com"
return $c->redirect_to('https://github.com/kraih') if $host =~ /kraih.com$/;
# Shortcut for "minion.pm"
return $c->redirect_to('https://github.com/mojolicious/minion') if $host =~ /minion.pm$/;
}
# Frontpage
$c->render('mojolicious/index');
};
app->start;