mojo_factoid_viewer/lib/MyApp.pm

52 lines
1.3 KiB
Perl

package MyApp;
use Mojo::Base 'Mojolicious', -signatures;
use MyApp::Model::FactoidDB;
use MyApp::Memcache;
use URI::Encode;
has 'factdb';
has 'mcache';
my $my_encode = sub ($part) {
return URI::Encode::uri_encode($part, {encode_reserved => 1});
};
# This method will run once at server start
sub startup ($self) {
# Load configuration from config file
my $config = $self->plugin('NotYAMLConfig');
$self->plugin(xslate_renderer => {
template_options => { syntax => 'TTerse',
function => {
uenc => $my_encode,
},
# header => ["common/includes.html.tx"],
# footer => ["common/page_footer.html.tx"],
}
});
my $dsn = $config->{dsn};
my $factdb = MyApp::Model::FactoidDB->new(dsn => $dsn);
$self->factdb($factdb);
my $mserver = $config->{memcache_server};
my $mcache = MyApp::Memcache->new(server => $mserver);
$self->mcache($mcache);
# Configure the application
$self->secrets($config->{secrets});
# Router
my $r = $self->routes;
# Normal route to controller
$r->get('/')->to('factoids#welcome');
$r->get('/*server/*names/list')->to('factoids#display');
$r->get('/*server/*names/search')->to('factoids#search');
$r->get('/*server/*names/revisions')->to('factoids#revisions');
$r->get('/*server/*names/autocomplete')->to('factoids#autocomplete');
}
1;