Skip to content

Latest commit

 

History

History

Folders and files

NameName
Last commit message
Last commit date

parent directory

..
 
 
 
 
 
 
 
 
 
 
 
 

README.md

@varlock/astro-integration

npm version GitHub stars license

This package helps you integrate varlock into an Astro project.

See our docs site for complete installation and usage instructions.

It is designed as an Astro integration, which will override Astro's default .env file loading logic (powered by Vite), to instead use varlock.

Compared to the default Astro behavior, this package provides:

  • Validation of your env vars against your .env.schema
  • Type-generation and type-safe env var access with built-in docs
  • Redaction of sensitive from logs during build time
  • Automatic leak prevention of sensitive items at build and runtime
  • More flexible multi-env handling, rather than relying on the --mode flag

While some of these features are similar to what can be accomplished via astro:env, this integration provides additional security features and more flexible multi-env handling.

  • Facilitates loading and composing multiple .env files
  • You can use validated env vars right away within your astro.config.* file
  • Facilitates setting values and handling multiple environments, not just setting defaults
  • More data types and options available
  • Leak detection, log redaction, and more security guardrails
  • Works with various adapters and platforms to make your resolved config available
  • Automatically injects a server route for dynamic+public values (/__varlock/public-env by default)

Dynamic public endpoint

The integration injects a JSON endpoint for getPublicDynamicEnv() in server/dev mode:

  • default behavior: auto-enabled only when your schema has dynamic+public items
  • default path when enabled: /__varlock/public-env
  • force-enable at default path:
varlockAstroIntegration({ publicDynamicEndpoint: true });
  • disable it:
varlockAstroIntegration({ publicDynamicEndpoint: false });
  • customize the path:
varlockAstroIntegration({
  publicDynamicEndpoint: { path: '/api/public-env' },
});