LANraragi icon indicating copy to clipboard operation
LANraragi copied to clipboard

[Feature Request] Add base url support

Open fullmetal1 opened this issue 4 years ago • 3 comments

The purpose is to provide the ability to run lanraragi behind a reverse proxy as a subpath of a domain instead of a subdomain, since many free services do not allow ddns domains to have subdomains.

fullmetal1 avatar Nov 15 '20 00:11 fullmetal1

According to the links in the previous issue we touched upon this subject, implementation could be as simple as adding a hook if a base url is configured:

app->hook( before_dispatch => sub {
        my $c = shift;
        unless ($c->req->url->path->to_route =~ m#/baseurl#) {
            $c->req->url->path( "/baseurl" . $c->req->url->path->to_string);
        }
    } );

(https://stackoverflow.com/questions/25170147/base-url-in-mojolicious-template-rendering)

The bigger question is where to put the base url config?
I honestly don't think this is a setting that would be used much, and it can't be set from the web interface since you likely won't have access to it, so it'd probably be fine in lrr.conf. Might also want to add an environment variable override for Docker users?

Difegue avatar Nov 16 '20 17:11 Difegue

You already have a hook into before dispatch, and that module has access to the LANraragi settings module. I was testing it out but couldn't understand mojolicious' url object. Had some wierd behaviour with url->base that would make it use the wrong address, and also the web app pages didn't seem to exist at the rewritten locations.I couldn't figure it out after a few hours.

fullmetal1 avatar Nov 17 '20 14:11 fullmetal1

Oh yeah, the SIGTERM catcher does hook in before_dispatch.
You can add code in there no problem normally, I still think it'd be better/easier to put the base url setting in lrr.conf, you could then access it with something as dumb as $config->{base_url}.

If you can't get stuff working in a hook, I think Routing.pm would also be an acceptable place to try? You could store the base url setting in a string (defaulting to empty of course) and prepend that to each routed URL path.

Difegue avatar Nov 17 '20 15:11 Difegue