GithubHelp home page GithubHelp logo

How to setup CORS in yii3 ? about demo HOT 5 OPEN

yiisoft avatar yiisoft commented on August 20, 2024 1
How to setup CORS in yii3 ?

from demo.

Comments (5)

yiiliveext avatar yiiliveext commented on August 20, 2024 1

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'),

from demo.

ayiangio avatar ayiangio commented on August 20, 2024

image
image

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

from demo.

samdark avatar samdark commented on August 20, 2024

@ayiangio what are headers that are sent?

from demo.

ayiangio avatar ayiangio commented on August 20, 2024

We want to send two headers

  1. Authorization for token
  2. Role user

@samdark

from demo.

samdark avatar samdark commented on August 20, 2024

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

from demo.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.