Skip to content

Latest commit

 

History

History
41 lines (31 loc) · 1 KB

File metadata and controls

41 lines (31 loc) · 1 KB

Mezzio

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 Laminas\Diactoros\ResponseFactory;
use Mezzio\Expressive\Application;

$app = new Application();

$app->pipe(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
));