blob: 0914943be79651404ad69629df9158470b4daa67 [file] [log] [blame]
Nils Diewald2fe12e12015-03-06 16:47:06 +00001package Kalamar;
Nils Diewald5d1ffb42014-05-21 17:45:34 +00002use Mojo::Base 'Mojolicious';
Nils Diewalde2c83812014-11-11 21:13:18 +00003use Mojo::ByteStream 'b';
Akronc7656e92018-08-30 13:33:25 +02004use Mojo::URL;
Akronf65ad6c2017-02-01 14:36:38 +01005use Mojo::File;
Akron2c2ddbd2021-03-05 12:10:27 +01006use Mojo::JSON qw/decode_json encode_json/;
Akron0c4cd222019-07-19 16:33:34 +02007use Mojo::Util qw/url_escape deprecated slugify/;
Akrond8db6722022-12-06 10:05:24 +01008use List::Util qw!none uniq!;
Nils Diewald5d1ffb42014-05-21 17:45:34 +00009
Nils Diewald709f52f2015-05-21 18:32:58 +000010# Minor version - may be patched from package.json
Akronb9070eb2025-12-16 12:17:59 +010011our $VERSION = '0.64';
Akronc7656e92018-08-30 13:33:25 +020012
13# Supported version of Backend API
14our $API_VERSION = '1.0';
Akronb9070eb2025-12-16 12:17:59 +010015our $API_VERSION_SUPPORTED = ['1.0','1.1'];
Nils Diewald7cad8402014-07-08 17:06:56 +000016
Nils Diewald7148c6f2015-05-04 15:07:53 +000017# TODO: The FAQ-Page has a contact form for new questions
Nils Diewald709f52f2015-05-21 18:32:58 +000018# TODO: Embed query serialization
19# TODO: Embed collection statistics
20# TODO: Implement tab opener for matches and the tutorial
Nils Diewald709f52f2015-05-21 18:32:58 +000021# TODO: Implement a "projects" system
Nils Diewald7148c6f2015-05-04 15:07:53 +000022
Nils Diewald002e8fb2014-06-22 14:27:01 +000023# Start the application and register all routes and plugins
Nils Diewald5d1ffb42014-05-21 17:45:34 +000024sub startup {
25 my $self = shift;
26
Nils Diewalda944fab2015-04-08 21:02:04 +000027 # Set version based on package file
Nils Diewald709f52f2015-05-21 18:32:58 +000028 # This may introduce a SemVer patch number
Akronf65ad6c2017-02-01 14:36:38 +010029 my $pkg_path = $self->home->child('package.json');
Akrone40933b2022-12-21 09:56:55 +010030 if ($ENV{KALAMAR_VERSION}) {
31 $Kalamar::VERSION = $ENV{KALAMAR_VERSION};
32 }
33 elsif (-e $pkg_path->to_abs) {
Akronf65ad6c2017-02-01 14:36:38 +010034 my $pkg = $pkg_path->slurp;
35 $Kalamar::VERSION = decode_json($pkg)->{version};
36 };
Nils Diewalda944fab2015-04-08 21:02:04 +000037
Akron656c5d92015-11-13 21:17:03 +010038 # Lift maximum template cache
39 $self->renderer->cache->max_keys(200);
40
Nils Diewaldab4d3ca2015-04-17 01:48:43 +000041 # Add additional plugin path
42 push(@{$self->plugins->namespaces}, __PACKAGE__ . '::Plugin');
43
Akron3340ae72022-11-22 12:20:13 +010044 # Add additional commands
45 push(@{$self->commands->namespaces}, __PACKAGE__ . '::Command');
46
Nils Diewaldfccfbcb2015-04-29 20:48:19 +000047 # Set secrets for signed cookies
Akron2c2ddbd2021-03-05 12:10:27 +010048 my $secret_file = $self->home->rel_file('kalamar.secret.json');
49
50 # Support old secrets file
51 # This is deprecated 2021-03-05
52 if (-e (my $old_secret = $self->home->child('kalamar.secret'))) {
Nils Diewalda79b2682015-05-18 18:34:06 +000053
54 # Load file and split lines for multiple secrets
Akron2c2ddbd2021-03-05 12:10:27 +010055 my $secrets = [b($old_secret->slurp)->split("\n")];
Akron3d68ac32022-01-04 14:40:30 +010056
Akron2c2ddbd2021-03-05 12:10:27 +010057 $self->secrets($secrets);
58
Akron3d68ac32022-01-04 14:40:30 +010059 for (@$secrets) {
60 if (length($secrets) > 22) {
61 $self->log->warn(
62 'Unable to automatically switch to Autosecrets, as secret is too long (> 22 chars)'
63 );
64 goto CONF;
65 };
66 }
67
Akron2c2ddbd2021-03-05 12:10:27 +010068 eval {
Akron889bc202024-03-15 17:16:55 +010069 $secret_file->spew(encode_json(@$secrets));
Akron2c2ddbd2021-03-05 12:10:27 +010070 $secret_file->chmod(0600);
71 if (-w $secret_file) {
72 $self->log->warn(
73 "Please delete $old_secret file " .
74 "- $secret_file was created instead"
75 );
76 }
77 };
78 if ($@) {
79 $self->log->error("Please make $secret_file accessible");
80 };
Nils Diewald4347ee92015-05-04 20:32:48 +000081 }
Nils Diewald709f52f2015-05-21 18:32:58 +000082
83 # File not found ...
84 # Kalamar needs secrets in a file to be easily deployable
85 # and publishable at the same time.
Nils Diewald4347ee92015-05-04 20:32:48 +000086 else {
Akron2c2ddbd2021-03-05 12:10:27 +010087 $self->plugin(AutoSecrets => {
88 path => $secret_file
89 });
Nils Diewald19402142015-04-30 15:44:52 +000090 };
Nils Diewaldfccfbcb2015-04-29 20:48:19 +000091
Akron3d68ac32022-01-04 14:40:30 +010092 CONF:
Akron2c2ddbd2021-03-05 12:10:27 +010093
Akroncba9f322016-02-29 23:12:45 +010094 # Configuration framework
Akron09a567c2016-04-11 22:49:20 +030095 $self->plugin('Config');
Nils Diewald709f52f2015-05-21 18:32:58 +000096
Akron741b2b12017-04-13 22:15:59 +020097 $self->log->info('Mode is ' . $self->mode);
98
Akron63d963b2019-07-05 15:35:51 +020099 # Get configuration
Akron47787ca2017-05-17 16:00:10 +0200100 my $conf = $self->config('Kalamar');
Akron63d963b2019-07-05 15:35:51 +0200101 unless ($conf) {
102 $self->config(Kalamar => {});
103 $conf = $self->config('Kalamar');
104 };
105
Akronf260e6e2023-05-16 16:36:10 +0200106 # Set log file. All precedng logs where send to stderr
107 if ($conf->{log_file}) {
108 Mojo::File->new(Mojo::File->new($conf->{log_file})->dirname)->make_path;
109 $self->log(Mojo::Log->new(
110 path => $conf->{log_file},
111 ));
112 };
113
114
Akron63d963b2019-07-05 15:35:51 +0200115 # Check for API endpoint and set the endpoint accordingly
116 if ($conf->{api}) {
117
118 # The api endpoint should be defined as a separated path
119 # and version string
120 $self->log->warn(
121 'Kalamar.api is no longer supported in configurations '.
122 'in favor of Kalamar.api_path'
123 );
124 };
125
Akron0c4cd222019-07-19 16:33:34 +0200126 $self->sessions->cookie_name('kalamar');
127
128 # Require HTTPS
129 if ($conf->{https_only}) {
130
131 # ... for cookie transport
132 $self->sessions->secure(1);
Akron1bee5a42021-01-13 17:44:18 +0100133
Akron26244a72021-04-28 00:17:56 +0200134 # Temporary for session riding
135 $self->sessions->samesite('None');
136
Akron1bee5a42021-01-13 17:44:18 +0100137 # For all pages
138 $self->hook(
139 before_dispatch => sub {
140 shift->res->headers->header('Strict-Transport-Security' => 'max-age=3600; includeSubDomains');
141 }
142 );
Akron0c4cd222019-07-19 16:33:34 +0200143 };
144
145 # Run the app from a subdirectory
Akron63d963b2019-07-05 15:35:51 +0200146 if ($conf->{proxy_prefix}) {
Akron47787ca2017-05-17 16:00:10 +0200147
Akronf3d856c2017-06-21 17:07:40 +0200148 for ($self->sessions) {
Akron1a394722017-06-21 16:25:30 +0200149 $_->cookie_path($conf->{proxy_prefix});
Akron0c4cd222019-07-19 16:33:34 +0200150 $_->cookie_name('kalamar-' . slugify($conf->{proxy_prefix}));
Akron1a394722017-06-21 16:25:30 +0200151 };
152
Akron47787ca2017-05-17 16:00:10 +0200153 # Set prefix in stash
154 $self->defaults(prefix => $conf->{proxy_prefix});
155
156 # Create base path
157 $self->hook(
158 before_dispatch => sub {
159 shift->req->url->base->path($conf->{proxy_prefix} . '/');
160 });
161 };
162
Akron807225b2021-01-13 18:00:13 +0100163 $self->hook(
164 before_dispatch => sub {
Akron5b6d7272021-01-21 11:26:02 +0100165 my $h = shift->res->headers;
166 $h->header('X-Content-Type-Options' => 'nosniff');
Akron52b32d02021-01-21 17:37:19 +0100167 $h->header('X-XSS-Protection' => '1; mode=block');
Akron5b6d7272021-01-21 11:26:02 +0100168 $h->header(
169 'Access-Control-Allow-Methods' =>
170 $h->header('Access-Control-Allow-Methods') // 'GET, POST, OPTIONS'
171 );
Akron807225b2021-01-13 18:00:13 +0100172 }
173 );
174
Akron90be03b2020-02-03 16:13:37 +0100175 $conf->{proxy_host} //= 1;
176
177 # Take proxy host
178 if ($conf->{proxy_host}) {
179 $self->hook(
180 before_dispatch => sub {
181 my $c = shift;
Akron409f6b82023-05-08 10:42:36 +0200182 my $h = $c->req->headers;
183 if (my $host = $h->header('X-Forwarded-Host')) {
184
185 my $proto = $h->header('X-Forwarded-Proto') // ($conf->{https_only} ? 'https' : undef);
186
Akron90be03b2020-02-03 16:13:37 +0100187 foreach ($c->req->url->base) {
188 $_->host($host);
Akron409f6b82023-05-08 10:42:36 +0200189 $_->scheme($proto);
Akron90be03b2020-02-03 16:13:37 +0100190 $_->port(undef);
191 };
192 };
193 }
194 );
195 };
196
Akron8f8deda2021-01-15 12:55:06 +0100197 # API is not yet set - define the default Kustvakt api endpoint
198 $conf->{api_path} //= $ENV{KALAMAR_API} || 'https://korap.ids-mannheim.de/api/';
Akron63d963b2019-07-05 15:35:51 +0200199 $conf->{api_version} //= $API_VERSION;
Akronc7656e92018-08-30 13:33:25 +0200200
Akron4036d542018-02-12 13:17:09 +0100201 # Add development path
Akron0e1ed242018-10-11 13:22:00 +0200202 if ($self->mode eq 'development') {
Akron4036d542018-02-12 13:17:09 +0100203 push @{$self->static->paths}, 'dev';
Akronbe9d5b32017-04-05 20:48:24 +0200204 };
205
Akron23ab0472019-12-17 16:55:55 +0100206 # Set proxy timeouts
207 if ($conf->{proxy_inactivity_timeout}) {
208 $self->ua->inactivity_timeout($conf->{proxy_inactivity_timeout});
209 };
210 if ($conf->{proxy_connect_timeout}) {
211 $self->ua->connect_timeout($conf->{proxy_connect_timeout});
212 };
213
Akron09a567c2016-04-11 22:49:20 +0300214 # Client notifications
Akron0504a182016-04-10 21:13:42 +0200215 $self->plugin(Notifications => {
216 'Kalamar::Plugin::Notifications' => 1,
Akron8ea84292018-10-24 13:41:52 +0200217 JSON => 1,
Akron3c390c42020-03-30 09:06:21 +0200218 HTML => 1
Akron0504a182016-04-10 21:13:42 +0200219 });
220
Akronc4ea2e52021-01-27 18:34:05 +0100221 # Establish content security policy
Akron0a4d36e2021-01-18 17:50:48 +0100222 # This needs to be defined prior to Kalamar::Plugin::Piwik!
Akronc4ea2e52021-01-27 18:34:05 +0100223 $self->plugin(CSP => {
224 'default-src' => 'self',
Akron0a4d36e2021-01-18 17:50:48 +0100225 'style-src' => ['self','unsafe-inline'],
Akron1871f032021-01-29 10:35:53 +0100226 # Hash for korap-overview.svg script
227 'script-src' => ['self','sha256-VGXK99kFz+zmAQ0kxgleFrBWZgybFAPOl3GQtS7FQkI='],
Akron5b6d7272021-01-21 11:26:02 +0100228 'connect-src' => 'self',
Akron0a4d36e2021-01-18 17:50:48 +0100229 'frame-src' => '*',
Akronaef5cf22021-06-21 11:45:54 +0200230 'frame-ancestors' => 'self',
Akron0a4d36e2021-01-18 17:50:48 +0100231 'media-src' => 'none',
232 'object-src' => 'self',
233 'font-src' => 'self',
234 'img-src' => ['self', 'data:'],
Akronb7b91c52021-01-27 17:46:52 +0100235 -with_nonce => 1
Akronc4ea2e52021-01-27 18:34:05 +0100236 });
237
Akron09a567c2016-04-11 22:49:20 +0300238 # Localization framework
239 $self->plugin(Localize => {
Akrondbb448c2018-02-14 17:02:36 +0100240 dict => {
241 Q => {
242 _ => sub { shift->config('Kalamar')->{'examplecorpus'} },
243 }
244 },
Akrona65bd5d2024-10-24 13:28:11 +0200245 resources => [
246 'kalamar.dict',
247 'kalamar.queries.dict',
248 'loc/kalamar.ro.dict',
249 'loc/kalamar.hu.dict'
250 ]
Akron09a567c2016-04-11 22:49:20 +0300251 });
252
253 # Pagination widget
254 $self->plugin('TagHelpers::Pagination' => {
255 prev => '<span><span>&lt;</span></span>',
Akron86e63a92019-02-27 17:35:04 +0100256 next => '<span><span>&gt;</span></span>',
Akrona4b17f72021-11-04 15:37:02 +0100257 ellipsis => '<a class="ellipsis inactive"><span><span>...</span></span></a>',
Akron09a567c2016-04-11 22:49:20 +0300258 separator => '',
259 current => '<span>{current}</span>',
260 page => '<span>{page}</span>'
261 });
262
Akron1011daf2021-03-01 12:34:58 +0100263 # Obfuscate email addresses
264 $self->plugin('TagHelpers::MailToChiffre' => {
265 method_name => 'PArok',
266 pattern_rotate => 673,
267 no_inline => 1
268 });
269
Nils Diewaldab4d3ca2015-04-17 01:48:43 +0000270 # Load plugins
Nils Diewaldfccfbcb2015-04-29 20:48:19 +0000271 foreach (
Akrone8235be2016-06-27 11:02:18 +0200272 'KalamarHelpers', # Specific Helpers for Kalamar
Akronb7b91c52021-01-27 17:46:52 +0100273 'KalamarPages', # Page Helpers for Kalamar
Akron7093b812018-10-19 17:28:21 +0200274 'KalamarErrors', # Specific Errors for Kalamar
275 'KalamarUser', # Specific Helpers for Kalamar Users
Akron429aeda2018-03-19 16:02:29 +0100276 'ClientIP', # Get client IP from X-Forwarded-For
Akron51757cb2018-05-16 13:10:08 +0200277 'ClosedRedirect', # Redirect with OpenRedirect protection
Akronafeca252018-05-23 15:54:28 +0200278 'TagHelpers::ContentBlock', # Flexible content blocks
Nils Diewaldfccfbcb2015-04-29 20:48:19 +0000279 ) {
Nils Diewaldab4d3ca2015-04-17 01:48:43 +0000280 $self->plugin($_);
281 };
282
Akron751e9e42019-03-13 09:54:55 +0100283 my $serializer = 'JSON';
284
285 if (my $chi = $self->config('CHI')) {
286 if ($chi->{default}) {
287 $chi->{default}->{serializer} = $serializer;
288 };
289 if ($chi->{user}) {
290 $chi->{user}->{serializer} = $serializer;
291 };
292 };
293
Akron05c6dd62018-10-11 17:05:06 +0200294 # Global caching mechanism
295 $self->plugin('CHI' => {
296 default => {
297 driver => 'Memory',
Akron751e9e42019-03-13 09:54:55 +0100298 global => 1,
299 serializer => $serializer
Akron05c6dd62018-10-11 17:05:06 +0200300 },
301 user => {
302 driver => 'Memory',
Akron751e9e42019-03-13 09:54:55 +0100303 global => 1,
304 serializer => $serializer
Akron05c6dd62018-10-11 17:05:06 +0200305 }
306 });
Nils Diewald709f52f2015-05-21 18:32:58 +0000307
Nils Diewaldfccfbcb2015-04-29 20:48:19 +0000308 # Configure mail exception
Akron40cc1d82017-05-10 17:58:16 +0200309 if ($self->config('MailException')) {
310 $self->plugin('MailException' => $self->config('MailException'));
311 };
Nils Diewald709f52f2015-05-21 18:32:58 +0000312
Akrond8db6722022-12-06 10:05:24 +0100313 # Load plugins defined in environment variables
314 if ($ENV{'KALAMAR_PLUGINS'}) {
315 $conf->{'plugins'} //= [];
316 push @{$conf->{'plugins'}}, split(/\s*,\s*/, $ENV{'KALAMAR_PLUGINS'} // '');
317 };
318
Akroncdfd9d52019-07-23 11:35:00 +0200319 # Load further plugins,
320 # that can override core functions,
321 # therefore order may be of importance
Akron4c33c622018-11-12 13:43:27 +0100322 if (exists $conf->{'plugins'}) {
Akrond8db6722022-12-06 10:05:24 +0100323 foreach (uniq @{$conf->{'plugins'}}) {
Akron4c33c622018-11-12 13:43:27 +0100324 $self->plugin('Kalamar::Plugin::' . $_);
325 };
326 };
327
Akron3422d452024-05-14 11:14:07 +0200328 # Set defaults per config
329 $self->defaults(
330 items_per_page => 25,
331 context => '40-t,40-t', # Before: 'base/s:p'/'paragraph'
Akron9d9872f2025-09-15 10:11:04 +0200332 alignment => 'left'
Akron3422d452024-05-14 11:14:07 +0200333 );
334
335 if (exists $conf->{defaults}) {
336 my $def = $conf->{defaults};
Akron9d9872f2025-09-15 10:11:04 +0200337 foreach (qw!items_per_page context alignment!) {
338 $self->defaults($_ => $def->{$_}) if $def->{$_};
339 };
Akron3422d452024-05-14 11:14:07 +0200340 };
341
Marc Kupietzaa6709c2025-12-19 20:03:54 +0100342 # Configure hint foundries for annotation layer helper hints
343 # Can be overridden via KALAMAR_HINT_FOUNDRIES environment variable (comma-separated)
344 # or via hint_foundries config option (array)
345 # Items starting with '-' exclude that foundry from defaults (e.g., '-spacy')
346 # If only exclusions are specified, they're removed from defaults
347 # If any positive items exist, they replace the defaults entirely
Marc Kupietzff51eb62026-01-15 17:39:42 +0100348 my @default_foundries = qw(base corenlp dereko malt marmot opennlp spacy tt);
Marc Kupietzaa6709c2025-12-19 20:03:54 +0100349 my $hint_foundries;
350 my $config_foundries;
351
352 if ($ENV{'KALAMAR_HINT_FOUNDRIES'}) {
353 $config_foundries = [split(/\s*,\s*/, $ENV{'KALAMAR_HINT_FOUNDRIES'})];
354 } elsif (exists $conf->{hint_foundries}) {
355 $config_foundries = $conf->{hint_foundries};
356 };
357
358 if ($config_foundries) {
359 # Separate exclusions (starting with '-') from inclusions
360 my @exclusions = map { substr($_, 1) } grep { /^-/ } @$config_foundries;
361 my @inclusions = grep { !/^-/ } @$config_foundries;
362
363 if (@inclusions) {
364 # If there are any positive items, use them as the full list
365 $hint_foundries = \@inclusions;
366 } elsif (@exclusions) {
367 # If only exclusions, remove them from defaults
368 my %exclude = map { lc($_) => 1 } @exclusions;
369 $hint_foundries = [grep { !$exclude{lc($_)} } @default_foundries];
370 } else {
371 $hint_foundries = \@default_foundries;
372 };
373 } else {
374 $hint_foundries = \@default_foundries;
375 };
376 $self->defaults(hint_foundries => $hint_foundries);
377
Nils Diewaldfccfbcb2015-04-29 20:48:19 +0000378 # Configure documentation navigation
Akrond512ea62019-10-24 15:50:04 +0200379 my $doc_navi = Mojo::File->new($self->home->child('templates','doc','navigation.json'))->slurp;
380 $doc_navi = $doc_navi ? decode_json($doc_navi) : [];
Akron1b1a2712018-12-21 14:59:05 +0100381
Akronf7ec4442019-10-27 20:01:05 +0100382 # TODO:
383 # Use navi->add()
Akron1b1a2712018-12-21 14:59:05 +0100384 if ($conf->{navi_ext}) {
Akrond512ea62019-10-24 15:50:04 +0200385 push @$doc_navi, @{$conf->{navi_ext}};
Akron1b1a2712018-12-21 14:59:05 +0100386 };
387
Akronf7ec4442019-10-27 20:01:05 +0100388 # TODO:
389 # Remove navi entry
Akrond512ea62019-10-24 15:50:04 +0200390 $self->config(doc_navi => $doc_navi);
Nils Diewaldfccfbcb2015-04-29 20:48:19 +0000391
Akronf7ec4442019-10-27 20:01:05 +0100392 $self->navi->set(doc => $doc_navi);
393
Akron63d963b2019-07-05 15:35:51 +0200394 $self->log->info('API expected at ' . $self->korap->api);
Nils Diewald709f52f2015-05-21 18:32:58 +0000395
Akron3cd391e2017-03-29 23:42:54 +0200396 # Establish routes with authentification
Akron7d75ee32017-05-02 13:42:41 +0200397 my $r = $self->routes;
Akron3cd391e2017-03-29 23:42:54 +0200398
Akronafeca252018-05-23 15:54:28 +0200399 # Set footer value
Akronef6d5f12018-05-28 17:54:58 +0200400 $self->content_block(footer => {
Akron3cfa26d2019-10-24 15:17:34 +0200401 inline => '<%= embedded_link_to "doc", "V ' . $Kalamar::VERSION . '", "korap", "kalamar" %>',
Akronafeca252018-05-23 15:54:28 +0200402 position => 100
Akronef6d5f12018-05-28 17:54:58 +0200403 });
Akronafeca252018-05-23 15:54:28 +0200404
Akronb7b91c52021-01-27 17:46:52 +0100405 # Add nonce script
406 $self->content_block(nonce_js => {
407 inline => <<'NONCE_JS'
408 // Remove the no-js class from the body
409 document.body.classList.remove('no-js');
410NONCE_JS
411 });
412
Nils Diewalda79b2682015-05-18 18:34:06 +0000413 # Base query route
Akronfb6d87d2018-10-24 18:10:20 +0200414 $r->get('/')->to('search#query')->name('index');
Nils Diewaldab4d3ca2015-04-17 01:48:43 +0000415
Nils Diewalda79b2682015-05-18 18:34:06 +0000416 # Documentation routes
hebastada903dd2021-07-20 15:58:48 +0200417 $r->get('/doc')->to('documentation#page', page => 'ql')->name('doc_start');
Akron254fe212019-10-24 14:33:28 +0200418 $r->get('/doc/:scope/:page')->to('documentation#page', scope => undef)->name('doc');
Nils Diewaldab4d3ca2015-04-17 01:48:43 +0000419
Akron59992122019-10-29 11:28:45 +0100420 # Settings routes
421 if ($self->navi->exists('settings')) {
422 $r->get('/settings')->to(
423 cb => sub {
Akron88c26b12020-09-07 12:44:18 +0200424 my $c = shift;
425 $c->res->headers->header('X-Robots' => 'noindex');
426 return $c->render('settings');
Akron59992122019-10-29 11:28:45 +0100427 }
428 )->name('settings_start');
429 $r->get('/settings/:scope/:page')->to(
430 scope => undef,
431 page => undef
432 )->name('settings');
433 };
Akronf7ec4442019-10-27 20:01:05 +0100434
Nils Diewaldc46003b2015-05-07 15:55:35 +0000435 # Contact route
436 $r->get('/contact')->to('documentation#contact');
437 $r->get('/contact')->mail_to_chiffre('documentation#contact');
438
Akron63d963b2019-07-05 15:35:51 +0200439 # API proxy route
Akronb9070eb2025-12-16 12:17:59 +0100440 $r->any('/api/v#apiv' => [apiv => $API_VERSION_SUPPORTED])->name('proxy')->to('Proxy#api_pass');
441 $r->any('/api/v#apiv/*proxy_path' => [apiv => $API_VERSION_SUPPORTED])->to('Proxy#api_pass');
Akronacb7f3d2025-09-17 11:56:45 +0200442
443 # General proxy mounts
444 my $proxies = $conf->{'proxies'} // [];
445 foreach (@$proxies) {
446 next if $_ eq 'PROXY_STUB';
447
448 my $root_path = Mojo::Path->new($_->{root_path})
449 ->canonicalize->leading_slash(1)
450 ->trailing_slash(1);
451
452 my %stash_hash = (
453 service => $_->{service},
454 root_path => $root_path,
455 mount => $_->{mount},
456 );
457
458 $r->any($root_path)->name($_->{service})->to(
459 'Proxy#pass', %stash_hash
460 );
461
462 $r->any($root_path . '*proxy_path')->to(
463 'Proxy#pass', %stash_hash
464 );
465 };
Akron63d963b2019-07-05 15:35:51 +0200466
Nils Diewald7148c6f2015-05-04 15:07:53 +0000467 # Match route
Akron80a84b22018-10-24 17:44:24 +0200468 # Corpus route
Akronfb6d87d2018-10-24 18:10:20 +0200469 my $corpus = $r->get('/corpus')->to('search#corpus_info')->name('corpus');
Akron4e413fb2023-09-26 13:11:11 +0200470 my $doc = $r->any('/corpus/#corpus_id/#doc_id');
471 my $text = $doc->get('/#text_id')->to('search#text_info')->name('text');
472 my $match = $doc->get('/#text_id/#match_id')->to('search#match_info')->name('match');
Nils Diewald996aa552014-12-02 03:26:44 +0000473};
474
475
4761;
477
478
479__END__
Nils Diewalda898dac2015-05-06 21:04:16 +0000480
481=pod
482
Nils Diewaldeb5f3072015-05-20 09:32:42 +0000483=encoding utf8
Nils Diewalda898dac2015-05-06 21:04:16 +0000484
Nils Diewaldeb5f3072015-05-20 09:32:42 +0000485=head1 NAME
486
487Kalamar
Nils Diewalda0defc42015-05-07 23:54:17 +0000488
489
Nils Diewaldeb5f3072015-05-20 09:32:42 +0000490=head1 DESCRIPTION
Nils Diewalda0defc42015-05-07 23:54:17 +0000491
Nils Diewaldeb5f3072015-05-20 09:32:42 +0000492L<Kalamar> is a L<Mojolicious|http://mojolicio.us/> based user interface
Akron87468c22021-02-08 09:30:01 +0100493frontend for the L<KorAP Corpus Analysis Platform|https://korap.ids-mannheim.de/>.
Nils Diewaldeb5f3072015-05-20 09:32:42 +0000494
Akron456abd92015-06-02 15:07:21 +0200495B<See the README for further information!>
Nils Diewaldeb5f3072015-05-20 09:32:42 +0000496
Akron456abd92015-06-02 15:07:21 +0200497=head2 COPYRIGHT AND LICENSE
Nils Diewalda748b0e2015-05-19 22:54:06 +0000498
Akron006ddc62024-02-19 08:49:43 +0100499Copyright (C) 2015-2024, L<IDS Mannheim|https://www.ids-mannheim.de/>
Akron87468c22021-02-08 09:30:01 +0100500Author: L<Nils Diewald|https://www.nils-diewald.de/>
Nils Diewalda748b0e2015-05-19 22:54:06 +0000501
502Kalamar is developed as part of the L<KorAP|http://korap.ids-mannheim.de/>
503Corpus Analysis Platform at the
Akron87468c22021-02-08 09:30:01 +0100504L<Leibniz Institute for the German Language (IDS)|https://www.ids-mannheim.de/>,
Nils Diewalda748b0e2015-05-19 22:54:06 +0000505member of the
hebasta21b7baf2019-12-16 10:32:43 +0100506L<Leibniz-Gemeinschaft|http://www.leibniz-gemeinschaft.de>
Nils Diewalda748b0e2015-05-19 22:54:06 +0000507and supported by the L<KobRA|http://www.kobra.tu-dortmund.de> project,
508funded by the
509L<Federal Ministry of Education and Research (BMBF)|http://www.bmbf.de/en/>.
510
511Kalamar is free software published under the
Akron87468c22021-02-08 09:30:01 +0100512L<BSD-2 License|https://opensource.org/licenses/BSD-2-Clause>.
Nils Diewalda748b0e2015-05-19 22:54:06 +0000513
514=cut