From 84a068e5a89aef38c75bd0520e7f3e13c9334e46 Mon Sep 17 00:00:00 2001 From: Lucas Gabriel Vuotto Date: Sun, 4 May 2025 09:36:09 +0000 Subject: [PATCH] site: allow to directly mount api --- bin/run.pl | 1 - lib/Pooru/Site.pm | 11 ++++++++++- pooru-site.conf | 8 +++++++- 3 files changed, 17 insertions(+), 3 deletions(-) diff --git a/bin/run.pl b/bin/run.pl index 1adc726..e4a9ea6 100644 --- a/bin/run.pl +++ b/bin/run.pl @@ -6,7 +6,6 @@ app->secrets(["unused"]); app->static->paths(["s"]); app->static->prefix("/s"); -plugin Mount => { "/api/v0" => "script/pooru-api-v0" }; plugin Mount => { "/" => "script/pooru-site" }; app->start; diff --git a/lib/Pooru/Site.pm b/lib/Pooru/Site.pm index b3b2794..2c555e2 100644 --- a/lib/Pooru/Site.pm +++ b/lib/Pooru/Site.pm @@ -82,12 +82,21 @@ sub startup ($self) my $config = $self->plugin("Config"); $self->secrets($config->{secrets}); + my %api; + if (defined(my $m = $config->{pooru_api}->{v0}->{mount})) { + $api{v0} = $self->plugin("Mount" => { + $m => $self->home->child("script", "pooru-api-v0"), + })->to_string; + } else { + $api{v0} = $config->{pooru_api}->{v0}->{endpoint}; + } + $self->helper(storage => sub { state $storage = Pooru::Storage::Static-> new($config->{store}, "/s/"); }); $self->helper(api_v0_url => sub { - return Mojo::URL->new($self->config("pooru_api")->{v0}); + return Mojo::URL->new("$api{v0}/"); }); $self->helper(extended_pager => \&extended_pager); $self->helper(tag_for_pager_shortcut => \&tag_for_pager_shortcut); diff --git a/pooru-site.conf b/pooru-site.conf index 611ce91..663c692 100644 --- a/pooru-site.conf +++ b/pooru-site.conf @@ -1,6 +1,12 @@ { pooru_api => { - v0 => "http://127.0.0.1:3000/api/v0/", + v0 => { + # Recommended for development. + mount => "/api/v0", + + # To run in a different location: + #endpoint => "https://api.example.com/v0", + }, }, store => "db/pooru.storable",