blob: 13a44d148b474963ddb499f22926fe0626aed15d [file] [log] [blame]
Nils Diewald5d1ffb42014-05-21 17:45:34 +00001package Korap;
2use Mojo::Base 'Mojolicious';
3
Nils Diewald64bab252014-05-22 11:04:04 +00004our $VERSION = '0.01';
5
Nils Diewald5d1ffb42014-05-21 17:45:34 +00006# This method will run once at server start
7sub startup {
8 my $self = shift;
9
10 $self->plugin('Config');
11 $self->plugin('TagHelpers::Pagination');
Nils Diewalddd2d4e82014-05-31 17:08:33 +000012 $self->plugin('Notifications');
13 $self->plugin('Number::Commify');
Nils Diewald5d1ffb42014-05-21 17:45:34 +000014
15 push(@{$self->plugins->namespaces}, __PACKAGE__ . '::Plugin');
16 $self->plugin('KorapSearch');
Nils Diewald5d1ffb42014-05-21 17:45:34 +000017
Nils Diewald64bab252014-05-22 11:04:04 +000018 # Routes
Nils Diewald5d1ffb42014-05-21 17:45:34 +000019 my $r = $self->routes;
20
Nils Diewalddd2d4e82014-05-31 17:08:33 +000021 # Create search endpoint
Nils Diewald5d1ffb42014-05-21 17:45:34 +000022 $r->add_shortcut(
23 search => sub {
24 shift->get('/search')->to('search#remote')
25 }
26 );
27
Nils Diewald64bab252014-05-22 11:04:04 +000028 $r->get('/')->to(
29 cb => sub {
30 my $c = shift;
Nils Diewalddd2d4e82014-05-31 17:08:33 +000031 $c->render(
32 text =>
33 'Go to '.
34 $c->link_to('search', '/collection/search'));
Nils Diewald64bab252014-05-22 11:04:04 +000035 }
36 );
37
38 # resource => [qw/collection corpus/]
Nils Diewald5d1ffb42014-05-21 17:45:34 +000039 $r->get('/:resource')->search;
40 $r->get('/:resource/:cid', resource => [qw/collection corpus/])->search;
41 $r->get('/:resource/')->search;
Nils Diewald5d1ffb42014-05-21 17:45:34 +000042 # /matchInfo?id=...&f=&l=&spans
Nils Diewald64bab252014-05-22 11:04:04 +000043};
44
Nils Diewald5d1ffb42014-05-21 17:45:34 +000045
461;