Cors [Mar 06]

:raising_hand_man: Marinara Liberator asked

Hi guys! New coder here - I’m dealing with a CORs issue when trying to query something to my local Nocodb/graphql - I am not sure if it is possible or what I’m missing theory wise or coding wise. If I were to use insomnia it can query, and I’m sure I’ve added xc-auth within my headers in my localhost querying. Thanks for any advice or help!

:person_tipping_hand: o1lab replied

And project was created via npx or docker

:raising_hand_man: Marinara Liberator replied

Hi!

:raising_hand_man: Marinara Liberator replied

It was created through npm

:person_tipping_hand: o1lab replied

Pls paste project info from right top menu

:raising_hand_man: Marinara Liberator replied

Sorry im not sure if npm vs npx

:person_tipping_hand: o1lab replied

Ya that’s fine

:person_tipping_hand: o1lab replied

If it’s working with insomnia

:person_tipping_hand: o1lab replied

Could you figure out an option is missing of sorts from your client like axios or fetch

:raising_hand_man: Marinara Liberator replied

Node: v14.18.3

Arch: x64

Platform: win32

Docker: false

Database: pg

ProjectOnRootDB: true

RootDB: pg

PackageVersion: 0.84.14

:raising_hand_man: Marinara Liberator replied

Hi Navi! I’m Roderic working under Handoyo

:raising_hand_man: Marinara Liberator replied

I’m not quite sure but I have this for my piece of code:

```function post(url, body) {

const requestOptions = {

method: ‘POST’,

origin: ‘http://localhost:3000’,

headers: { ‘Content-Type’: ‘application/json’,

‘xc-auth’: [Authenfication Token]

},

credentials: ‘include’,

// origin: ‘*’, //try

// mode: ‘cors’, //could remove

body: JSON.stringify(body)

};

try{

return fetch(url, requestOptions).then(handleResponse);

// return fetch(url).then(handleResponse);

}

catch(error){

console.log("Error: " + error);

}

}```

:raising_hand_man: Marinara Liberator replied

Hi Navi! Handoyo added this into index.js:

``` app.use(cors({

origin: ‘*’,

methods: “GET,HEAD,PUT,PATCH,POST,DELETE”,

preflightContinue: false,

optionsSuccessStatus: 204

}));

```

along with installing cors - and It works!

Autogenerated from discord


Join NocoDB’s community

DiscordTwitterRedditDocs