I’m trying to make a request on my ionic app to my server. I enabled cors on the server. When on ionic serve --lab: I make my request, it doesn’t work. The GET requests work, but the POST does not.
register(username: string, email: string, password: string) {
var header = new Headers();
header.append("Accept", "application/json");
header.append("Content-Type", "application/json" );
let options = new RequestOptions({ headers: header });
var body = {
name: username,
email: email,
password: password
};
var senderBody = JSON.stringify(body);
console.log(body, senderBody)
return new Promise((resolve, reject) => {
this.http.post("http://54.233.195.52:8080/user_parent", senderBody, options)
.map(res => res.json())
.subscribe(data => {
resolve(data)
}, error => {
console.log(error)
reject(error)
});
});
}
And i have cors on my server…
func SetDBtoContext(db *gorm.DB) gin.HandlerFunc {
return func(c *gin.Context) {
c.Writer.Header().Set("Access-Control-Allow-Origin", "*")
c.Writer.Header().Set("Access-Control-Allow-Headers", "Accept, Content-Type, Content-Length, Accept-Encoding, X-CSRF-Token, Authorization, Origin")
c.Writer.Header().Set("Access-Control-Allow-Methods", "POST, GET, OPTIONS, PUT, DELETE")
c.Set("DB", db)
c.Next()
}
}
And these are the console.log answers:
OPTIONS http://54.233.195.52:8080/user_parent 404 (Not Found)
Failed to load http://54.233.195.52:8080/user_parent: Response for preflight has invalid HTTP status code 404
Am I missing something?