diff --git a/docs/pages/env-vars-config.md b/docs/pages/env-vars-config.md index e48418a44..0dddf1612 100644 --- a/docs/pages/env-vars-config.md +++ b/docs/pages/env-vars-config.md @@ -13,6 +13,16 @@ Glee provides a few environment variables for you to customize the Glee applicat |GLEE_SERVER_CERTS|A comma-separated list of `${serverName}:${pathToCertificateFile}`. These are the certificates to use when establishing the connection to the given server.|`GLEE_SERVER_CERTS=mosquitto:mosquitto.org.crt`| |GLEE_SERVER_VARIABLES|A comma-separated list of `${serverName}:${serverVariable}:${value}`. These are the values to use for each server variable.|`GLEE_SERVER_VARIABLES=websockets:namespace:public`| +### Support for multiple .env files +Glee has support for loading variables from `.env.local` into `process.env`. +This is useful for storing secret environment variables needed in development while keeping them out of the repository. +However, sometimes you might want to add some defaults for the `development` or `production` environment. You can do that by creating files with the following names: +`.env.development` or `.env.production` + +`.env.local` always overrides any other existing `.env*` file. + +You can change the environment by setting the `NODE_ENV` variable to `development` or `production`. + ## Configuring Glee Glee comes with sensible defaults so you don't have to worry about configuration. However, sometimes you may want to change the behavior or customize Glee in different ways. For that purpose, you can use the `glee.config.js` file. diff --git a/package-lock.json b/package-lock.json index dafb55e94..f6b912b60 100644 --- a/package-lock.json +++ b/package-lock.json @@ -13,6 +13,7 @@ "@asyncapi/html-template": "^2.0.0", "@asyncapi/markdown-template": "^1.5.0", "@asyncapi/parser": "^3.0.2", + "@next/env": "^14.0.4", "@types/jest": "^29.5.11", "@types/qs": "^6.9.7", "ajv": "^6.12.6", @@ -3820,6 +3821,11 @@ "resolved": "https://registry.npmjs.org/@kwsites/promise-deferred/-/promise-deferred-1.1.1.tgz", "integrity": "sha512-GaHYm+c0O9MjZRu0ongGBRbinu8gVAMd2UZjji6jVmqKtZluZnptXGWhz1E8j8D2HJ3f/yMxKAUC0b+57wncIw==" }, + "node_modules/@next/env": { + "version": "14.0.4", + "resolved": "https://registry.npmjs.org/@next/env/-/env-14.0.4.tgz", + "integrity": "sha512-irQnbMLbUNQpP1wcE5NstJtbuA/69kRfzBrpAD7Gsn8zm/CY6YQYc3HQBz8QPxwISG26tIm5afvvVbu508oBeQ==" + }, "node_modules/@nodelib/fs.scandir": { "version": "2.1.5", "resolved": "https://registry.npmjs.org/@nodelib/fs.scandir/-/fs.scandir-2.1.5.tgz", diff --git a/package.json b/package.json index 58d7617e3..60f564e73 100644 --- a/package.json +++ b/package.json @@ -38,6 +38,7 @@ "@asyncapi/html-template": "^2.0.0", "@asyncapi/markdown-template": "^1.5.0", "@asyncapi/parser": "^3.0.2", + "@next/env": "^14.0.4", "@types/jest": "^29.5.11", "@types/qs": "^6.9.7", "ajv": "^6.12.6", diff --git a/src/index.ts b/src/index.ts index 57ac5b413..9e77c7c8d 100755 --- a/src/index.ts +++ b/src/index.ts @@ -1,6 +1,4 @@ import { resolve } from 'path' -import * as dotenv from 'dotenv' -import dotenvExpand from 'dotenv-expand' import Glee from './lib/glee.js' import { logWelcome, logLineWithIcon, logWarningMessage } from './lib/logger.js' import experimentalFlags from './lib/experimentalFlags.js' @@ -33,8 +31,12 @@ import { getSelectedServerNames } from './lib/servers.js' import { EnrichedEvent, AuthEvent } from './lib/adapter.js' import { ClusterEvent } from './lib/cluster.js' import { getMessagesSchema } from './lib/util.js' +import { OperationReplyInterface } from '@asyncapi/parser' +import {loadEnvConfig} from '@next/env' -dotenvExpand(dotenv.config()) + +const isDev = process.env.NODE_ENV === 'development' +loadEnvConfig(process.cwd(), isDev) enum LOG_CONFIG { NONE = 'none',