mirror of
https://github.com/DefectingCat/candy
synced 2025-07-15 08:41:35 +00:00
chore: bump to 0.2.0
This commit is contained in:
@ -6,12 +6,13 @@ Features:
|
|||||||
|
|
||||||
- Reverse proxy
|
- Reverse proxy
|
||||||
- Refactor with axum
|
- Refactor with axum
|
||||||
|
- SSL support
|
||||||
|
|
||||||
## 0.1.1
|
## 0.1.1
|
||||||
|
|
||||||
Features:
|
Features:
|
||||||
|
|
||||||
- Gitlab CI integration
|
- GitLab CI integration
|
||||||
- FreeBSD support
|
- FreeBSD support
|
||||||
- Reverse proxy
|
- Reverse proxy
|
||||||
- Connection timeout
|
- Connection timeout
|
||||||
|
2
Cargo.lock
generated
2
Cargo.lock
generated
@ -371,7 +371,7 @@ checksum = "d71b6127be86fdcfddb610f7182ac57211d4b18a3e9c82eb2d17662f2227ad6a"
|
|||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "candy"
|
name = "candy"
|
||||||
version = "0.1.1"
|
version = "0.2.0"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"anyhow",
|
"anyhow",
|
||||||
"axum",
|
"axum",
|
||||||
|
@ -2,7 +2,7 @@ cargo-features = ["profile-rustflags", "trim-paths"]
|
|||||||
|
|
||||||
[package]
|
[package]
|
||||||
name = "candy"
|
name = "candy"
|
||||||
version = "0.1.1"
|
version = "0.2.0"
|
||||||
edition = "2024"
|
edition = "2024"
|
||||||
|
|
||||||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||||
|
@ -1,9 +1,15 @@
|
|||||||
[[host]]
|
[[host]]
|
||||||
ip = "0.0.0.0"
|
ip = "0.0.0.0"
|
||||||
port = 4000
|
port = 80
|
||||||
|
|
||||||
[[host.route]]
|
[[host.route]]
|
||||||
# route path: GET /
|
# route path: GET /
|
||||||
location = "/"
|
location = "/"
|
||||||
# static file path
|
# static file path
|
||||||
root = "./html"
|
root = "./html"
|
||||||
|
|
||||||
|
[[host]]
|
||||||
|
ip = "0.0.0.0"
|
||||||
|
port = 8080
|
||||||
|
[[host.route]]
|
||||||
|
location = "/"
|
||||||
|
proxy_pass = "https://www.google.com/"
|
||||||
|
@ -1,9 +1,3 @@
|
|||||||
# Default file type for unknow file
|
|
||||||
default_type = "application/octet-stream"
|
|
||||||
# Custom MIME types
|
|
||||||
[types]
|
|
||||||
wasm = "application/wasm"
|
|
||||||
|
|
||||||
# Virtual host
|
# Virtual host
|
||||||
[[host]]
|
[[host]]
|
||||||
ip = "0.0.0.0"
|
ip = "0.0.0.0"
|
||||||
@ -11,6 +5,8 @@ port = 4000
|
|||||||
# Connection timeout
|
# Connection timeout
|
||||||
timeout = 15
|
timeout = 15
|
||||||
# SSL certificate
|
# SSL certificate
|
||||||
|
# ssl enable
|
||||||
|
# ssl = true
|
||||||
# Self sign a certificate
|
# Self sign a certificate
|
||||||
# sudo openssl req -x509 -nodes -days 365 -newkey rsa:2048 -keyout ./html/selfsigned.key -out ./html/selfsigned.crt
|
# sudo openssl req -x509 -nodes -days 365 -newkey rsa:2048 -keyout ./html/selfsigned.key -out ./html/selfsigned.crt
|
||||||
certificate = "./html/selfsigned.crt"
|
certificate = "./html/selfsigned.crt"
|
||||||
|
@ -1,11 +1,8 @@
|
|||||||
use crate::{
|
use crate::{
|
||||||
consts::{
|
consts::{default_disabled, host_index, timeout_default, upstream_timeout_default},
|
||||||
default_disabled, host_index, mime_default, timeout_default, types_default,
|
|
||||||
upstream_timeout_default,
|
|
||||||
},
|
|
||||||
error::Result,
|
error::Result,
|
||||||
};
|
};
|
||||||
use std::{borrow::Cow, fs};
|
use std::fs;
|
||||||
|
|
||||||
use anyhow::Context;
|
use anyhow::Context;
|
||||||
use dashmap::DashMap;
|
use dashmap::DashMap;
|
||||||
@ -69,7 +66,7 @@ pub struct SettingHost {
|
|||||||
/// "/doc": <SettingRoute>
|
/// "/doc": <SettingRoute>
|
||||||
/// }
|
/// }
|
||||||
#[serde(skip)]
|
#[serde(skip)]
|
||||||
pub route_map: DashMap<String, SettingRoute>,
|
pub route_map: HostRouteMap,
|
||||||
/// HTTP keep-alive timeout
|
/// HTTP keep-alive timeout
|
||||||
#[serde(default = "timeout_default")]
|
#[serde(default = "timeout_default")]
|
||||||
pub timeout: u16,
|
pub timeout: u16,
|
||||||
@ -78,17 +75,9 @@ pub struct SettingHost {
|
|||||||
pub headers: Option<HeaderMap>,
|
pub headers: Option<HeaderMap>,
|
||||||
}
|
}
|
||||||
|
|
||||||
pub type MIMEType = DashMap<Cow<'static, str>, Cow<'static, str>>;
|
|
||||||
|
|
||||||
/// Whole config settings
|
/// Whole config settings
|
||||||
#[derive(Deserialize, Clone, Debug, Default)]
|
#[derive(Deserialize, Clone, Debug, Default)]
|
||||||
pub struct Settings {
|
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
|
/// Virtual host
|
||||||
pub host: Vec<SettingHost>,
|
pub host: Vec<SettingHost>,
|
||||||
}
|
}
|
||||||
|
@ -1,8 +1,4 @@
|
|||||||
use std::{borrow::Cow, env};
|
use std::env;
|
||||||
|
|
||||||
use dashmap::DashMap;
|
|
||||||
|
|
||||||
use crate::config::MIMEType;
|
|
||||||
|
|
||||||
// pre defined
|
// pre defined
|
||||||
pub const NAME: &str = env!("CARGO_PKG_NAME");
|
pub const NAME: &str = env!("CARGO_PKG_NAME");
|
||||||
@ -24,28 +20,12 @@ pub fn timeout_default() -> u16 {
|
|||||||
TIMEOUT_EFAULT
|
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
|
// default reverse proxy upstream timeout
|
||||||
pub const UPSTREAM_TIMEOUT: u16 = 5;
|
pub const UPSTREAM_TIMEOUT: u16 = 5;
|
||||||
pub fn upstream_timeout_default() -> u16 {
|
pub fn upstream_timeout_default() -> u16 {
|
||||||
UPSTREAM_TIMEOUT
|
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
|
// default boolean false
|
||||||
pub fn default_disabled() -> bool {
|
pub fn default_disabled() -> bool {
|
||||||
false
|
false
|
||||||
|
@ -150,6 +150,7 @@ pub async fn make_server(host: SettingHost) -> anyhow::Result<()> {
|
|||||||
.serve(router.into_make_service())
|
.serve(router.into_make_service())
|
||||||
.await?;
|
.await?;
|
||||||
} else {
|
} else {
|
||||||
|
info!("listening on http://{}", addr);
|
||||||
axum_server::bind(addr)
|
axum_server::bind(addr)
|
||||||
.handle(handle)
|
.handle(handle)
|
||||||
.serve(router.into_make_service())
|
.serve(router.into_make_service())
|
||||||
|
Reference in New Issue
Block a user