Today I faced with an issue where any solution found in interned could not handle it.
I am trying to create a blog app using amazing Notion.so note-taking app. Of course, for this stuff I need their API.
Before implementing in React code I tested everything in Insomnia (postman like app). Everything worked smoothly.
When I started to implement first request in react-redux
... boom everything is ruined.
This is where request is made:
export const notionApi = createApi({
reducerPath: "notionApi",
baseQuery: fetchBaseQuery({
baseUrl: "https://api.notion.com/v1",
prepareHeaders: headers => {
headers.set("Authorization", process.env.REACT_APP_NOTION_SECRET);
headers.set("Notion-Version", " 2022-02-22");
return headers;
}
}),
endpoints: builder => ({
getMenu: builder.query({
query: id => `/blocks/${id}/children`
})
})
});
export const { useGetMenuQuery } = notionApi;
This is in browser:
Access to fetch at 'https://api.notion.com/v1/blocks/c5886e5e15d04d4bb8112bafcec8475b/children' from
origin 'http://localhost:3000' has been blocked by CORS policy: Response to preflight
request doesn't pass access control check: No 'Access-Control-Allow-Origin' header is
present on the requested resource. If an opaque response serves your needs, set the
request's mode to 'no-cors' to fetch the resource with CORS disabled.
Believe or not, I tried everything: Cors Chrome App to imitate, CRA proxy to in package.json, express sever to imitate proxy and 5 hours of desperate search.