Record the experience of a front-end call to the back-end interface and return 404

Record the experience of a front-end call to the back-end interface and return 404

Problem Description

The interface is newly developed and has not been online, so I brought the branch of the back-end project
in the test environment. When the test environment called the back-end interface, I found a 404 error, as shown in the figure:

Thought process

  • First of all, the first reaction is that the url is wrong, such as the wrong word, "/", etc., but it is not wrong to go to the interface document and copy it again.
  • Then I suspected that there was no back-end interface resource. I opened the interface directly in the browser and found that the GET request was available. And after inquiry, the interface has been verified by ios and Android to be feasible. I made a request with postman myself and found that it can be done (no parameters are filled in, but there are back-end resources).

  • Then I suspected that the POST in the browser was proxied to another environment. Turn off Charles and switchyOmega, and check whether the project I am responsible for is proxied by middleware, but Goose is not. This is interesting, and I suddenly felt that I might learn something from this question.
  • Look carefully at the return value of 404 like this:

Openresty is a high-performance web platform based on Nginx and Lua, which means that this 404 is returned by Nginx, so I asked the back-end students to check the Nginx logs and compare the difference between normal post interface requests and this. It turns out that there is no difference. After further exploration by the back-end classmates, I found that the request was proxied by two layers of Nginx. In the end, the origin of the request was changed from the test domain name to the online domain name? ? ? That is to say, the interface of the front-end self-adjusting the domain name is actually cross-domain, and it is directly blocked by Nginx, and there is no cross-domain error message. The get request does not have an origin, so it is normal, and the post has an origin, so an error occurred. Other normal interfaces are because the back-end has been specifically configured. This new interface is not equipped, so let the back-end change it decisively. This kind of pit left over from history is really hard to guard against...


404 is not necessarily a pure front-end problem. When there is no possibility of error on the front-end, look at the category other than the front-end, and there may be new answers.