intrumentation.ts env loading
Unanswered
LaPerm posted this in #help-forum
LaPermOP
i wanted to load my env vars from 3rd party api fetch using the new
i saw also
instrumentation.ts
file and it works awesome on server side but on client side they are not set even when they start with NEXT_PUBLIC_
any ideas how to solve that?i saw also
instrumentation-client.ts
but is it secure to call an api with api token retrieving the env vars in here, wont it be exposed to the site users?3 Replies
LaPermOP
okay so tested a bit and when i use
fetch
in instrumentation-client.ts
this request is made on client side, hence api key is exposed to a user. So how could i load client side env variables from external api? I assume they are needed at build time already?Burmese
are these config items static and ok to bundle into your build? or do you want them to be able to be changed? If so, youd need to fetch them server side, and wire up your frontend to fetch them from your backend - rather than the external api directly
also, I dont think instrumentation gets called when doing prerendering of static routes, so it may work if nothing is pre-rendered, but probably not worth it