Skip to content
This repository was archived by the owner on Mar 18, 2025. It is now read-only.

Commit ed100b3

Browse files
authored
fix default config for http server (#496)
1 parent 23a0ae5 commit ed100b3

File tree

4 files changed

+29
-6
lines changed

4 files changed

+29
-6
lines changed

bin/conductor/src/lib.rs

+1
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@ pub async fn run_services(config_file_path: &String) -> std::io::Result<()> {
5757
});
5858

5959
let server_config = config.server.clone().unwrap_or_default();
60+
6061
let server_address = format!("{}:{}", server_config.host, server_config.port);
6162
debug!("server is trying to listen on {:?}", server_address);
6263

libs/config/conductor.schema.json

+5-2
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,18 @@
11
{
22
"$schema": "https://json-schema.org/draft/2019-09/schema",
33
"title": "ConductorConfig",
4-
"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.",
54
"type": "object",
65
"required": [
76
"endpoints",
87
"sources"
98
],
109
"properties": {
1110
"server": {
12-
"description": "Configuration for the HTTP server.",
11+
"description": "Configuration for the HTTP server.\n\nNote: for CloudFlare Worker runtime, this configuration is ignored.",
12+
"default": {
13+
"host": "127.0.0.1",
14+
"port": 9000
15+
},
1316
"anyOf": [
1417
{
1518
"$ref": "#/definitions/ServerConfig"

libs/config/src/lib.rs

+20-1
Original file line numberDiff line numberDiff line change
@@ -84,11 +84,30 @@ use std::{collections::HashMap, fs::read_to_string, path::Path, time::Duration};
8484
/// Examples:
8585
/// - `endpoint: ${API_ENDPOINT:https://api.example.com/}` - Uses the `API_ENDPOINT` variable or defaults to the provided URL.
8686
/// - `name: \$super` - Results in the literal string `name: \$super` in the configuration.
87+
///
88+
89+
#[cfg(not(target_arch = "wasm32"))]
90+
fn default_server_config() -> Option<ServerConfig> {
91+
Some(ServerConfig {
92+
port: default_server_port(),
93+
host: default_server_host(),
94+
})
95+
}
96+
97+
#[cfg(target_arch = "wasm32")]
98+
fn default_server_config() -> Option<ServerConfig> {
99+
None
100+
}
87101

88102
#[derive(Deserialize, Serialize, Debug, Clone, JsonSchema)]
89103
pub struct ConductorConfig {
90-
#[serde(default, skip_serializing_if = "Option::is_none")]
104+
#[serde(
105+
default = "default_server_config",
106+
skip_serializing_if = "Option::is_none"
107+
)]
91108
/// Configuration for the HTTP server.
109+
///
110+
/// Note: for CloudFlare Worker runtime, this configuration is ignored.
92111
pub server: Option<ServerConfig>,
93112
#[serde(default, skip_serializing_if = "Option::is_none")]
94113
/// Conductor logger configuration.

test_config/config.yaml

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
server:
22
port: 8000
33

4-
logger:
5-
filter: debug
6-
format: compact
4+
# logger:
5+
# filter: debug
6+
# format: compact
77

88
sources:
99
- id: countries

0 commit comments

Comments
 (0)