2017 © Pedro Peláez
 

library cors-provider

cors provider for fastd application

image

fastd/cors-provider

cors provider for fastd application

  • Wednesday, May 23, 2018
  • by JanHuang
  • Repository
  • 1 Watchers
  • 4 Stars
  • 10 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 5 Versions
  • 233 % Grown

The README.md

FastD Cors Provider

Installation

composer require fastd/cors-provider

Usage

复制 vendor/fastd/cors-provider/config/cors.phpconfig/cors.php, 并修改配置, (*1)

<?php
return [
    'allow_credentials' => true,
    'origins' => ['*'],
    'methods' => ['GET', 'POST', 'HEAD', 'DELETE', 'PATCH', 'PUT'],
    'headers' => ['*'],
    'exposed_headers' => ['x-custom'],
    'max_age' => null,
];

配置 config/routes.php, (*2)

<?php
use FastD\CORSProvider\CorsMiddleware;
use \FastD\Routing\RouteCollection;

route()->middleware(new CorsMiddleware(), function (RouteCollection $router) {
    $router->get('/demo', function () {
        return json([
            'foo' => 'bar',
        ]);
    });
});

完成 !, (*3)

执行 curl -i 'http://127.0.0.1:8889/demo' -XGET, (*4)

响应:, (*5)

HTTP/1.1 200
Host: 127.0.0.1:8889
Date: Sat, 28 Apr 2018 17:08:47 +0800
Connection: close
X-Powered-By: PHP/7.2.4
Content-Type: application/json; charset=UTF-8

{"foo":"bar"}

执行 curl -i 'http://127.0.0.1:8889/demo' -XGET -H 'Origin: http://127.0.0.1:8889', (*6)

响应:, (*7)

HTTP/1.1 200
Host: 127.0.0.1:8889
Date: Sat, 28 Apr 2018 17:09:35 +0800
Connection: close
X-Powered-By: PHP/7.2.4
Content-Type: application/json; charset=UTF-8
Access-Control-Allow-Credentials: true
Access-Control-Allow-Origin: http://127.0.0.1:8889
Vary: Origin
Access-Control-Expose-Headers: x-custom

{"foo":"bar"}

执行 curl -i 'http://127.0.0.1:8889/demo' -XOPTIONS -H 'access-control-request-method: GET', (*8)

响应:, (*9)

HTTP/1.1 200
Host: 127.0.0.1:8889
Date: Sat, 28 Apr 2018 17:10:31 +0800
Connection: close
X-Powered-By: PHP/7.2.4
Access-Control-Allow-Methods: GET,POST,HEAD,DELETE,PATCH,PUT
Access-Control-Max-Age: 200
Content-type: text/html; charset=UTF-8

执行 curl -i 'http://127.0.0.1:8889/demo' -XOPTIONS -H 'access-control-request-method: GET' -H 'access-control-request-headers: hello', (*10)

响应:, (*11)

HTTP/1.1 200
Host: 127.0.0.1:8889
Date: Sat, 28 Apr 2018 17:11:27 +0800
Connection: close
X-Powered-By: PHP/7.2.4
Access-Control-Allow-Methods: GET,POST,HEAD,DELETE,PATCH,PUT
Access-Control-Allow-Headers: hello
Access-Control-Max-Age: 200
Content-type: text/html; charset=UTF-8

The Versions

23/05 2018

dev-master

9999999-dev

cors provider for fastd application

  Sources   Download

MIT

The Requires

 

The Development Requires

by Avatar JanHuang

cors fastd

23/05 2018

v1.0.1

1.0.1.0

  Sources   Download

The Requires

 

by Avatar JanHuang

28/04 2018

dev-develop

dev-develop

  Sources   Download

The Requires

 

by Avatar JanHuang

28/04 2018

v1.0.0

1.0.0.0

  Sources   Download

The Requires

 

by Avatar JanHuang

11/01 2018

v0.1.0

0.1.0.0

  Sources   Download

The Requires

  • php >=5.6

 

by Avatar JanHuang