Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
* Setup the middleware queue your application will use.
* @param \Cake\Http\MiddlewareQueue $middlewareQueue The middleware queue to setup.
* @return \Cake\Http\MiddlewareQueue The updated middleware queue.
public function middleware(MiddlewareQueue $middlewareQueue): MiddlewareQueue
$bodies = new BodyParserMiddleware();
// Catch any exceptions in the lower layers,
// and make an error page/response
->add(new ErrorHandlerMiddleware(Configure::read('Error')))
// Handle plugin/theme assets like CakePHP normally does.
->add(new AssetMiddleware([
'cacheTime' => Configure::read('Asset.cacheTime'),
// Add routing middleware.
// If you have a large number of routes connected, turning on routes
// caching in production could improve performance. For that when
// creating the middleware instance specify the cache config name by
// using it's second constructor argument:
// `new RoutingMiddleware($this, '_cake_routes_')`
->add(new RoutingMiddleware($this))->add($bodies);
return $middlewareQueue;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment