Make the HTTP port configurable
This commit is contained in:
parent
107d6b11ea
commit
473faafa5b
4 changed files with 6 additions and 6 deletions
|
@ -12,6 +12,5 @@ COPY --from=caddy-builder /usr/bin/caddy /caddy
|
||||||
|
|
||||||
VOLUME "/config.toml"
|
VOLUME "/config.toml"
|
||||||
VOLUME "/sites"
|
VOLUME "/sites"
|
||||||
EXPOSE 80
|
|
||||||
|
|
||||||
CMD ["./sscdc"]
|
CMD ["./sscdc"]
|
|
@ -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!({
|
json!({
|
||||||
"admin": {
|
"admin": {
|
||||||
"listen": format!("unix/{}", admin_api_socket_path),
|
"listen": format!("unix/{}", admin_api_socket_path),
|
||||||
|
@ -123,7 +123,7 @@ fn get_initial_caddy_configuration_object(admin_api_socket_path: &Utf8Path, api_
|
||||||
"http": {
|
"http": {
|
||||||
"servers": {
|
"servers": {
|
||||||
"srv0": {
|
"srv0": {
|
||||||
"listen": [":80"],
|
"listen": [format!(":{http_port}")],
|
||||||
"routes": [{
|
"routes": [{
|
||||||
"match": [{ "path": ["/_sscdc/*"] }],
|
"match": [{ "path": ["/_sscdc/*"] }],
|
||||||
"handle": [
|
"handle": [
|
||||||
|
@ -150,7 +150,7 @@ async fn request_uds(path: &Utf8Path, request: Request) -> http_client::http_typ
|
||||||
async_h1::connect(stream, request).await
|
async_h1::connect(stream, request).await
|
||||||
}
|
}
|
||||||
|
|
||||||
pub async fn start_caddy(api_socket_path: &Utf8Path, sockets_directory_path: &Utf8Path) -> Result<CaddyController> {
|
pub async fn start_caddy(api_socket_path: &Utf8Path, sockets_directory_path: &Utf8Path, http_port: u16) -> Result<CaddyController> {
|
||||||
let caddy_admin_socket_path = sockets_directory_path.join("caddy-admin-api.sock");
|
let caddy_admin_socket_path = sockets_directory_path.join("caddy-admin-api.sock");
|
||||||
|
|
||||||
// Stop not properly cleaned up proxy.
|
// 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.
|
// Spawn a new proxy.
|
||||||
let process = Command::new(caddy_path).args(&["run", "--config", "-"]).stdin(Stdio::piped()).spawn()?;
|
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();
|
let initial_configuration_string = initial_configuration_object.to_string();
|
||||||
debug!("Initial caddy configuration: {}", initial_configuration_string);
|
debug!("Initial caddy configuration: {}", initial_configuration_string);
|
||||||
|
|
||||||
|
|
|
@ -11,6 +11,7 @@ use validator::Validate;
|
||||||
|
|
||||||
#[derive(Deserialize, Debug, Validate)]
|
#[derive(Deserialize, Debug, Validate)]
|
||||||
pub struct Config {
|
pub struct Config {
|
||||||
|
pub http_port: u16,
|
||||||
pub sites_directory: String,
|
pub sites_directory: String,
|
||||||
pub sockets_directory: String,
|
pub sockets_directory: String,
|
||||||
#[validate(nested)]
|
#[validate(nested)]
|
||||||
|
|
|
@ -32,7 +32,7 @@ async fn main() -> Result<()> {
|
||||||
let api_socket_path = sockets_directory_path.join("api.sock");
|
let api_socket_path = sockets_directory_path.join("api.sock");
|
||||||
|
|
||||||
log::info!("Starting the reverse proxy…");
|
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?;
|
let (sites_worker, sites_worker_join_handle) = start_sites_worker(config.sites_directory.to_string().into(), caddy_controller).await?;
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue