PHP code example of neomerx / cors-illuminate

1. Go to this page and download the library: Download neomerx/cors-illuminate library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

neomerx / cors-illuminate example snippets


class Kernel extends HttpKernel
{
    ...

    protected $middleware = [
        \Illuminate\Foundation\Http\Middleware\CheckForMaintenanceMode::class,
        \Neomerx\CorsIlluminate\CorsMiddleware::class, // <== add this line
        
        ...
    ];
    
    ...
}

$app->middleware([
    ...
    \Neomerx\CorsIlluminate\CorsMiddleware::class,
]);

$app->register(\Neomerx\CorsIlluminate\Providers\LumenServiceProvider::class);

    ...
    
    /**
     * Could be string or array. If specified as array (recommended for
     * better performance) it should be in parse_url() result format.
     */
    Settings::KEY_SERVER_ORIGIN => [
        'scheme' => 'http',
        'host'   => 'localhost',
        'port'   => 1337,
    ],

    /**
     * A list of allowed request origins (no trail slashes).
     * If value is not on the list it is considered as not allowed.
     * If you want to allow all origins remove/comment this section.
     */
    Settings::KEY_ALLOWED_ORIGINS => [
        'http://localhost:4200',
    ],
    
    ...

use Neomerx\Cors\Contracts\AnalysisResultInterface;

$corsHeaders = [];
if (app()->resolved(AnalysisResultInterface::class) === true) {
    /** @var AnalysisResultInterface $result */
    $result = app(AnalysisResultInterface::class);
    $corsHeaders = $result->getResponseHeaders();
}

php artisan vendor:publish --provider="Neomerx\CorsIlluminate\Providers\LaravelServiceProvider"