The error Access to fetch at 'https://api.minaexplorer.com/accounts/B62qqCvKnFKM3jUbPL92fZseNYA2kVSaU694GJucFScJadnTXre3Exy' from origin 'http://localhost:3001' 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.
#having cors error while fetching from client side
35 messages · Page 1 of 1 (latest)
🔎 This post has been indexed in our web forum and will be seen by search engines so other users can find it outside Discord
🕵️ Your user profile is private by default and won't be visible to users outside Discord, if you want to be visible in the web forum you can add the "Public Profile" role in id:customize
✅ You can mark a message as the answer for your post with Right click -> Apps -> Mark Solution
(if you don't see the option, try refreshing Discord with Ctrl + R)
Yeah you need to have 'use server' on top not 'use client'. But the problem for you here would be that you are using some sort of a crypto wallet which from my experience require 'use client'. So either you make a new file with 'use server' and export a function from there into that file or I think you can also just add 'use server' inside a function in the same file by writing it right under the function declaration above where the function code would go
ya crypto wallet will require me to use client are you suggesting me to use routes ? like make a server compoenent and then try to paste the request code and from my client side request the data ?
No no just make a new file like request.tsx or something and write the request in a function in that file which you then import in the client component
And the function should just return the value
Like for example getAccountBalance.tsx
:ts 'use server' export const getAccountBalance = async(accounts) =>{ const apiUrl = `https://api.minaexplorer.com/accounts/${accounts}`; const response = await fetch(apiUrl, { method: 'GET', headers: { 'Content-Type': 'application/json', // Add any headers you need }, }); if(response.ok){ const data = await response.json(); return(data); } else{ console.log("Error"); } }
And then you just import it in the file you sent above like:
import getAccountBalance from getAccountBalance.tsx```
haa got it , let me try it out
Keep me posted
Sorry could not get back due to health reason's Getting this as an error
Yeah you either have to add the server component feature to the config or update next.js to v14
I can update
add it to the config
I am checking the docs it isn't mentioned any place
will go with adding the server component feature to the config
Probably because it isn't experimental in v14 anymore
yaa do you know what exactly I amsuppose ot add in the config
oh okay was this mentioned in the docs the link provided did not even mention this
It's probably not in the docs anymore because adding it to the config isn't required anymore in the new version
gotcha
I might have to see if I cna upgrade an existing next js project to 14
there is a high possiblity my wallet might have issue
If the console says that when you updated just ignore it
cool it works by the way thanks alot
No problem 👍
If You want to upload image without extra traffic, You do it from client side - so there still should be solution to make requests from client without CORS problem.