Skip to content

Commit

Permalink
fix default config for http server (#496)
Browse files Browse the repository at this point in the history
  • Loading branch information
dotansimha authored Mar 5, 2024
1 parent 23a0ae5 commit ed100b3
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 6 deletions.
1 change: 1 addition & 0 deletions bin/conductor/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down
7 changes: 5 additions & 2 deletions libs/config/conductor.schema.json
Original file line number Diff line number Diff line change
@@ -1,15 +1,18 @@
{
"$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",
"sources"
],
"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"
Expand Down
21 changes: 20 additions & 1 deletion libs/config/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<ServerConfig> {
Some(ServerConfig {
port: default_server_port(),
host: default_server_host(),
})
}

#[cfg(target_arch = "wasm32")]
fn default_server_config() -> Option<ServerConfig> {
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<ServerConfig>,
#[serde(default, skip_serializing_if = "Option::is_none")]
/// Conductor logger configuration.
Expand Down
6 changes: 3 additions & 3 deletions test_config/config.yaml
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
server:
port: 8000

logger:
filter: debug
format: compact
# logger:
# filter: debug
# format: compact

sources:
- id: countries
Expand Down

0 comments on commit ed100b3

Please sign in to comment.