2021-12-04 00:11:37 -05:00
|
|
|
#!/usr/bin/env perl
|
|
|
|
|
|
|
|
# Dec 2021
|
|
|
|
# Daniel Bowling <swaggboi@slackware.uk>
|
|
|
|
|
|
|
|
use Mojolicious::Lite -signatures;
|
2021-12-04 18:34:35 -05:00
|
|
|
use Mojo::Pg;
|
2021-12-04 02:26:25 -05:00
|
|
|
use lib 'lib';
|
|
|
|
use GuestbookNg::Model::Test;
|
|
|
|
|
2021-12-04 18:34:35 -05:00
|
|
|
# Plugins
|
|
|
|
plugin 'Config';
|
|
|
|
|
|
|
|
# Helpers
|
|
|
|
helper pg => sub {
|
|
|
|
state $pg = Mojo::Pg->new(
|
2021-12-04 18:50:19 -05:00
|
|
|
'postgres://' .
|
2021-12-04 18:34:35 -05:00
|
|
|
app->config->{'pg_user'} .
|
2021-12-04 18:50:19 -05:00
|
|
|
':' .
|
2021-12-04 18:34:35 -05:00
|
|
|
app->config->{'pg_pw'} .
|
2021-12-04 22:33:53 -05:00
|
|
|
'@' .
|
|
|
|
app->config->{'pg_host'} .
|
|
|
|
'/' .
|
2021-12-04 18:34:35 -05:00
|
|
|
app->config->{'pg_db'}
|
|
|
|
);
|
|
|
|
};
|
|
|
|
|
|
|
|
helper test => sub {
|
|
|
|
state $test = GuestbookNg::Model::Test->new(pg => shift->pg)
|
|
|
|
};
|
|
|
|
|
2021-12-04 23:06:05 -05:00
|
|
|
helper message => sub {
|
|
|
|
state $test = GuestbookNg::Model::Message->new(pg => shift->pg)
|
|
|
|
};
|
|
|
|
|
2021-12-04 18:34:35 -05:00
|
|
|
# Routes
|
|
|
|
under sub ($c) {
|
2021-12-04 23:06:05 -05:00
|
|
|
$c->pg->migrations->from_dir('migrations')->migrate(1);
|
2021-12-04 18:34:35 -05:00
|
|
|
};
|
2021-12-04 00:11:37 -05:00
|
|
|
|
|
|
|
get '/' => sub ($c) {
|
2021-12-04 02:26:25 -05:00
|
|
|
$c->render()
|
|
|
|
} => 'index';
|
|
|
|
|
|
|
|
any '/test' => sub ($c) {
|
2021-12-04 13:28:07 -05:00
|
|
|
my $method = $c->req->method();
|
2021-12-04 18:34:35 -05:00
|
|
|
my $time = $c->test->now();
|
|
|
|
my $string =
|
|
|
|
$method eq 'POST' ? $c->test->test_model($c->param('string')) : undef;
|
2021-12-04 02:26:25 -05:00
|
|
|
|
2021-12-04 18:34:35 -05:00
|
|
|
$c->render(
|
|
|
|
method => $method,
|
|
|
|
string => $string,
|
|
|
|
time => $time
|
|
|
|
);
|
2021-12-04 00:11:37 -05:00
|
|
|
};
|
|
|
|
|
2021-12-04 18:34:35 -05:00
|
|
|
# Send it
|
2021-12-04 00:11:37 -05:00
|
|
|
app->start();
|