POST request treated as OPTIONS on beego framework

◇◆丶佛笑我妖孽 提交于 2019-12-05 18:01:34

That might because of an issue/pull request currently pending to be merged into master: issue 912

Without this line everything is fine:: router.go#L861

That seems to be in line with commit 3bb4d6f which shows:

// Write status code if it has been set manually
// Set it to 0 afterwards to prevent "multiple response.WriteHeader calls"

(and router.go do set a status, hence the error message)

Commit f962457 is supposed to solve this issue, but isn't merged yet.


The other issue 904 mentions something about being unable to retrieve the Session data previously registered in the Session Engine. Maybe Session.on flag can help.

I handle it like that, I hope it helps

import (
_ "info_apoyo/routers"

"github.com/astaxie/beego"
"github.com/astaxie/beego/plugins/cors"
)

func main() {
if beego.BConfig.RunMode == "dev" {
    beego.BConfig.WebConfig.DirectoryIndex = true
    beego.BConfig.WebConfig.StaticDir["/swagger"] = "swagger"
}
beego.InsertFilter("*", beego.BeforeRouter, cors.Allow(&cors.Options{
    AllowOrigins:     []string{"*"},
    AllowMethods:     []string{"GET", "POST", "DELETE", "PUT", "PATCH"},
    AllowHeaders:     []string{"Origin", "content-type", "Access-Control-
Allow-Origin"},
    ExposeHeaders:    []string{"Content-Length", "Access-Control-Allow-
Origin"},
    AllowCredentials: true,
}))
beego.Run()
}
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!