mirror of
https://github.com/flarum/core.git
synced 2025-10-12 07:24:27 +02:00
Fixes wrong IP address when using a reverse proxy (#2236)
Added reverse proxy support to preserve forwarded IPs
This commit is contained in:
@@ -22,6 +22,7 @@ use Flarum\Http\Middleware as HttpMiddleware;
|
||||
use Flarum\Http\RouteCollection;
|
||||
use Flarum\Http\RouteHandlerFactory;
|
||||
use Flarum\Http\UrlGenerator;
|
||||
use Illuminate\Support\Arr;
|
||||
use Laminas\Stratigility\MiddlewarePipe;
|
||||
|
||||
class ApiServiceProvider extends AbstractServiceProvider
|
||||
@@ -45,6 +46,7 @@ class ApiServiceProvider extends AbstractServiceProvider
|
||||
$this->app->singleton('flarum.api.middleware', function () {
|
||||
return [
|
||||
'flarum.api.error_handler',
|
||||
'flarum.api.proxy_middleware',
|
||||
HttpMiddleware\ParseJsonBody::class,
|
||||
Middleware\FakeHttpMethods::class,
|
||||
HttpMiddleware\StartSession::class,
|
||||
@@ -64,6 +66,15 @@ class ApiServiceProvider extends AbstractServiceProvider
|
||||
);
|
||||
});
|
||||
|
||||
$this->app->bind('flarum.api.proxy_middleware', function () {
|
||||
$config = $this->app->make('flarum.config');
|
||||
|
||||
return new HttpMiddleware\ProxyAddress(
|
||||
Arr::get($config, 'reverse_proxy.enabled', false),
|
||||
Arr::get($config, 'reverse_proxy.allowed', ['127.0.0.1'])
|
||||
);
|
||||
});
|
||||
|
||||
$this->app->singleton('flarum.api.handler', function () {
|
||||
$pipe = new MiddlewarePipe;
|
||||
|
||||
|
Reference in New Issue
Block a user