honox icon indicating copy to clipboard operation
honox copied to clipboard

ENV in Honox

Open divofred opened this issue 2 years ago • 5 comments

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?

divofred avatar Feb 20 '24 20:02 divofred

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 avatar Feb 20 '24 22:02 bruceharrison1984

@bruceharrison1984 It did not seem to work without the adding the VITE_ prefix. What am I doing wrong?

divofred avatar Feb 20 '24 23:02 divofred

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');
  }
  ...

niicojs avatar Feb 23 '24 10:02 niicojs

@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

terenced avatar May 17 '24 14:05 terenced

@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

divofred avatar May 17 '24 14:05 divofred