ENV in Honox
What is the feature you are proposing?
I looked through the documentation and I did not see anywhere documenting how to use ENVs. I checked VITE and saw that I can use ENV by creating an .env file and adding the VITE_ prefix to the env name. Sample VITE_HELLO=WORLD.
Is this the best way or is there another?
Since HonoX is built on Vite, dotfiles should work fine. They can be accessed via the Context object within any route.
export default createRoute(async (c) => {
console.log(c.env.DEBUG)
return c.html(<html>{c.env.DEBUG}</html>);
});
@bruceharrison1984 It did not seem to work without the adding the VITE_ prefix. What am I doing wrong?
in my case, I'm doing it in vite config. not ideal but good enough for my use case
export default defineConfig(async ({ command, mode }) => {
if (command === 'serve') {
await import('dotenv/config');
}
...
@divofred If I am not mistaken, the VITE_ prefix is my design. Vite does this to prevent accidentally leaking env variables.
https://vitejs.dev/guide/env-and-mode#env-files
@divofred If I am not mistaken, the
VITE_prefix is my design. Vite does this to prevent accidentally leaking env variables. https://vitejs.dev/guide/env-and-mode#env-files
Alright, thanks. @terenced