Environment Variables
Glee provides several environment variables that allow you to tailor your application's behavior to fit specific needs:
Variable | Purpose | Example Usage |
---|---|---|
GLEE_SERVER_NAMES | Specifies a list of servers to initialize at startup, separated by commas. | GLEE_SERVER_NAMES=websockets,mosquitto |
GLEE_SERVER_CERTS | Indicates server-specific certificate files in a ${serverName}:${pathToCertificateFile} format, separated by commas. | GLEE_SERVER_CERTS=mosquitto:mosquitto.org.crt |
GLEE_SERVER_VARIABLES | Sets 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.
Field | Default | Purpose |
---|---|---|
glee.gleeDir | .glee | Determines the Glee directory for compiled sources. |
glee.lifecycleDir | lifecycle | Specifies the path to lifecycle events. |
glee.functionsDir | functions | Designates the path to functions. |
glee.asyncapiFilePath | asyncapi.(yaml | yml | json) | Path to your AsyncAPI file. |
glee.logs | default | Configures logging for incoming and outgoing messages. |
glee.logs.incoming | "all" | Options: channel-only , none . |
glee.logs.outgoing | "all" | Options: channel-only , none . |
Documentation Configuration
Field | Purpose |
---|---|
docs.enabled | Enables or disables documentation generation. |
docs.folder | Specifies the output directory for documentation. |
docs.template | Determines the AsyncAPI template for docs generation. |
WebSocket Server Configuration
Field | Purpose |
---|---|
ws.server | WebSocket server-specific settings. |
ws.server.adapter | Selects the WebSocket server adapter: native , socket.io , or a custom one. |
ws.server.httpServer | A custom HTTP server instance. |
ws.server.port |
|The port for the WebSocket server.|
Cluster Configuration
Field | Purpose |
---|---|
cluster.adapter | Chooses the cluster communication adapter (default: Redis Pub/Sub). |
cluster.name | The cluster's name. |
cluster.url | URL of the server used by the cluster adapter. |
HTTP Server Configuration
Field | Purpose |
---|---|
http.server | HTTP server-specific settings. |
http.server.adapter | Selects the HTTP server adapter. |
http.server.port | The port for the HTTP server. |