The Wayback Machine - https://web.archive.org/web/20220508105456/https://github.com/Difegue/LANraragi/issues/363
Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Feature Request] Add base url support #363

Open
fullmetal1 opened this issue Nov 15, 2020 · 3 comments
Open

[Feature Request] Add base url support #363

fullmetal1 opened this issue Nov 15, 2020 · 3 comments

Comments

@fullmetal1
Copy link

@fullmetal1 fullmetal1 commented Nov 15, 2020

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.

@Difegue
Copy link

@Difegue Difegue commented Nov 16, 2020

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?

@fullmetal1
Copy link
Author

@fullmetal1 fullmetal1 commented Nov 17, 2020

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.

@Difegue
Copy link

@Difegue Difegue commented Nov 17, 2020

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment