0

I'm trying to debug an Angular 6 application and run locally using ng serve --proxy-config proxy.conf.json. My proxy.conf.json file is as follows: (target is obfuscated for security reasons)

{
  "/**": {
    "target": "http://my-main-application.com",
    "secure": false,
    "logLevel": "debug",
    "changeOrigin": true
  }
}

This works for most GET requests but fails for POSTs (see screenshot below). search post fail

Is there something additional I need to do to allow the POSTs to get through successfully?

vinays84
  • 394
  • 4
  • 14

1 Answers1

0

403 is a client side issue, meaning your API gets the call it just refuses to execute it. if your GETs pass, this might be the issue.

CLI CORS Proxy not changing origin, still get 403 on API reqs?

Yoshy
  • 170
  • 2
  • 14
  • I saw that other post, but my issue doesn't show OPTIONS. You are correct that the requests never get to the server. Their response is "Invalid CORs Request" - but I'm not sure why this doesn't occur for GETs then. – vinays84 Feb 03 '20 at 18:49
  • A GET doesn't have a content type. If it's a CORS problem a simple way to check if it's only CORS acting up, is trying to send data without any proxy, if the request passes as expected, something else is amiss; if it doesn't, consider checking your data formation and the CORS content type headers. – Yoshy Feb 03 '20 at 18:54
  • Set These two header request.'Access-Control-Allow-Methods', 'POST, GET, PUT, DELETE, OPTIONS' "Access-Control-Allow-Headers", "Origin, X-Requested-With, Content-Type, Accept, ContentType, contenttype, content-type, Cache-Control, Pragma" – Yoshy Feb 03 '20 at 18:55
  • I tried setting the headers you suggested to no avail. Also, my understanding is that using the proxy conf avoided CORS issues? – vinays84 Feb 04 '20 at 15:30
  • Avoided issues yes, but these issues are a bit in a different nature, read this article for more information: https://levelup.gitconnected.com/overview-of-proxy-server-and-how-we-use-them-in-react-bf67c062b929 – Yoshy Feb 15 '20 at 13:36