Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/marcusramberg/mojolicious-plugin-requestbase
Set request base based on X-Request-Base for reverse proxy setups
https://github.com/marcusramberg/mojolicious-plugin-requestbase
Last synced: 17 days ago
JSON representation
Set request base based on X-Request-Base for reverse proxy setups
- Host: GitHub
- URL: https://github.com/marcusramberg/mojolicious-plugin-requestbase
- Owner: marcusramberg
- Created: 2011-11-18T07:40:21.000Z (about 13 years ago)
- Default Branch: master
- Last Pushed: 2016-11-18T08:33:32.000Z (about 8 years ago)
- Last Synced: 2024-12-21T11:51:29.403Z (26 days ago)
- Language: Perl
- Homepage:
- Size: 16.6 KB
- Stars: 4
- Watchers: 4
- Forks: 0
- Open Issues: 1
-
Metadata Files:
- Readme: README
- Changelog: Changes
Awesome Lists containing this project
README
NAME
Mojolicious::Plugin::RequestBase - Support setting base in frontend
proxySYNOPSIS
Frontend proxy
The "X-Request-Base" header must be set in the frontend proxy.# nxinx
proxy_set_header X-Request-Base "https://example.com/myapp";
# or
proxy_set_header X-Request-Base "/myapp";Application
This plugin will read the "X-Request-Base" header.# Mojolicious
$app->plugin("RequestBase");# Mojolicious::Lite
plugin "RequestBase";Controller
URL generating helpers, such as url_for will create the correct URL
using the base URL from "X-Request-Base".Here are example with "X-Request-Base" set to
"https://example.com/myapp" and a request sent to Request to
"https://example.com/myapp/foo":# /myapp/foo
$c->url_for;# https://example.com/myapp/foo
$c->url_for->to_abs;# https://example.com/myapp/some/path
$c->url_for("/some/path")->to_abs;# https://example.com/foo (Probably not what you want)
$c->req->url->to_abs;Hooks
before_dispatch
In a before_dispatch the router has not yet started, so you need to pass
in the request path to get the expected result:hook before_dispatch => sub {
my $c = shift;# https://example.com/myapp/foo
$c->url_for($c->req->url->path)->to_abs;# https://example.com/foo (Probably not what you want)
$c->url_for->to_abs;
};DESCRIPTION
Simple plugin to support Request Base header. Just load it and set
X-Request-Base in your Frontend Proxy. For instance, if you are using
nginx you could use it like this:proxy_set_header X-Request-Base 'https://example.com/myapp';
Note that you can also pass a relative URL to retain the original
hostname provided by the proxy.METHODS
Mojolicious::Plugin::RequestBase inherits all methods from
Mojolicious::Plugin and implements the following new ones.register
$plugin->register;Register plugin in Mojolicious application.
SEE ALSO
Catalyst::TraitFor::Request::ProxyBase, Mojolicious,
Mojolicious::Guides, .COPYRIGHT AND LICENSE
Copyright (C) 2011, Marcus Ramberg.This program is free software, you can redistribute it and/or modify it
under the terms of the Artistic License version 2.0.