I’m getting errors when running my remix application in production mode. I thing this is the fact that my Remix application is launched in Fly.io and I am not exactly sure how to access these secrets. I have the route where I am trying to access my secret keys as follows:
type LoaderData = {
ALGOLIA_ID: string;
ALGOLIA_KEY: string;
};
export const loader: LoaderFunction = async () => {
const ALGOLIA_ID = process.env.ALGOLIA_ID;
const ALGOLIA_KEY = process.env.ALGOLIA_KEY;
if (!ALGOLIA_ID || !ALGOLIA_KEY) throw new Error('Env Variables not found');
const data: LoaderData = { ALGOLIA_ID, ALGOLIA_KEY };
return data;
};
//... code here
export default function Index() {
let searchClient;
if (process.env.NODE_ENV === 'development') {
const data = useLoaderData<LoaderData>();
searchClient = algoliasearch(data.ALGOLIA_ID, data.ALGOLIA_KEY);
} else if (process.env.NODE_ENV === 'production') {
if (!process.env.ALGOLIA_ID || !process.env.ALGOLIA_KEY)
throw new Error('Env Variables not found');
searchClient = algoliasearch(
process.env.ALGOLIA_ID,
process.env.ALGOLIA_KEY
);
}
//... more code after
}
I am getting the error ReferenceError: process is not defined
so I can’t even use process when I am in production. I am not sure how to go about accessing my secrets for production. This also makes me wonder how would I go about adding conditionals for my remix app depending whether I am in production or not since I cannot use process.env
?