[Koha-devel] Plack Middleware to isolate library branches via path

Thomas Klausner domm at plix.at
Tue Apr 19 14:12:45 CEST 2022


Hi!

A customer wants to access branches/branchgroups via a subpath, instead 
of the more common / documented way of setting up a subdomain per 
branch:
https://wiki.koha-community.org/wiki/Override_sysprefs_in_Apache_config

So instead of https://aaa.library.example.com/ they want 
https://library.example.com/aaa/  (for ~10 branches)


This boils down to:
- matching the path and munging the URL
- setting some ENV vars (OPAC_SEARCH_LIMIT, OPAC_CSS_OVERRIDE, etc)
- munging the HTML generated by Koha to fix the links

While this could be implemented via carefull application of various 
Apache modules (mod_proxy, mod_rewrite, mod_proxy_html) I feel more 
comfortable implementing this in Perl in a Plack Middleware.
The result is not very pretty, but seems to work (see attached code...)

But to load the middleware, I have to enable it in /etc/koha/plack.psgi 
and thus change a core file (or copy upstream plack.psgi and edit the 
copy, which still means that we'll have to apply our changes after each 
update)

In theory we could add some config to load custom Middlewares, but as 
the load order of Middlewares is very relevant, this seems hardly doable 
- unless we start with one middleware config slot at the location I need :-)

Anyway, I think we'll just go with maintaining a custom plack.psgi, 
unless anybody here has any other ideas / best practices / solutions on 
how to mount library branches at location/sub-dirs... I'm also not sure 
if this feature is on any roadmap etc.


Greetings,
domm


-- 
#!/usr/bin/perl                             https://domm.plix.at
for(ref bless{},just'another'perl'hacker){s-:+-$"-g&&print$_.$/}
-------------- next part --------------
A non-text attachment was scrubbed...
Name: IsolateBranch.pm
Type: text/x-perl
Size: 2447 bytes
Desc: not available
URL: <http://lists.koha-community.org/pipermail/koha-devel/attachments/20220419/6cc9a231/attachment.pm>


More information about the Koha-devel mailing list