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

URL issue with http proxy #24

Open
PJ-DSI-DevOps opened this issue Dec 14, 2020 · 0 comments
Open

URL issue with http proxy #24

PJ-DSI-DevOps opened this issue Dec 14, 2020 · 0 comments

Comments

@PJ-DSI-DevOps
Copy link

PJ-DSI-DevOps commented Dec 14, 2020

Hello,

When using this plugin behind a reverse proxy with path, the urls generated by "url_for" doesn't work as expected anymore. We end up having a path that look like /{LANG}/{PATH}/foo instead of /{PATH}/{LANG}/foo.

The method used to set the reverse proxy path is taken from this blog post : https://mojolicious.io/blog/2019/03/18/reverse-proxy-with-path/

Here is a small app to reproduce the problem :

use Mojolicious::Lite -signatures;

plugin I18N => {namespace => 'MyApp::I18N', support_url_langs => [qw(en fr)]};

if ( my $path = $ENV{MOJO_REVERSE_PROXY} ) {
    my @path_parts = grep /\S/, split m{/}, $path;
    app->hook( before_dispatch => sub ($c) {
        my $url = $c->req->url;
        my $base = $url->base;
        push @{ $base->path }, @path_parts;
        $base->path->trailing_slash(1);
        $url->path->leading_slash(0);
    });
}

get '/' => sub ($c) {
  $c->render(text => $c->url_for('/foo'));
};

app->start;

Then :

MOJO_REVERSE_PROXY="/myapp" ./base_i18n.pl get /fr/
/fr/myapp/foo

And i was expecting /myapp/fr/foo.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant