Where in the Middlewares should CORS Middleware be placed in CakePHP?

Written by James McDonald

April 21, 2022

Answer: Before RoutingMiddleware

EventManager::instance()->on('Server.buildMiddleware',
    function ($event, $middleware) {
        try {
            $middleware->insertBefore(RoutingMiddleware::class, new CorsMiddleware());
        } catch (\LogicException $exception) {
            $middleware->add(new CorsMiddleware());
        }
    }
);

0 Comments

Submit a Comment

Your email address will not be published.

You May Also Like…

List your VSCode Extensions

Ever wondered what extensions you have installed and want to keep a list? This actually is a good way to audit your...

array_merge vs the + operator

<?php $options = [ 'rootNode' => 'response' ]; // array_merge // the same key appearing later will overwrite echo...