mirror of
https://github.com/flarum/core.git
synced 2025-10-12 15:34:26 +02:00
API: Add an event to configure server middleware
This commit is contained in:
@@ -11,6 +11,7 @@
|
||||
|
||||
namespace Flarum\Api;
|
||||
|
||||
use Flarum\Event\ConfigureMiddleware;
|
||||
use Flarum\Foundation\Application;
|
||||
use Flarum\Http\AbstractServer;
|
||||
use Tobscure\JsonApi\Document;
|
||||
@@ -25,20 +26,23 @@ class Server extends AbstractServer
|
||||
{
|
||||
$pipe = new MiddlewarePipe;
|
||||
|
||||
$apiPath = parse_url($app->url('api'), PHP_URL_PATH);
|
||||
$path = parse_url($app->url('api'), PHP_URL_PATH);
|
||||
|
||||
if ($app->isInstalled() && $app->isUpToDate()) {
|
||||
$pipe->pipe($apiPath, $app->make('Flarum\Http\Middleware\ParseJsonBody'));
|
||||
$pipe->pipe($apiPath, $app->make('Flarum\Api\Middleware\FakeHttpMethods'));
|
||||
$pipe->pipe($apiPath, $app->make('Flarum\Http\Middleware\StartSession'));
|
||||
$pipe->pipe($apiPath, $app->make('Flarum\Http\Middleware\RememberFromCookie'));
|
||||
$pipe->pipe($apiPath, $app->make('Flarum\Http\Middleware\AuthenticateWithSession'));
|
||||
$pipe->pipe($apiPath, $app->make('Flarum\Http\Middleware\AuthenticateWithHeader'));
|
||||
$pipe->pipe($apiPath, $app->make('Flarum\Http\Middleware\SetLocale'));
|
||||
$pipe->pipe($apiPath, $app->make('Flarum\Http\Middleware\DispatchRoute', ['routes' => $app->make('flarum.api.routes')]));
|
||||
$pipe->pipe($apiPath, $app->make('Flarum\Api\Middleware\HandleErrors'));
|
||||
$pipe->pipe($path, $app->make('Flarum\Http\Middleware\ParseJsonBody'));
|
||||
$pipe->pipe($path, $app->make('Flarum\Api\Middleware\FakeHttpMethods'));
|
||||
$pipe->pipe($path, $app->make('Flarum\Http\Middleware\StartSession'));
|
||||
$pipe->pipe($path, $app->make('Flarum\Http\Middleware\RememberFromCookie'));
|
||||
$pipe->pipe($path, $app->make('Flarum\Http\Middleware\AuthenticateWithSession'));
|
||||
$pipe->pipe($path, $app->make('Flarum\Http\Middleware\AuthenticateWithHeader'));
|
||||
$pipe->pipe($path, $app->make('Flarum\Http\Middleware\SetLocale'));
|
||||
|
||||
event(new ConfigureMiddleware($pipe, $path, $this));
|
||||
|
||||
$pipe->pipe($path, $app->make('Flarum\Http\Middleware\DispatchRoute', ['routes' => $app->make('flarum.api.routes')]));
|
||||
$pipe->pipe($path, $app->make('Flarum\Api\Middleware\HandleErrors'));
|
||||
} else {
|
||||
$pipe->pipe($apiPath, function () {
|
||||
$pipe->pipe($path, function () {
|
||||
$document = new Document;
|
||||
$document->setErrors([
|
||||
[
|
||||
|
Reference in New Issue
Block a user