chore: bump to 0.2.0

This commit is contained in:
xfy
2025-06-17 23:35:50 +08:00
parent 88098dca5c
commit 61934b6c0d
8 changed files with 19 additions and 46 deletions

View File

@ -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

2
Cargo.lock generated
View File

@ -371,7 +371,7 @@ checksum = "d71b6127be86fdcfddb610f7182ac57211d4b18a3e9c82eb2d17662f2227ad6a"
[[package]]
name = "candy"
version = "0.1.1"
version = "0.2.0"
dependencies = [
"anyhow",
"axum",

View File

@ -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

View File

@ -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/"

View File

@ -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"

View File

@ -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": <SettingRoute>
/// }
#[serde(skip)]
pub route_map: DashMap<String, SettingRoute>,
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<HeaderMap>,
}
pub type MIMEType = DashMap<Cow<'static, str>, 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<SettingHost>,
}

View File

@ -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

View File

@ -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())