Skip to content
Advertisement

CORS Policy blocking my API requests in a google cloud platform app engine in a live website

I uploaded my node js server to the google cloud app engine service to be able to make the front end work. I also uploaded the frontend and my website is now live.

The node js is running fine and it’s deployed in the app engine in google cloud.

my only problem is that whenever I try to make a request I get blocked by the cors policy which I looked everywhere for a solution but could not find any.

here is what the error looks like exactly in my console:

JavaScript

What am I supposed to do to get rid of this error?

Here is what I am doing

index.js from my node js server

JavaScript

And in the frontend i am requesting like this:

JavaScript

Any help, please?

EDIT:

tried Simit answer it does not work aswell.

Advertisement

Answer

Try this middleware on top of your routes…

JavaScript

Hope this works for you…

User contributions licensed under: CC BY-SA
9 People found this is helpful
Advertisement