-
Notifications
You must be signed in to change notification settings - Fork 0
/
pot_web.pl
executable file
·75 lines (64 loc) · 1.65 KB
/
pot_web.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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
#!/usr/bin/env perl
use Mojolicious::Lite;
use Mojo::Redis2;
use Mojo::ACME
# Documentation browser under "/perldoc"
plugin 'PODRenderer';
plugin 'proxy';
plugin 'ACME';
my $redis = Mojo::Redis2->new;
my $ipfshash = "QmYEzhKy1ZB3dcZtyKrUnqJyp7ZnQQK8EkofUa8Whu2RdM";
app->config(hypnotoad => {listen => ['http://*:9080'], pid_file => '/home/node/run/pot_web.pid'});
get '/' => sub {
my $c = shift;
my $host = $c->req->url->to_abs->host;
my $file = $c->req->url->to_abs;
my $id;
if ($redis->exists('url_'.$host)) {
$id = $redis->get('url_'.$host);
if ($file !~ m/\.html$/) {
$file = "index.html";
}
} else {
$id = $ipfshash;
$file = "index.html";
}
my $base = "http://127.0.0.1:8080/ipfs/$id/$file";
$c->proxy_to($base);
};
get '/public/*file' => sub {
my $c = shift;
my $host = $c->req->url->to_abs->host;
my $file = $c->param('file');
my $id;
if ($redis->exists('url_'.$host)) {
$id = $redis->get('url_'.$host)
} else {
$id = $ipfshash;
}
$file = "public/$file";
my $base = "http://127.0.0.1:8080/ipfs/$id/$file";
$c->proxy_to($base);
};
get '/ipfs/:id/*file' => sub {
my $c = shift;
my $url = $c->req->url->to_string;
my $id = $c->param('id');
my $file = $c->param('file');
my $base = "http://127.0.0.1:8080/ipfs/$id/$file";
$c->proxy_to($base);
};
app->start;
__DATA__
@@ index.html.ep
% layout 'default';
% title 'Welcome';
<h1>Welcome to the Mojolicious real-time web framework!</h1>
To learn more, you can browse through the documentation
<%= link_to 'here' => '/perldoc' %>.
@@ layouts/default.html.ep
<!DOCTYPE html>
<html>
<head><title><%= title %></title></head>
<body><%= content %></body>
</html>