skipperbent / simple-php-router

Simple, fast and yet powerful PHP router that is easy to get integrated and in any project. Heavily inspired by the way Laravel handles routing, with both simplicity and expand-ability in mind.
631 stars 116 forks source link

Add support for handling CORS preflight requests #714

Open jurakin opened 1 month ago

jurakin commented 1 month ago

Description

This pull request adds support for handling CORS preflight requests in the routing system. The router will respond to OPTIONS requests only when the route actually exists and a preflight setting is enabled. The setting is disabled by default.

Changes

Usage

// single route
SimpleRouter::form('foo', function () {
    // ...
})->setSettings(['preflight' => true]);

// group routes
SimpleRouter::group(['preflight' => true], function () {
    SimpleRouter::form('foo', function() {
        // ...
    });
});