2

I'm trying to get my Angular 2 application running and everything is going relatively smoothly until I hit the API for some data.

Apache is responding with a 301 redirect when Angular's http module does that OPTIONS request, see headers:

Request:

OPTIONS http://api.mydomain.com/register/

Host: api.mydomain.com
User-Agent: Mozilla/5.0 (Windows NT 10.0; WOW64; rv:46.0) Gecko/20100101 Firefox/46.0
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8
Accept-Language: en-US,en;q=0.5
Accept-Encoding: gzip, deflate
Access-Control-Request-Method: POST
Access-Control-Request-Headers: content-type
Origin: http://app.mydomain.com
Connection: keep-alive
Pragma: no-cache
Cache-Control: no-cache

Response:

Connection: Keep-Alive
Content-Length: 341
Content-Type: text/html; charset=iso-8859-1
Date: Wed, 18 May 2016 18:35:02 GMT
Keep-Alive: timeout=5, max=100
Location: http://api.mydomain.com/register
Server: Apache/2.4.7 (Ubuntu)

Honestly I'm new to Angular and CORS so I'm hoping I just made a nooby mistake. Thanks for your help!

The Maniac
  • 121
  • 3
  • 1
    Don't assume anyone here knows Angular; we probably don't. As for your request, clearly you're being redirected to a different URL. You should probably look into why you're requesting OPTIONS for the wrong URL (or being redirected to the wrong URL, as the case may be). – Michael Hampton May 18 '16 at 18:46
  • Its not the wrong URL, I can access it just fine without using CORS. There is no redirect. The reason I asked the question here is because this is not an Angular issue, its an issue with my Apache server and CORS. – The Maniac May 18 '16 at 18:50
  • 2
    What do you mean? Which one isn't the wrong URL? And why do you say there's no redirect when you _posted a copy of the redirect_? – Michael Hampton May 18 '16 at 18:52
  • 1
    Wow, maybe I'm being a complete idiot. I manually edited the request and removed the trailing slash and didn't get the 301 -- maybe it was the wrong URL! Argh. Thanks for pointing me in the right direction. – The Maniac May 18 '16 at 18:56

0 Answers0