How to solve CORS policy problem for Strapi?

You are not sure about documentation? :sweat_smile:

./config/middleware.js

Thank for you replied. i already found the right path for this middleware.js file.

In the past, I’d to know the path of the folder for the middleware.js.
In the docs, it show ./config/middleware.js. I wondering is it
/app/config/middleware.js or
/app/middlewares/config/middleware.js

This is the correct path, our documentation may not make this very clear. Most of the pathing terminology comes from Linux/Mac where ./ means the current folder, and it’s implied that the “current folder” is the root of the Strapi application.

Thank for your time to replied. =)

In my case, I was missing to add the protocol, after adding http:// the cors error stopped.

For me, some extension was causing the issue which I’m not sure which one but using incognito window fixed it.

Hello people,
Hope this helps someone like me.

Summary
In my frontend apollo-client I have given the uri without ‘http://’

Front-end
Framework: Angular
Graphql client: apollo-client
File path: app > graphql.module.ts
To do: Check if the value of constant uri correct. If it is localhost, give ‘http://localhost:1337’(replace the port number with yours)

Hello.
I need to create config/middelware.js

Is necessary to say to strapi to use this middelware somewhere in settings or this is an automatic process?.

Postman dosen’t show Access-Control-Allow-Origin:*

It is ok? how can I check is working propely.

Oh wow! This is really handy. I can’t believe I didn’t find about this in the 3 months I’ve been using strapi. :sweat_smile:

There is a very small reference to it on our documentation but it is extremely handy for learning how the internal API functions.

1 Like

Postman is doing a “server-side” request, this is why it doesn’t contain origin in headers and it doesn’t make a pre-flight request that verifies origin.

I am having a similar issue and would like to see the what is running in my middleware.js, but if I use the strapi.middleware command I get the output [Function: middleware] .

it’s strapi.config.middlewares not strapi.middleware