
Extend env module for AdonisJS
Request Feature
·
Report Bug
·
Request Modification
Table of Contents
The environment module extend the behavior of the default AdonisJS env module by adding support for Scaleway Secrets.
We welcome contributions and improvements to this module. Don't hesitate to submit features and improvements ;)
For now the package isn't published to npm, but you can install it from the GitHub registry and can be installed in any project.
-
You need to create a
.npmrc
file at the root of your project with the following content:@lithium-apps:registry=https://npm.pkg.github.com
-
For the login process you need to set a personal access token with the
read:packages
scope. Then you can login to the GitHub registry with the following command:pnpm login --registry=https://npm.pkg.github.com --scope=@lithium-apps
-
You can now install the packages using the following command:
pnpm install @lithium-apps/extended-env
-
Replace the import of the default AdonisJS env module by the extended one in
start/env.ts
:// import { Env } from '@adonisjs/core/env'; -- Replace this line import { Env } from '@lithium-apps/extended-env';
-
Use the new modules when defining your schema:
import { Env } from '@lithium-apps/extended-env'; export default await Env.create(new URL('../', import.meta.url), { NODE_ENV: Env.schema.enum(['development', 'production', 'test'] as const), PORT: Env.schema.number(), APP_KEY: Env.schema.string(), HOST: Env.schema.string({ format: 'host' }), LOG_LEVEL: Env.schema.enum(['fatal', 'error', 'warn', 'info', 'debug', 'trace', 'silent']), /* |---------------------------------------------------------- | Variables for configuring database connection |---------------------------------------------------------- */ SECRET_DATABASE: Env.scaleway.database.optional({ host: 'DB_HOST', port: 'DB_PORT', username: 'DB_USER', password: 'DB_PASSWORD', dbname: 'DB_DATABASE', }), DB_HOST: Env.schema.string.optionalWhen(() => Env.scaleway.exists('SECRET_DATABASE'), { format: 'host' }), DB_PORT: Env.schema.number.optionalWhen(() => Env.scaleway.exists('SECRET_DATABASE')), DB_USER: Env.schema.string.optionalWhen(() => Env.scaleway.exists('SECRET_DATABASE')), DB_DATABASE: Env.schema.string.optionalWhen(() => Env.scaleway.exists('SECRET_DATABASE')), DB_PASSWORD: Env.schema.string.optional(), });
- Kylian Mallet - @Kylian-Mallet - kylian.mallet@sklav.group