Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to setup CORS in yii3 ? #110

Open
ayiangio opened this issue Jul 1, 2020 · 5 comments
Open

How to setup CORS in yii3 ? #110

ayiangio opened this issue Jul 1, 2020 · 5 comments
Labels
type:docs Documentation

Comments

@ayiangio
Copy link

ayiangio commented Jul 1, 2020

What steps will reproduce the problem?

i have done to setup on web server in this case i use apache2

What is the expected result?

my API can run on another domain

Additional info

Q A
Version 1.0.?
PHP version 7.4.7
Operating system Ubuntu 18.04
@yiiliveext
Copy link
Contributor

yiiliveext commented Jul 1, 2020

We don't yet have our own CORS middleware implementation, but you can use any psr-7/psr-15 compatible middleware.
For example https://github.com/tuupola/cors-middleware

Route::get('/info/v2', ApiInfo::class)
    ->addMiddleware(FormatDataResponseAsJson::class)
    ->addMiddleware(fn() => new Tuupola\Middleware\CorsMiddleware([
        "origin" => ["*"],
        "methods" => ["GET", "POST", "PUT", "PATCH", "DELETE"],
        "headers.allow" => [],
        "headers.expose" => [],
        "credentials" => false,
        "cache" => 0,
   ]))
   ->name('api/info/v2'),

@samdark samdark closed this as completed Jul 1, 2020
@ayiangio
Copy link
Author

ayiangio commented Jul 6, 2020

image
image

@samdark @yiiliveext
the code you have given doesn't work in my case

@samdark
Copy link
Member

samdark commented Jul 6, 2020

@ayiangio what are headers that are sent?

@ayiangio
Copy link
Author

ayiangio commented Jul 8, 2020

We want to send two headers

  1. Authorization for token
  2. Role user

@samdark

@samdark samdark reopened this Jul 8, 2020
@samdark
Copy link
Member

samdark commented Jul 8, 2020

OK but what headers are actually sent after you configure CSRF middleware and make a request?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type:docs Documentation
Projects
None yet
Development

No branches or pull requests

3 participants