DEV Community

Discussion on: Handling sensitive client-side API keys in Next.js

Collapse
 
lyrod profile image
Lyrod

You do not need to use window.location.origin 😉

Collapse
 
codegino profile image
Carlo Gino Catapang • Edited

Yeah. thanks for pointing that out.

Content updated. Appreciate the feedback.

Collapse
 
lyrod profile image
Lyrod

However, if you do not add "/" at the begining, the browser will fetch for "currentPath/yourUrl". So if you host the page on /random-route, it will fetch /random-route/api/hello

You need this /

Thread Thread
 
codegino profile image
Carlo Gino Catapang

Not sure what you mean by that. But it's working for me even if I start it with api or /api.

Thread Thread
 
lyrod profile image
Lyrod

Because you're fetching from index.js right?

Thread Thread
 
codegino profile image
Carlo Gino Catapang

Yep. Will update code to be resilient to change. Thanks.