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 #674

Closed
wants to merge 8 commits into from
Closed
Show file tree
Hide file tree
Changes from 6 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
9 changes: 9 additions & 0 deletions docs/pages/env-vars-config.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,15 @@ 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:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please mention how the user can change the environment. (by setting NODE_ENV in their environment.)

`.env.development` or `.env.production`

`.env.local` always overrides any other existing `.env*` file.

## 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
44 changes: 22 additions & 22 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,9 +31,11 @@ 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 { ChannelInterface, OperationReplyInterface } from '@asyncapi/parser'
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',
Expand Down Expand Up @@ -100,27 +100,27 @@ export default async function GleeAppInitializer() {
app.useOutbound(errorLogger)
await generateDocs(config)
parsedAsyncAPI.operations().filterByReceive().forEach(operation => {
const channel = operation.channels()[0] // operation can have only one channel.
const reply = operation.reply()
setUpReplyMiddlewares(reply, app)

const schema = getMessagesSchema(operation)
if (schema.oneOf.length > 0) app.use(channel.id(), validate(schema))
app.use(channel.id(), (event, next) => {
triggerFunction({
app,
operation,
message: event
}).then(next).catch(next)
const channel = operation.channels()[0] // operation can have only one channel.
const reply = operation.reply()
setUpReplyMiddlewares(reply, app)

const schema = getMessagesSchema(operation)
if (schema.oneOf.length > 0) app.use(channel.id(), validate(schema))
app.use(channel.id(), (event, next) => {
triggerFunction({
app,
operation,
message: event
}).then(next).catch(next)
})
})
})

parsedAsyncAPI.operations().filterBySend().forEach(operation => {
const channel = operation.channels()[0] // operation can have only one channel.
const schema = getMessagesSchema(operation)
if (schema.oneOf.length > 0) app.useOutbound(channel.id(), validate(schema))
app.useOutbound(channel.id(), json2string)
})
const channel = operation.channels()[0] // operation can have only one channel.
const schema = getMessagesSchema(operation)
if (schema.oneOf.length > 0) app.useOutbound(channel.id(), validate(schema))
app.useOutbound(channel.id(), json2string)
})

app.on('adapter:auth', async (e: AuthEvent) => {
logLineWithIcon(
Expand Down
Loading