Preflight OPTIONS request returns status 405

482 views Asked by At

I am currently developing a dashboard which consumes the Mention API. However, I am having difficulties due to the CORS policy.

If the dashboard is opened on Chrome or another browser that has a strict CORS policy, they make a preflight OPTIONS request each time, but these appear to not be supported by the Mention API.

Therefore, every time I do something like:

this.mentionAPI = axios.create({
  baseURL: 'https://web.mention.net/api/accounts/my-account-id',
  headers: {
    'Authorization': 'Bearer my-access-token',
  }
});

this.mentionAPI.get('/alerts')
  .then((response) => {
    console.log(response);
  })
  .catch((response) => {
    console.log(response);
  });

I get a response with the status 405 Method Not Allowed. This suggests that the OPTIONS requests are not handled by the Mention API at all.

Naturally, in my case I can just make sure that the browser is configured to not perform preflight requests. After all, my use case prescribes just one client, which I control completely. Alternatively, I could build a server-side service to make the requests on my behalf, however it seems like hunting a fly with cannon, since client side JavaScript is more than capable to perform everything else.

Any help on this issue would be really appreciated. Perhaps I'm misunderstanding how the API is intended to be consumed?

0

There are 0 answers