Skip to content
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

ENV in Honox #79

Open
divofred opened this issue Feb 20, 2024 · 5 comments
Open

ENV in Honox #79

divofred opened this issue Feb 20, 2024 · 5 comments
Labels
enhancement New feature or request

Comments

@divofred
Copy link

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 divofred added the enhancement New feature or request label Feb 20, 2024
@bruceharrison1984
Copy link
Contributor

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

@divofred
Copy link
Author

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

@niicojs
Copy link

niicojs commented Feb 23, 2024

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

@terenced
Copy link

@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
Copy link
Author

@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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

4 participants