Skip to content

Commit

Permalink
fix: repetitive requests on forum frontend (#11)
Browse files Browse the repository at this point in the history
* fix: repetitive requests when debugging forum frontend

* revert admin check change

* feat: add middleware event
  • Loading branch information
SychO9 authored Jul 11, 2022
1 parent 1436b19 commit 8c75555
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 0 deletions.
2 changes: 2 additions & 0 deletions src/Clockwork/FlarumDataSource.php
Original file line number Diff line number Diff line change
Expand Up @@ -114,9 +114,11 @@ public function listenToEvents()
{
$this->container['events']->listen('clockwork.middleware.start', function () {
$this->timeline->event('Request processing')->color('purple')->begin();
$this->timeline->event('Middleware')->color('yellow')->begin();
});

$this->container['events']->listen('clockwork.controller.start', function () {
$this->timeline->event('Middleware')->end();
$this->timeline->event('Controller logic')->color('purple')->begin();
});

Expand Down
2 changes: 2 additions & 0 deletions src/Middleware/ClockworkMiddleware.php
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,8 @@ public function process(ServerRequestInterface $request, RequestHandlerInterface
$request = $request->withUri($uri->withPath('/api'.$uri->getPath()));
} elseif ($requestHandler == 'flarum.admin.middleware') {
$request = $request->withUri($uri->withPath('/admin'.$uri->getPath()));
} elseif ($requestHandler == 'flarum.forum.handler') {
$request = $request->withUri($uri->withPath('/forum'.$uri->getPath()));
}

$this->container['clockwork.flarum']
Expand Down
8 changes: 8 additions & 0 deletions src/Provider/ClockworkServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
use FoF\Clockwork\Clockwork\FlarumAuthenticator;
use FoF\Clockwork\Clockwork\FlarumDataSource;
use FoF\Clockwork\Middleware\BeforeRouteExecutionMiddleware;
use FoF\Clockwork\Middleware\ClockworkMiddleware;
use Illuminate\Support\ServiceProvider;

class ClockworkServiceProvider extends ServiceProvider
Expand All @@ -48,6 +49,13 @@ public function boot()
return $middleware;
});
}

// Remove the clockwork middleware from API Client handling
$this->app->extend('flarum.api_client.exclude_middleware', function (array $exlusions) {
$exlusions[] = ClockworkMiddleware::class;

return $exlusions;
});
}

public function register()
Expand Down

0 comments on commit 8c75555

Please sign in to comment.