summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDaniel Friesel <derf@finalrewind.org>2022-02-14 21:41:32 +0100
committerDaniel Friesel <derf@finalrewind.org>2022-02-14 21:41:32 +0100
commit6fc21cac41e3b1bf4a6484fed736aec27b340b63 (patch)
tree058c5770141d57320f50f163e49fcd382040c3db
parent170c7e420e89ec780ee336a508f4862feed651f0 (diff)
Use correct base URL when running a command job (work/maintenance)
-rw-r--r--examples/travelynx.conf10
-rwxr-xr-xlib/Travelynx.pm19
2 files changed, 25 insertions, 4 deletions
diff --git a/examples/travelynx.conf b/examples/travelynx.conf
index 0499796..47bc92c 100644
--- a/examples/travelynx.conf
+++ b/examples/travelynx.conf
@@ -5,6 +5,16 @@
# 'localhost'.
{
+ # Base URL of this travelynx installation, e.g. "https://travelynx.de" for
+ # travelynx.de. Used to identify this travelynx instance when performing API
+ # requests (so API providers know whom to contact case of issues) and for
+ # imprint and other links in travelynx E-Mails. Note that this entry is
+ # only used when travelynx is performing requests or sending E-mails from
+ # a "work", "worker", or "maintenance" job. Otherwise, it will infer the
+ # base URL from the HTTP request. If your travelynx instance is reachable
+ # via multiple URLs, use any one of them.
+ base_url => Mojo::URL->new('https://FIXME.local'),
+
# travelynx relies on several backend projects. You may override the
# defaults to use other (e.g. self-hosted) instances.
backend => {
diff --git a/lib/Travelynx.pm b/lib/Travelynx.pm
index b7284e4..8e29114 100755
--- a/lib/Travelynx.pm
+++ b/lib/Travelynx.pm
@@ -277,6 +277,17 @@ sub startup {
);
$self->helper(
+ base_url_for => sub {
+ my ( $self, $path ) = @_;
+ if ( ( my $url = $self->url_for($path) )->base ne q{} ) {
+ return $url;
+ }
+ return $self->url_for($path)
+ ->base( $self->app->config->{base_url} );
+ }
+ );
+
+ $self->helper(
hafas => sub {
my ($self) = @_;
state $hafas = Travelynx::Helper::HAFAS->new(
@@ -284,7 +295,7 @@ sub startup {
hafas_rest_api => $self->app->config->{backend}{hafas_rest_api},
main_cache => $self->app->cache_iris_main,
realtime_cache => $self->app->cache_iris_rt,
- root_url => $self->url_for('/')->to_abs,
+ root_url => $self->base_url_for('/')->to_abs,
user_agent => $self->ua,
version => $self->app->config->{version},
);
@@ -298,7 +309,7 @@ sub startup {
log => $self->app->log,
main_cache => $self->app->cache_iris_main,
realtime_cache => $self->app->cache_iris_rt,
- root_url => $self->url_for('/')->to_abs,
+ root_url => $self->base_url_for('/')->to_abs,
version => $self->app->config->{version},
);
}
@@ -317,7 +328,7 @@ sub startup {
state $trwl_api = Travelynx::Helper::Traewelling->new(
log => $self->app->log,
model => $self->traewelling,
- root_url => $self->url_for('/')->to_abs,
+ root_url => $self->base_url_for('/')->to_abs,
user_agent => $self->ua,
version => $self->app->config->{version},
);
@@ -406,7 +417,7 @@ sub startup {
state $dbdb = Travelynx::Helper::DBDB->new(
log => $self->app->log,
cache => $self->app->cache_iris_main,
- root_url => $self->url_for('/')->to_abs,
+ root_url => $self->base_url_for('/')->to_abs,
user_agent => $self->ua,
version => $self->app->config->{version},
);