Koa2 cross-domain cookie cannot be written to the browser

problem description

Local front-end separation project
front-end address localhost:2018
back-end address localhost:3020 framework koa2
when the current end accesses an interface at the backend, the cookie cannot be written to the browser

the environmental background of the problems and what methods you have tried

related codes

/ / Please paste the code text below (do not replace the code with pictures)

//: 
//login set cookie
router.post("/login",async(ctx)=>{
    ctx.cookies.set("userid",1111,{
        domain:"http://localhost:2018",
        path:"/"
    });
    ctx.body={
        code:200,
        message:"get it"
    }
 })
 // koa2-cors
 app.use(cors({
    origin:"http://localhost:2018",
    credentials:true,
    exposeHeaders: ["WWW-Authenticate", "Server-Authorization"],
    allowMethods: ["GET", "PUT", "POST", "PATCH", "DELETE", "HEAD", "OPTIONS"],
    allowHeaders: ["Content-Type", "Authorization", "Accept"],
 }));

what result do you expect? What is the error message actually seen?

you can see that there is already cookie in the response header

clipboard.png

clipboard.png


if you post the back-end node.js code and say it's a front-end problem, is it a front-end problem or a back-end problem?

Menu