CORS issue

Hello,
i’m trying to call a n8n endpoint with a webhook and a respond to webhook.
Calling from a curl command, i got a result as expected, however calling the same endpoint from a javascript code i got a error related with cors

from origin 'null' has been blocked by CORS policy: Response to preflight request doesn't pass access control check: The value of the 'Access-Control-Allow-Credentials' header in the response is '' which must be 'true' when the request's credentials mode is 'include'.

The code used to call the n8n endpoint:

    fetch(url, {
    method: 'POST',
    credentials: 'include',
    headers: {
      'Accept': 'application/json',
      'Content-Type': 'application/json', 
      'Authorization': "Basic " + btoa(`${username}:${password}`),
      'Access-Control-Allow-Credentials': true, 
    },
    body: JSON.stringify({username:"[email protected]"})
    })
    .then(resp => {
      console.log('........',resp)
    })
   .then(function(response) {
      console.info('fetch()', response);
      return response;
   }).catch(error => {alert("error", error)});;

Can you advice?
Thanks

Hi @mxp, handling CORS is a bit tricky, mostly because you’d have to handle this outside of n8n. In case you are using nginx, @roemhildtg has published a working reverse proxy setup here (make sure to also vote on the feature request, so we’ll hopefully see this feature directly in n8n at some point).

Hey @MutedJam ,
thank you for your reply. I’m trying to run a javascript which calls a n8n endpoint. For the moment i’m running locally, but he goal is to integrate this javascript at jotform. Has i mentioned, if i run curl, it works, but not inside javascript. Saying that, i don’t have a nginx running. Any clue?

Many thanks

Hi @mxp, CORS is a technology used by web browsers (who would also be the applications blocking such requests), not by applications such as curl, Postman, or server-side applications. This is why you will only see this failing when using Javascript code on a website, but not if you were to execute the same code through Node.js for example.

Saying that, i don’t have a nginx running. Any clue?

Can you confirm how exactly you are running n8n? Do you have any reverse proxy server in use? It seems you have removed the respective section from the forum template, so my hint towards nginx was just a guess :slight_smile:

@MutedJam ,
thank you for the explanations! I’m running n8n cloud version Pro, so i can’t manage the web server.

Many thanks

Hi @mxp, I am afraid n8n cloud does not offer an option to individually configure the reverse proxy server in use :frowning:

Are you perhaps able to handle the this on the server side of things? If so, you could use the Jotform trigger to run your workflow then a form is submitted.

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.