-
Notifications
You must be signed in to change notification settings - Fork 281
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Environment Variables in Hydrogen Development #714
Comments
@braginteractive The env variables can be found on the context object which is accessible in remix loaders and actions. const handleRequest = createRequestHandler({
build: remixBuild,
mode: process.env.NODE_ENV,
getLoadContext: () => ({session, storefront, env}),
});
const response = await handleRequest(request); |
@jordan-diffagency thanks for this! What about outside of loaders/actions though? For example, an api.js file with all the fetch requests: export async function getCustomers() {
const res = await fetch(
process.env.API_URL +
"/customers/";
{
headers,
}
);
const customer = await res.json();
return customer;
} Then in then customers route, the loader would be something like: import { getCustomers } from "~/lib/api";
export const loader = async ({ request }) => {
const customer = await getCustomers()
return json({ customer });
}; I guess I could pass the env as a parameter, but it would be nice if I just had access to the environmental variables in the api.js file. No? |
I have been resorting to passing the context as a param though I agree that it would be nice to have access to the env variables directly. |
What is the location of your example repository?
No response
Which package or tool is having this issue?
Hydrogen
What version of that package or tool are you using?
2023.1.5
What version of Remix are you using?
1.12.0
Steps to Reproduce
I am trying to load data from a third party API. I have added the URLs, Tokens, and Keys to the .env file.
I am trying to access these env variables in a route loader. In remix applications this works, in a hydrogen application I am not having much success.
The Hydrogen documentation, https://shopify.dev/docs/custom-storefronts/hydrogen/environment-variables, say to refer to the Remix documentation: https://remix.run/docs/en/1.14.3/guides/envvars#server-environment-variables
export const loader = async () => { console.log(process.env.API_URL); };
Expected Behavior
Return the env variables.
Actual Behavior
"ReferenceError: process is not defined"
The text was updated successfully, but these errors were encountered: