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