0

I've been searching and trying different things for over an hour. I've found many articles that are basically what's happening to me, but nothing I'm finding/trying is fixing the 404. Angular is converting my $http.post to method OPTIONS. This is causing my node/express route to fail because there is no OPTIONS route. It's a POST route. So I get a 404. The middleware runs fine of course, but the app.post route cannot be hit and cannot figure out how to force the method to be POST.

This is what I see in Chrome console "Console" tab...

enter image description here

This is what I see in Chrome console "Network" tab...

enter image description here

This is my AngularJS Service code...

enter image description here

This is my Node/Express routes middleware code...

enter image description here

This is my Node/Express POST route will not run because method is wrong!!!...

enter image description here

I've tried soooo many different things in the client and server code and setting headers in the client and server and I cannot make this work.

Can someone please sort me out? :-/

EDIT:

I found it myself, finally. My issue had absolutely nothing to do with the "duplicate" article. It looked like the same issue, but it absolutely was not the same. My screen shots above DO show the issue. It is visible and I'll accept the answer from whomever sees it...

Locohost
  • 1,517
  • 3
  • 20
  • 36
  • 2
    From your screenshot, you're trying to access localhost:8098 from localhost:8398. Take a look at http://stackoverflow.com/questions/12111936/angularjs-performs-an-options-http-request-for-a-cross-origin-resource for more information on the OPTIONS http request. – Matt DeKrey Apr 17 '15 at 01:47
  • 8398 is the node/express website app. 8098 is a node/express server REST api. I have the server header set to allow origin 8398. I have all the other headers I've found while searching, set. What is missing? – Locohost Apr 17 '15 at 01:59
  • Where in the article that you say is a duplicate do I see the answer to my 404 issue? What line in that article solves my problem because I do not see the line that provides my answer. – Locohost Apr 17 '15 at 02:19
  • I found it myself, finally. My issue had *absolutely nothing to do with the "duplicate" article.* It looked like the same issue, but it absolutely was not the same. My screen shots above DO show the issue. It is visible and I'll accept the answer from whomever sees it... – Locohost Apr 17 '15 at 02:40
  • 2
    If you found out the answer then you should post it. SO is a community resource for people such as yourself to use. Imagine if you had this problem and found this post written by someone else saying exactly what you say above. "It is visible and I'll accept the answer from whomever sees it...". You would more than likely curse the OP. – Scott Sword Apr 17 '15 at 03:49
  • @Swordfish0321: I was quite pissed when I went to bed last night. You're absolutely correct, I'll post the answer when I get a chance later this eve or tomorrow eve. Sorry about some of above :-/ – Locohost Apr 17 '15 at 13:04
  • 1
    Actually I have enough time right now: The answer is actually very painful and simple. Those are the kinds of issues that cause the most pain :-( Look at the route string "api/:authToken/post-article" in the last screen shot. Now notice there is a missing "/" at the front of it? That was source of my hours of misery last night. When I put the "/" where it belongs, all these imaginary CORS monsters suddenly disappeared. – Locohost Apr 17 '15 at 13:07

1 Answers1

0

Have your tried to add on your POST the following parameter:

"headers": { "Content-Type": "application/x-www-form-urlencoded" }

Moreover, there are some "specificities" on AngularJS, I always test on regular Javascript to be sure that this may not be linked to angular.

I have ended up using this great and simple Chrome Estention : POSTMAN

floribon
  • 18,567
  • 4
  • 50
  • 66
aorfevre
  • 4,854
  • 3
  • 19
  • 50
  • Changing my headers set in the client side service to your suggestion does cause the request to show as POST in the network tab, however still same 404 error. So my thought about OPTIONS request killing it is wrong. It's something else. – Locohost Apr 17 '15 at 02:00