Skip to content

Latest commit

 

History

History
46 lines (36 loc) · 1.19 KB

Slim3.md

File metadata and controls

46 lines (36 loc) · 1.19 KB

Slim 3

Requirements

Example

<?php

declare(strict_types=1);

namespace App;

use Chubbyphp\Cors\CorsMiddleware;
use Chubbyphp\Cors\Negotiation\HeadersNegotiator;
use Chubbyphp\Cors\Negotiation\MethodNegotiator;
use Chubbyphp\Cors\Negotiation\Origin\AllowOriginExact;
use Chubbyphp\Cors\Negotiation\Origin\AllowOriginRegex;
use Chubbyphp\Cors\Negotiation\Origin\OriginNegotiator;
use Chubbyphp\SlimPsr15\MiddlewareAdapter;
use Http\Factory\Slim\ResponseFactory;
use Slim\App;

$app = new App();

$app->add(new MiddlewareAdapter(
    new CorsMiddleware(
        new ResponseFactory(),
        new OriginNegotiator([
            new AllowOriginExact('https://myproject.com'),
            new AllowOriginRegex('^https://myproject\.'),
        ]), // allow-origin
        new MethodNegotiator(['GET', 'POST']), // allow-method
        new HeadersNegotiator(['X-Custom-Request']), // allow-headers
        ['X-Custom-Response'], // expose-headers
        true, // allow-credentials
        7200 // max age
    )
));