Rest Api Error in Next-js
-
While using Word-press Rest API in Next-Js getServerSideProps it is working file , but when i try to use standard useEffect fetch api , method it is giving me CORS Error, in Production . Any thing i can do to prevent this ?
And the same thing i have tested in ReactJs and it is giving me same CORS error in production, but in Development it is working fine .
The blog I need help with is: (visible only to logged in users)
-
Hi there,
I’m not familiar with the tool you’re using, but their support would likely be able to offer better help.
That said, Is
example716321636.wordpress.comthe website you’re trying to use?
If yes, it’s currently unpublished, so I don’t imagine things will be able to access it.If you have another site, is it hosted elsewhere?
-
I am using another WordPress website this added by mistake.
So the problem is , the rest api seems to work on server side app, with no problems, but when I call it on client side it is showing me cors error -
And in my case I have to use the client side fetch .. so is their any fix of the cors error, which I can do
-
What is the other website?
If it’s not hosted with WordPress.com, you’ll be better off posting in the WordPress.org forum.
https://wordpress.org/support/forums/
CORS is a security mechanism that can’t be bypassed, but depending on the level of control you have on the server, you can configure it to allow the requests.
I think, either way, you’re probably best asking for help from the Next.js folks.
Cheers,
Eric -
If the site is hosted with WordPress.com, I suggest checking out our developer resources: https://developer.wordpress.com/
And depending what you’re trying to do, this plugin might be helpful: https://wordpress.org/plugins/wp-cors/
- The topic ‘Rest Api Error in Next-js’ is closed to new replies.