POST request processed as OPTIONS based on beego framework

I am using the beego framework as my API and AngularJS framework on the client. I configured all CORS settings correctly. I can make a GET request. But, when I try to execute POST, beego treat is an OPTIONS request. He also throws a warning: multiple response.WriteHeader calls. what could be wrong?

My CORS setup for beego:

func init() {
    orm.RegisterDataBase("default", "mysql", "root:@tcp(127.0.0.1:3306)/fakeapi")
    beego.InsertFilter("*", beego.BeforeRouter, cors.Allow(&cors.Options{
        AllowOrigins:     []string{"*"},
        AllowMethods:     []string{"GET", "DELETE", "PUT", "PATCH", "POST"},
        AllowHeaders:     []string{"Origin"},
        ExposeHeaders:    []string{"Content-Length"},
        AllowCredentials: true,
    }))

}

My request is ANGularJS

var transaction = $http.post(BASE_URL + "transaction", transactionData);
                return $q.all([transaction]).then(function(response) {
            console.log(response);
        });

my system: Ubuntu 14.04 beego: 1.4.2 bee: 1.2.4 angularJS: 1.3.12

+4
source share
2 answers

This may be due to a problem / push request, which is currently expected to merge with master: issue 912

: router.go#L861

commit 3bb4d6f, :

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

( router.go , , )

Commit f962457 , .


904 - , Session Engine. , Session.on .

+2

, ,

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()
}
0

All Articles