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

feat: add support for multiple .env files. #683

Merged
merged 2 commits into from
Jan 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions docs/pages/env-vars-config.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
6 changes: 6 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
8 changes: 5 additions & 3 deletions src/index.ts
Original file line number Diff line number Diff line change
@@ -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'
Expand Down Expand Up @@ -33,8 +31,12 @@
import { EnrichedEvent, AuthEvent } from './lib/adapter.js'
import { ClusterEvent } from './lib/cluster.js'
import { getMessagesSchema } from './lib/util.js'
import { OperationReplyInterface } from '@asyncapi/parser'

Check warning on line 34 in src/index.ts

View workflow job for this annotation

GitHub Actions / Test NodeJS PR - ubuntu-latest

'OperationReplyInterface' is defined but never used

Check warning on line 34 in src/index.ts

View workflow job for this annotation

GitHub Actions / Test NodeJS PR - macos-latest

'OperationReplyInterface' is defined but never used
import {loadEnvConfig} from '@next/env'

dotenvExpand(dotenv.config())

const isDev = process.env.NODE_ENV === 'development'
loadEnvConfig(process.cwd(), isDev)

enum LOG_CONFIG {
NONE = 'none',
Expand Down