Closed zepfietje closed 1 year ago
Hi there,
Middleware is handled differently in Folio Router and even if we can merge the PR it would be slightly different from middleware registered to Laravel Router.
Alternatively, you can also run the following if possible.
/**
* Handle an incoming request.
*
* @param \Closure(\Illuminate\Http\Request): (\Symfony\Component\HttpFoundation\Response) $next
*/
public function handle(Request $request, Closure $next): Response
{
return tap($next($request), function ($response) use ($request) {
// Run any terminating feature.
});
}
Thanks for taking a look at this issue, @crynobone!
Would your suggested code snippet actually run the code after returning the response though?
For now I've worked around it by using a regular middleware and app()->terminating()
.
Figured it'd be good to still report the issue as others might run into it too.
Laravel does use this in some middleware including https://github.com/laravel/framework/blob/10.x/src/Illuminate/Session/Middleware/AuthenticateSession.php
Okay, but is that behavior exactly the same as terminable middleware works?
Asking since I'm using it for tracking pageviews to an analytics service from the back end. Calling the analytics API before the response is actually returned, results in performance issues in your app.
Terminable middleware is executed slightly later in the request lifecycle (terminating the app from HTTP Kernel) and may behave differently during feature tests. I myself haven't use terminable middleware.
No worries, @crynobone. Just want to make sure that terminable middleware runs in a similar fashion as it does when not using Folio. If that's impossible to achieve, it's probably better to not support it.
Folio Version
v1.0.0-beta.2
Laravel Version
v10.17.1
PHP Version
8.2.8
Description
When registering terminable middleware in the
FolioServiceProvider
, theterminate()
function of the middleware isn't executed.Steps To Reproduce
terminate()
method:info('terminating')
FolioServiceProvider
:terminating
log entry