I need some help, I deployed my project using the google search json API. On my local enviroment...
Unanswered
Hamiltonstövare posted this in #help-forum
HamiltonstövareOP
works perfectly, but when I try to search on my deploy, d data wont reach, and web throws an error. Did anyone have this problem also? Should I add something to make it work on the deploy? Thanks!
7 Replies
you mean, this endpoint?
most probably, the env variables are missing. encompass try/catch to see how it runs.
const googleRes = await fetch(
`https://customsearch.googleapis.com/customsearch/v1?key=${
googleAPIKey ? googleAPIKey : process.env.GOOGLE_API_KEY
}&cx=${
googleCSEId ? googleCSEId : process.env.GOOGLE_CSE_ID
}&q=${query}&num=5`,
);
const googleData = await googleRes.json();most probably, the env variables are missing. encompass try/catch to see how it runs.
@tafutada777 you mean, this endpoint?
typescript
const googleRes = await fetch(
`https://customsearch.googleapis.com/customsearch/v1?key=${
googleAPIKey ? googleAPIKey : process.env.GOOGLE_API_KEY
}&cx=${
googleCSEId ? googleCSEId : process.env.GOOGLE_CSE_ID
}&q=${query}&num=5`,
);
const googleData = await googleRes.json();
most probably, the env variables are missing. encompass try/catch to see how it runs.
HamiltonstövareOP
Oh, wydm by googleApiKey? is it that you have another api key for your deploy? like the one that is on .env.local wont work?
may i see both error message and codes?
plus, do you use Vercel or self hosted Docker?
plus, do you use Vercel or self hosted Docker?
HamiltonstövareOP
I sent you a friend request so maybe you can help me fix it.
but I have this error, and basically means that when Im trying to fetch the data. My code breaks. I ´ve searched why it was and it its because when its returning on client component, the data wont fetch from API. On localhost it works perfectly
most probably you involved the Google search API from client components. it has to execute from server side such as API or server components otherwise API KEYs are exposed and any one can invoke your api for free.
thus Next.js protects you from exposing api keys accidentally to client side codes unless env variables start with NEXT_PUBLIC