demo
demo copied to clipboard
How to setup CORS in yii3 ?
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 |
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 @yiiliveext the code you have given doesn't work in my case
@ayiangio what are headers that are sent?
We want to send two headers
- Authorization for token
- Role user
@samdark
OK but what headers are actually sent after you configure CSRF middleware and make a request?