diff --git a/bin/conductor/src/lib.rs b/bin/conductor/src/lib.rs index 6691b987..867ca307 100644 --- a/bin/conductor/src/lib.rs +++ b/bin/conductor/src/lib.rs @@ -57,6 +57,7 @@ pub async fn run_services(config_file_path: &String) -> std::io::Result<()> { }); let server_config = config.server.clone().unwrap_or_default(); + let server_address = format!("{}:{}", server_config.host, server_config.port); debug!("server is trying to listen on {:?}", server_address); diff --git a/libs/config/conductor.schema.json b/libs/config/conductor.schema.json index a0aae6c3..879e979a 100644 --- a/libs/config/conductor.schema.json +++ b/libs/config/conductor.schema.json @@ -1,7 +1,6 @@ { "$schema": "https://json-schema.org/draft/2019-09/schema", "title": "ConductorConfig", - "description": "This section describes the top-level configuration object for Conductor gateway.\n\nConductor supports both YAML and JSON format for the configuration file.\n\n## Loading the config file\n\nThe configuration is loaded when server starts, based on the runtime environment you are using:\n\n### Binary\n\nIf you are running the Conductor binary directly, you can specify the configuration file path using the first argument:\n\n```sh\n\nconductor my-config-file.json\n\n```\n\n> By default, Conductor will look for a file named `config.json` in the current directory.\n\n### Docker\n\nIf you are using Docker environment, you can mount the configuration file into the container, and then point the Conductor binary to it:\n\n```sh\n\ndocker run -v my-config-file.json:/app/config.json the-guild-org/conductor:TAG /app/config.json\n\n```\n\n> Replace `TAG` with a specific [release version](https://github.com/the-guild-org/conductor/releases).\n\n### CloudFlare Worker\n\nWASM runtime doesn't allow filesystem access, so you need to load the configuration file into an environment variable named `CONDUCTOR_CONFIG`.\n\n## Autocomplete/validation in VSCode\n\nFor JSON files, you can specify the `$schema` property to enable autocomplete and validation in VSCode:\n\n```json filename=\"config.json\"\n\n{ \"$schema\": \"https://raw.githubusercontent.com/the-guild-org/conductor/master/libs/config/conductor.schema.json\" }\n\n```\n\nFor YAML auto-complete and validation, you can install the [YAML Language Support](https://marketplace.visualstudio.com/items?itemName=redhat.vscode-yaml) extension and enable it by adding the following to your YAML file:\n\n```yaml filename=\"config.yaml\"\n\n$schema: \"https://raw.githubusercontent.com/the-guild-org/conductor/master/libs/config/conductor.schema.json\"\n\n```\n\n### JSONSchema\n\nAs part of the release flow of Conductor, we are publishing the configuration schema as a JSONSchema file.\n\nYou can find [here the latest version of the schema](https://github.com/the-guild-org/conductor/releases).\n\n### Configuration Interpolation with Environment Variables\n\nThis feature allows the dynamic insertion of environment variables into the config file for Conductor. It enhances flexibility by adapting the configuration based on the runtime environment.\n\nSyntax for Environment Variable Interpolation: - Use `${VAR_NAME}` to insert the value of an environment variable. If `VAR_NAME` is not set, an error will pop up. - Specify a default value with `${VAR_NAME:default_value}` which is used when `VAR_NAME` is not set. - Escape a dollar sign by preceding it with a backslash (e.g., `\\$`) to use it as a literal character instead of triggering interpolation.\n\nExamples: - `endpoint: ${API_ENDPOINT:https://api.example.com/}` - Uses the `API_ENDPOINT` variable or defaults to the provided URL. - `name: \\$super` - Results in the literal string `name: \\$super` in the configuration.", "type": "object", "required": [ "endpoints", @@ -9,7 +8,11 @@ ], "properties": { "server": { - "description": "Configuration for the HTTP server.", + "description": "Configuration for the HTTP server.\n\nNote: for CloudFlare Worker runtime, this configuration is ignored.", + "default": { + "host": "127.0.0.1", + "port": 9000 + }, "anyOf": [ { "$ref": "#/definitions/ServerConfig" diff --git a/libs/config/src/lib.rs b/libs/config/src/lib.rs index 52143cdf..e11fc76c 100644 --- a/libs/config/src/lib.rs +++ b/libs/config/src/lib.rs @@ -84,11 +84,30 @@ use std::{collections::HashMap, fs::read_to_string, path::Path, time::Duration}; /// Examples: /// - `endpoint: ${API_ENDPOINT:https://api.example.com/}` - Uses the `API_ENDPOINT` variable or defaults to the provided URL. /// - `name: \$super` - Results in the literal string `name: \$super` in the configuration. +/// + +#[cfg(not(target_arch = "wasm32"))] +fn default_server_config() -> Option { + Some(ServerConfig { + port: default_server_port(), + host: default_server_host(), + }) +} + +#[cfg(target_arch = "wasm32")] +fn default_server_config() -> Option { + None +} #[derive(Deserialize, Serialize, Debug, Clone, JsonSchema)] pub struct ConductorConfig { - #[serde(default, skip_serializing_if = "Option::is_none")] + #[serde( + default = "default_server_config", + skip_serializing_if = "Option::is_none" + )] /// Configuration for the HTTP server. + /// + /// Note: for CloudFlare Worker runtime, this configuration is ignored. pub server: Option, #[serde(default, skip_serializing_if = "Option::is_none")] /// Conductor logger configuration. diff --git a/test_config/config.yaml b/test_config/config.yaml index 80c159cf..00cf158e 100644 --- a/test_config/config.yaml +++ b/test_config/config.yaml @@ -1,9 +1,9 @@ server: port: 8000 -logger: - filter: debug - format: compact +# logger: + # filter: debug + # format: compact sources: - id: countries