Whenever my application sends an ajax request to the server:
$.ajax({
url: config.api.url + '/1/register',
type: 'POST',
contentType: 'application/json',
data: /* some JSON data here */,
/* Success and error functions here*/
});
It sends the following two requests:
Request URL:https://api.example.com/1/register
Request Method:OPTIONS
Status Code:404 Not Found
Followed by the appropriate POST
with all of the data. Since I handle the routes as such:
expressApp.post('/1/register', UserController.register);
And do not have a .options
for this route, it always ends up in 404
. It's the same for nearly all methods. This question talks a little bit about it in the two answers below the accepted one, but I'm not quite sure what to make of it.
How can I handle this? Should I be adding .options
route and if so what should it do?