From 61934b6c0dc9b8437327439f32bb52642450327b Mon Sep 17 00:00:00 2001 From: xfy Date: Tue, 17 Jun 2025 23:35:50 +0800 Subject: [PATCH] chore: bump to 0.2.0 --- CHANGELOG.md | 3 ++- Cargo.lock | 2 +- Cargo.toml | 2 +- config.example.toml | 10 ++++++++-- config.example_full.toml | 8 ++------ src/config.rs | 17 +++-------------- src/consts.rs | 22 +--------------------- src/http/mod.rs | 1 + 8 files changed, 19 insertions(+), 46 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 0c3c0d8..3d0f06a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,12 +6,13 @@ Features: - Reverse proxy - Refactor with axum +- SSL support ## 0.1.1 Features: -- Gitlab CI integration +- GitLab CI integration - FreeBSD support - Reverse proxy - Connection timeout diff --git a/Cargo.lock b/Cargo.lock index 518e465..9219e1c 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -371,7 +371,7 @@ checksum = "d71b6127be86fdcfddb610f7182ac57211d4b18a3e9c82eb2d17662f2227ad6a" [[package]] name = "candy" -version = "0.1.1" +version = "0.2.0" dependencies = [ "anyhow", "axum", diff --git a/Cargo.toml b/Cargo.toml index c2dc504..4a92351 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -2,7 +2,7 @@ cargo-features = ["profile-rustflags", "trim-paths"] [package] name = "candy" -version = "0.1.1" +version = "0.2.0" edition = "2024" # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html diff --git a/config.example.toml b/config.example.toml index 790d492..168bedf 100644 --- a/config.example.toml +++ b/config.example.toml @@ -1,9 +1,15 @@ [[host]] ip = "0.0.0.0" -port = 4000 - +port = 80 [[host.route]] # route path: GET / location = "/" # static file path root = "./html" + +[[host]] +ip = "0.0.0.0" +port = 8080 +[[host.route]] +location = "/" +proxy_pass = "https://www.google.com/" diff --git a/config.example_full.toml b/config.example_full.toml index 916b524..0bf35f1 100644 --- a/config.example_full.toml +++ b/config.example_full.toml @@ -1,9 +1,3 @@ -# Default file type for unknow file -default_type = "application/octet-stream" -# Custom MIME types -[types] -wasm = "application/wasm" - # Virtual host [[host]] ip = "0.0.0.0" @@ -11,6 +5,8 @@ port = 4000 # Connection timeout timeout = 15 # SSL certificate +# ssl enable +# ssl = true # Self sign a certificate # sudo openssl req -x509 -nodes -days 365 -newkey rsa:2048 -keyout ./html/selfsigned.key -out ./html/selfsigned.crt certificate = "./html/selfsigned.crt" diff --git a/src/config.rs b/src/config.rs index 08cd4e8..3cc5413 100644 --- a/src/config.rs +++ b/src/config.rs @@ -1,11 +1,8 @@ use crate::{ - consts::{ - default_disabled, host_index, mime_default, timeout_default, types_default, - upstream_timeout_default, - }, + consts::{default_disabled, host_index, timeout_default, upstream_timeout_default}, error::Result, }; -use std::{borrow::Cow, fs}; +use std::fs; use anyhow::Context; use dashmap::DashMap; @@ -69,7 +66,7 @@ pub struct SettingHost { /// "/doc": /// } #[serde(skip)] - pub route_map: DashMap, + pub route_map: HostRouteMap, /// HTTP keep-alive timeout #[serde(default = "timeout_default")] pub timeout: u16, @@ -78,17 +75,9 @@ pub struct SettingHost { pub headers: Option, } -pub type MIMEType = DashMap, Cow<'static, str>>; - /// Whole config settings #[derive(Deserialize, Clone, Debug, Default)] pub struct Settings { - /// Default file type for unknow file - #[serde(default = "mime_default")] - pub default_type: Cow<'static, str>, - /// MIME types - #[serde(default = "types_default")] - pub types: MIMEType, /// Virtual host pub host: Vec, } diff --git a/src/consts.rs b/src/consts.rs index 57b5087..9e505c9 100644 --- a/src/consts.rs +++ b/src/consts.rs @@ -1,8 +1,4 @@ -use std::{borrow::Cow, env}; - -use dashmap::DashMap; - -use crate::config::MIMEType; +use std::env; // pre defined pub const NAME: &str = env!("CARGO_PKG_NAME"); @@ -24,28 +20,12 @@ pub fn timeout_default() -> u16 { TIMEOUT_EFAULT } -// default mime type for unknow file -pub const MIME_DEFAULT: &str = "application/octet-stream"; -pub fn mime_default() -> Cow<'static, str> { - MIME_DEFAULT.into() -} - // default reverse proxy upstream timeout pub const UPSTREAM_TIMEOUT: u16 = 5; pub fn upstream_timeout_default() -> u16 { UPSTREAM_TIMEOUT } -// default mime types -pub fn types_default() -> MIMEType { - DashMap::new() -} -// macro_rules! insert_mime { -// ($name:literal, $mime:ident, $map:ident) => { -// $map.entry($name.into()).or_insert($mime.into()); -// }; -// } - // default boolean false pub fn default_disabled() -> bool { false diff --git a/src/http/mod.rs b/src/http/mod.rs index da57f88..29b86e0 100644 --- a/src/http/mod.rs +++ b/src/http/mod.rs @@ -150,6 +150,7 @@ pub async fn make_server(host: SettingHost) -> anyhow::Result<()> { .serve(router.into_make_service()) .await?; } else { + info!("listening on http://{}", addr); axum_server::bind(addr) .handle(handle) .serve(router.into_make_service())