Beego allows cross-domain request issues

scenario :

ABeegoBUI
BA

A

in the main.go file, add the following

clipboard.png


clipboard.png


clipboard.png

my question
obviously, the problem is that when a cross-domain request is made, the pre-check request fails, , but the A backend prompts OPTIONS no match, but the return value is still 200. Why? And how to solve the problem of OPTIONS failure?

Mar.09,2021

I also encountered this problem. The following configuration, using websocket request, prompts websocket: 'Origin' header value not allowed, to seek the same solution

beego.InsertFilter("*", beego.BeforeRouter, cors.Allow(&cors.Options{
        AllowAllOrigins:  true,
        AllowMethods:     []string{"GET", "POST", "PUT", "DELETE", "OPTIONS"},
        AllowHeaders:     []string{"Origin", "Authorization", "Access-Control-Allow-Origin", "Access-Control-Allow-Headers", "Content-Type"},
        ExposeHeaders:    []string{"Content-Length", "Access-Control-Allow-Origin", "Access-Control-Allow-Headers", "Content-Type"},
        AllowCredentials: true,
    }))

Access-Control-Allow-Origin can add this response header. When
Option requests for the first time, it is found that this header exists, and the setting of this header allows your domain name to return 2000.Then the client initiates a real request again


server with a response header, or reverse proxy.


although I haven't used beego, I can answer it forcefully. After setting the allowed header, you need to finish the request and respond to the request immediately when the middleware matches the request of method = OPTIONS.

it is also recommended to add Access-Control-Max-Age header to reduce the number of requests for front-end preflight

MySQL Query : SELECT * FROM `codeshelper`.`v9_news` WHERE status=99 AND catid='6' ORDER BY rand() LIMIT 5
MySQL Error : Disk full (/tmp/#sql-temptable-64f5-1e9be13-1890.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
MySQL Errno : 1021
Message : Disk full (/tmp/#sql-temptable-64f5-1e9be13-1890.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
Need Help?