Configuring Environment Variables and Configuration File

Found an error? Have a suggestion?Edit this page on GitHub

Environment Variables

Glee provides several environment variables that allow you to tailor your application's behavior to fit specific needs:

VariablePurposeExample Usage
GLEE_SERVER_NAMESSpecifies a list of servers to initialize at startup, separated by commas.GLEE_SERVER_NAMES=websockets,mosquitto
GLEE_SERVER_CERTSIndicates server-specific certificate files in a ${serverName}:${pathToCertificateFile} format, separated by commas.GLEE_SERVER_CERTS=mosquitto:mosquitto.org.crt
GLEE_SERVER_VARIABLESSets server variables in a ${serverName}:${serverVariable}:${value} format, separated by commas.GLEE_SERVER_VARIABLES=websockets:namespace:public

Handling Multiple .env Files

Glee supports loading variables from .env.local directly into process.env. This feature is handy for keeping secrets out of your repository during development. You can also set environment-specific defaults in .env.development or .env.production.

.env.local takes precedence over other .env* files.

Switch between development and production environments by setting the NODE_ENV variable accordingly.

Customizing Glee Settings

While Glee comes with defaults for ease of use, you may want to customize settings for specific needs. This is where glee.config.js comes into play.

The Glee Config File

glee.config.js is a JavaScript file exporting an asynchronous function, structured as follows:

1export default async function () {
2  // Configuration details go here...
3}

This function should return an object with configurable properties:

1export default async function () {
2  return {
3    glee: {},
4    websocket: {},
5    cluster: {},
6    http: {}
7  }
8}

For example, a typical glee.config.js might look like this:

1export default async function () {
2  return {
3    glee: { // Core Glee configurations
4      lifecycleDir: './lifecycle',
5      functionsDir: './functions',
6      asyncapiFilePath: './asyncapi.json',
7      logs: { // Adjust default logging behavior
8        incoming: 'channel-only', // Logs only the channel, not the message payload
9        outgoing: 'none', // Disables outgoing logs
10      }
11    },
12    docs: {
13      enabled: true, // Toggles documentation generation
14      folder: 'docs', // Destination folder for docs
15      template: '@asyncapi/markdown-template' // Specifies the documentation template
16    },
17    ws: {
18      server: {
19        httpServer: customServer, // Custom HTTP server
20        adapter: "native", // Defaults to 'native', can be 'socket.io' or a custom adapter
21        port: process.env.PORT, // Server port
22      }
23    },
24    cluster: {
25      adapter: "redis", // Cluster adapter, default is Redis
26      name: "cluster", // Cluster name
27      url: "redis://localhost:6379", // URL for the cluster server (Redis in this case)
28    },
29    http: {
30      server: {
31        httpServer: customServer, // Custom HTTP server
32        adapter: 'native', 
33        port: process.env.PORT, // Server port
34      },
35    }
36  };
37}

In the return statement, configure the following options:

Core Glee Configurations

These settings are specific to Glee itself.

FieldDefaultPurpose
glee.gleeDir.gleeDetermines the Glee directory for compiled sources.
glee.lifecycleDirlifecycleSpecifies the path to lifecycle events.
glee.functionsDirfunctionsDesignates the path to functions.
glee.asyncapiFilePathasyncapi.(yaml | yml | json)Path to your AsyncAPI file.
glee.logsdefaultConfigures logging for incoming and outgoing messages.
glee.logs.incoming"all"Options: channel-only, none.
glee.logs.outgoing"all"Options: channel-only, none.

Documentation Configuration

FieldPurpose
docs.enabledEnables or disables documentation generation.
docs.folderSpecifies the output directory for documentation.
docs.templateDetermines the AsyncAPI template for docs generation.

WebSocket Server Configuration

FieldPurpose
ws.serverWebSocket server-specific settings.
ws.server.adapterSelects the WebSocket server adapter: native, socket.io, or a custom one.
ws.server.httpServerA custom HTTP server instance.
ws.server.port

|The port for the WebSocket server.|

Cluster Configuration

FieldPurpose
cluster.adapterChooses the cluster communication adapter (default: Redis Pub/Sub).
cluster.nameThe cluster's name.
cluster.urlURL of the server used by the cluster adapter.

HTTP Server Configuration

FieldPurpose
http.serverHTTP server-specific settings.
http.server.adapterSelects the HTTP server adapter.
http.server.portThe port for the HTTP server.
Was this helpful?
Help us improve the docs by adding your contribution.
OR
Github:AsyncAPICreate Issue on GitHub