i wanted to get my env variable that has an api key from a netlify function to hide it from the client , i have coded the function i have tested it by running **netlify dev** to see what i get in the console sadly i am getting an error in the console here is my function
``import type { Handler, HandlerEvent, HandlerContext } from “@netlify/functions”;
While we can try to help you fix this, I don’t think this is doing what you think it’s doing. Your key will still be exposed to the client this way. You should instead use the API key to make an API request from the function itself and return the response to the client.
well i want to return it to be able to use it in firebase config object which needs to be passed to a initilizeApp function
``export const firebaseConfig = {
apiKey: xxxxxxxx, // i wanna pass it here
authDomain: “xxxx”,
databaseURL: process.env.REACT_FIREBASE_DATABASEURL,
projectId: “e-commerce-cbe7c”,
storageBucket: “xxxxxx”,
messagingSenderId: “xxxxxx”,
appId:xxxxxxx,
measurementId: “xxxxxx”
tsx is not a valid extension for Functions. js or ts only.
But as I mentioned, you’re approaching this problem incorrectly. You can continue to pursue this path, but you’re not making your app any secure or hiding the key this way.
Check the network tab for the complete response. This isn’t a Netlify problem at this point, but a problem with your code. You’re trying to parse the response as a JSON, when it’s not a JSON. Your terminal would also have some info.
why are some things not mentioned in the docs for example i had to figure that i need to call this handler function by having it inside of a url then calling that url because it’s a serveless function if that’s correct however there was no mentions in the docs that u have to do that , i had to look up some tutorials to figure that out
I’m not sure what you mean. As far as the docs are concerned, this section explains that: Create functions | Netlify Docs. Quoting:
These formats would deploy a synchronous function that can be called on the following endpoint, relative to the base URL of your site: /.netlify/functions/hello .