diff --git a/Containerfile b/Containerfile index a95d31c..e7c3b28 100644 --- a/Containerfile +++ b/Containerfile @@ -12,6 +12,5 @@ COPY --from=caddy-builder /usr/bin/caddy /caddy VOLUME "/config.toml" VOLUME "/sites" -EXPOSE 80 CMD ["./sscdc"] \ No newline at end of file diff --git a/src/caddy.rs b/src/caddy.rs index 916d30f..0382abf 100644 --- a/src/caddy.rs +++ b/src/caddy.rs @@ -97,7 +97,7 @@ impl CaddyController { } } -fn get_initial_caddy_configuration_object(admin_api_socket_path: &Utf8Path, api_socket_path: &Utf8Path) -> serde_json::Value { +fn get_initial_caddy_configuration_object(admin_api_socket_path: &Utf8Path, api_socket_path: &Utf8Path, http_port: u16) -> serde_json::Value { json!({ "admin": { "listen": format!("unix/{}", admin_api_socket_path), @@ -123,7 +123,7 @@ fn get_initial_caddy_configuration_object(admin_api_socket_path: &Utf8Path, api_ "http": { "servers": { "srv0": { - "listen": [":80"], + "listen": [format!(":{http_port}")], "routes": [{ "match": [{ "path": ["/_sscdc/*"] }], "handle": [ @@ -150,7 +150,7 @@ async fn request_uds(path: &Utf8Path, request: Request) -> http_client::http_typ async_h1::connect(stream, request).await } -pub async fn start_caddy(api_socket_path: &Utf8Path, sockets_directory_path: &Utf8Path) -> Result { +pub async fn start_caddy(api_socket_path: &Utf8Path, sockets_directory_path: &Utf8Path, http_port: u16) -> Result { let caddy_admin_socket_path = sockets_directory_path.join("caddy-admin-api.sock"); // Stop not properly cleaned up proxy. @@ -162,7 +162,7 @@ pub async fn start_caddy(api_socket_path: &Utf8Path, sockets_directory_path: &Ut // Spawn a new proxy. let process = Command::new(caddy_path).args(&["run", "--config", "-"]).stdin(Stdio::piped()).spawn()?; - let initial_configuration_object = get_initial_caddy_configuration_object(&caddy_admin_socket_path, api_socket_path); + let initial_configuration_object = get_initial_caddy_configuration_object(&caddy_admin_socket_path, api_socket_path, http_port); let initial_configuration_string = initial_configuration_object.to_string(); debug!("Initial caddy configuration: {}", initial_configuration_string); diff --git a/src/config.rs b/src/config.rs index e915061..f50ec7b 100644 --- a/src/config.rs +++ b/src/config.rs @@ -11,6 +11,7 @@ use validator::Validate; #[derive(Deserialize, Debug, Validate)] pub struct Config { + pub http_port: u16, pub sites_directory: String, pub sockets_directory: String, #[validate(nested)] diff --git a/src/main.rs b/src/main.rs index 655897e..c5f4ee5 100644 --- a/src/main.rs +++ b/src/main.rs @@ -32,7 +32,7 @@ async fn main() -> Result<()> { let api_socket_path = sockets_directory_path.join("api.sock"); log::info!("Starting the reverse proxy…"); - let caddy_controller = start_caddy(&api_socket_path, &sockets_directory_path).await?; + let caddy_controller = start_caddy(&api_socket_path, &sockets_directory_path, config.http_port).await?; let (sites_worker, sites_worker_join_handle) = start_sites_worker(config.sites_directory.to_string().into(), caddy_controller).await?;