diff --git a/framework/core/src/Api/Controller/CreateDiscussionController.php b/framework/core/src/Api/Controller/CreateDiscussionController.php index 16d9443c2..b4d8b5603 100644 --- a/framework/core/src/Api/Controller/CreateDiscussionController.php +++ b/framework/core/src/Api/Controller/CreateDiscussionController.php @@ -54,7 +54,7 @@ class CreateDiscussionController extends AbstractCreateController protected function data(ServerRequestInterface $request, Document $document) { $actor = $request->getAttribute('actor'); - $ipAddress = Arr::get($request->getServerParams(), 'REMOTE_ADDR', '127.0.0.1'); + $ipAddress = $request->getAttribute('ipAddress'); $discussion = $this->bus->dispatch( new StartDiscussion($actor, Arr::get($request->getParsedBody(), 'data', []), $ipAddress) diff --git a/framework/core/src/Api/Controller/CreatePostController.php b/framework/core/src/Api/Controller/CreatePostController.php index 171130955..d3a6459d9 100644 --- a/framework/core/src/Api/Controller/CreatePostController.php +++ b/framework/core/src/Api/Controller/CreatePostController.php @@ -55,7 +55,7 @@ class CreatePostController extends AbstractCreateController $actor = $request->getAttribute('actor'); $data = Arr::get($request->getParsedBody(), 'data', []); $discussionId = Arr::get($data, 'relationships.discussion.data.id'); - $ipAddress = Arr::get($request->getServerParams(), 'REMOTE_ADDR', '127.0.0.1'); + $ipAddress = $request->getAttribute('ipAddress'); $post = $this->bus->dispatch( new PostReply($discussionId, $actor, $data, $ipAddress) diff --git a/framework/core/src/Foundation/InstalledApp.php b/framework/core/src/Foundation/InstalledApp.php index 5fbccf656..a7d0f88b5 100644 --- a/framework/core/src/Foundation/InstalledApp.php +++ b/framework/core/src/Foundation/InstalledApp.php @@ -55,6 +55,7 @@ class InstalledApp implements AppInterface $pipe = new MiddlewarePipe; + $pipe->pipe(new HttpMiddleware\ProcessIp()); $pipe->pipe(new BasePath($this->basePath())); $pipe->pipe(new OriginalMessages); $pipe->pipe( diff --git a/framework/core/src/Http/Middleware/ProcessIp.php b/framework/core/src/Http/Middleware/ProcessIp.php new file mode 100644 index 000000000..0a5ae94bf --- /dev/null +++ b/framework/core/src/Http/Middleware/ProcessIp.php @@ -0,0 +1,26 @@ +getServerParams(), 'REMOTE_ADDR', '127.0.0.1'); + + return $handler->handle($request->withAttribute('ipAddress', $ipAddress)); + } +}