feat: Add Dockerization support
This commit is contained in:
@@ -1,28 +1,28 @@
|
||||
use serde::Deserialize;
|
||||
use serde::{Deserialize, Serialize};
|
||||
use std::path::PathBuf;
|
||||
use std::fs;
|
||||
|
||||
#[derive(Debug, Deserialize, Clone)]
|
||||
#[derive(Debug, Deserialize, Serialize, Clone)]
|
||||
pub struct TlsConfig {
|
||||
pub enabled: bool,
|
||||
pub cert_path: PathBuf,
|
||||
pub key_path: PathBuf,
|
||||
}
|
||||
|
||||
#[derive(Debug, Deserialize, Clone)]
|
||||
#[derive(Debug, Deserialize, Serialize, Clone)]
|
||||
pub struct MaskingConfig {
|
||||
pub enabled: bool,
|
||||
pub headers: Vec<String>,
|
||||
}
|
||||
|
||||
#[derive(Debug, Deserialize, Clone)]
|
||||
#[derive(Debug, Deserialize, Serialize, Clone)]
|
||||
pub struct RouteConfig {
|
||||
pub path: String,
|
||||
pub response_file: PathBuf,
|
||||
pub status_code: u16,
|
||||
}
|
||||
|
||||
#[derive(Debug, Deserialize, Clone)]
|
||||
#[derive(Debug, Deserialize, Serialize, Clone)]
|
||||
pub struct Config {
|
||||
pub host: String,
|
||||
pub port: u16,
|
||||
@@ -41,7 +41,11 @@ impl Config {
|
||||
})
|
||||
}
|
||||
Err(_) => {
|
||||
Self::default()
|
||||
let default_config = Self::default();
|
||||
if let Ok(json) = serde_json::to_string_pretty(&default_config) {
|
||||
let _ = fs::write("config.json", json);
|
||||
}
|
||||
default_config
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -50,7 +54,7 @@ impl Config {
|
||||
impl Default for Config {
|
||||
fn default() -> Self {
|
||||
Self {
|
||||
host: "127.0.0.1".to_string(),
|
||||
host: "0.0.0.0".to_string(),
|
||||
port: 3000,
|
||||
routes: vec![RouteConfig {
|
||||
path: "/".to_string(),
|
||||
|
||||
@@ -47,7 +47,14 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
|
||||
.layer(axum_middleware::from_fn_with_state(state.clone(), logging_middleware))
|
||||
.with_state(state);
|
||||
|
||||
let addr: SocketAddr = format!("{}:{}", config.host, config.port).parse()?;
|
||||
let mut host = config.host.clone();
|
||||
|
||||
// In Docker, we usually want to bind to 0.0.0.0 to be accessible
|
||||
if std::env::var("DOCKER_CONTAINER").is_ok() {
|
||||
host = "0.0.0.0".to_string();
|
||||
}
|
||||
|
||||
let addr: SocketAddr = format!("{}:{}", host, config.port).parse()?;
|
||||
|
||||
// 4. Start server
|
||||
if config.tls.enabled {
|
||||
|
||||
Reference in New Issue
Block a user