Skip to content

A CakePHP (3.7+) middleware for activate cors domain in your application.

Notifications You must be signed in to change notification settings

aymeekouakou/cakephp-cors-middleware

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

21 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Build Status

A CakePHP (3.7+) middleware for activate cors domain in your application. Middleware docs.

Learn more about CORS

Requirements

  • PHP version 7.2 or higher
  • CakePhp 3.7 or higher

Installation

You can install this plugin into your CakePHP application using composer.

The recommended way to install composer packages is:

composer require aymardkouakou/cakephp-cors-middleware

Ensure that debug mode is activated:

// In config/app.php

...

'debug' => filter_var(env('DEBUG', true), FILTER_VALIDATE_BOOLEAN),

...

Quick Start

Adding the Middleware:

// In src/Application.php

$middlewareQueue

    ...
    
    ->add(CorsMiddleware::class)
    // OR 
    ->add(new CorsMiddleware())
    
    ...
    

By default the middleware authorize cors for all origins, all methods and all headers. No configuration required for work fine.

Custom configuration

For using custom configuration, you must adding a Cors array in your config/app.php file.

'Cors' => [

    // Authorized options here
    
    'AllowOrigin' => string|array,
    'AllowMethods' => array,
    'AllowHeaders' => array,
    'ExposeHeaders' => array,
    'AllowCredentials' => true|false,
    'Maxge' => int
    
]

Authorized options

Allow all domains

'AllowOrigin' => '*'
// Or
'AllowOrigin' => ['*']

Allow one domain only

'AllowOrigin' => 'localhost:4200'

Allow multiple domains

'AllowOrigin' => [
    'localhost:4200',
    ...
]

About

A CakePHP (3.7+) middleware for activate cors domain in your application.

Topics

Resources

Stars

Watchers

Forks

Packages

No packages published

Languages