Skip to content

Commit

Permalink
refactor: adjust admin web page
Browse files Browse the repository at this point in the history
  • Loading branch information
vicanso committed Mar 29, 2024
1 parent 8797d60 commit 75b936f
Show file tree
Hide file tree
Showing 21 changed files with 378 additions and 106 deletions.
8 changes: 8 additions & 0 deletions .github/workflows/publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,10 @@ jobs:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: setup node
uses: actions/setup-node@v4
- name: build-web
run: make build-web
- name: release
uses: addnab/docker-run-action@v3
with:
Expand All @@ -29,6 +33,10 @@ jobs:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: setup node
uses: actions/setup-node@v4
- name: build-web
run: make build-web
- name: release
uses: addnab/docker-run-action@v3
with:
Expand Down
4 changes: 4 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,10 @@ jobs:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: setup node
uses: actions/setup-node@v4
- name: build-web
run: make build-web
- name: release
uses: addnab/docker-run-action@v3
with:
Expand Down
48 changes: 24 additions & 24 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 4 additions & 4 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ description = "A reverse proxy like nginx"
license = "Apache-2.0"
homepage = "https://github.com/vicanso/pingap"
repository = "https://github.com/vicanso/pingap"
exclude = ["asset/*", "test/*", "Cargo.lock"]
exclude = ["asset/*", "test/*", "Cargo.lock", "web/*", "dist/*", ".github/*"]
readme = "./README.md"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

Expand All @@ -18,8 +18,8 @@ async-trait = "0.1.79"
base64 = "0.22.0"
bytes = "1.6.0"
bytesize = "1.3.0"
chrono = "0.4.35"
clap = { version = "4.5.3", features = ["derive"] }
chrono = "0.4.37"
clap = { version = "4.5.4", features = ["derive"] }
dirs = "5.0.1"
env_logger = "0.11.3"
futures-util = "0.3.30"
Expand All @@ -37,7 +37,7 @@ pingora = { version = "0.1.0", default-features = false, features = ["lb"] }
regex = "1.10.4"
rust-embed = { version = "8.3.0", features = ["mime-guess", "compression"] }
serde = "1.0.197"
serde_json = "1.0.114"
serde_json = "1.0.115"
snafu = "0.8.2"
substring = "1.4.5"
tempfile = "3.10.1"
Expand Down
7 changes: 4 additions & 3 deletions TODO.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@
- [x] support add tls
- [ ] log rotate
- [x] stats of server
- [ ] start without config
- [ ] static serve for admin
- [x] start without config
- [x] static serve for admin
- [ ] status:499 for client abort
- [ ] support get pingap start time
- [x] support get pingap start time
- [ ] custom error for pingora error
3 changes: 3 additions & 0 deletions conf/pingap.toml
Original file line number Diff line number Diff line change
Expand Up @@ -95,3 +95,6 @@ locations = ["lo"]

# Stats path for get the stats of server. Default `None`
stats_path = "/stats"

# Admin path for admin server. Default `None`
admin_path = "/admin"
1 change: 1 addition & 0 deletions docs/config_zh.md
Original file line number Diff line number Diff line change
Expand Up @@ -45,3 +45,4 @@ Pingap使用toml来配置相关参数,具体参数说明如下:
- `access_log`: 可选,默认为不输出访问日志。请求日志格式化,指定输出访问日志的形式。
- `locations`: location的列表,指定该server使用的所有location。
- `stats_path`: 可选,默认无。指定返回server的stats的路由。
- `admin_path`: 可选,默认无。指定用于转发至admin管理后台的路由。
1 change: 1 addition & 0 deletions src/config/load.rs
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,7 @@ pub struct ServerConf {
pub tls_cert: Option<String>,
pub tls_key: Option<String>,
pub stats_path: Option<String>,
pub admin_path: Option<String>,
}

impl ServerConf {
Expand Down
12 changes: 12 additions & 0 deletions src/config/mod.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
use once_cell::sync::Lazy;
use once_cell::sync::OnceCell;
use std::time::{Duration, SystemTime, UNIX_EPOCH};

mod load;

Expand All @@ -12,3 +14,13 @@ pub fn set_config_path(conf_path: &str) {
pub fn get_config_path() -> String {
CONFIG_PATH.get_or_init(|| "".to_string()).to_owned()
}

static START_TIME: Lazy<Duration> = Lazy::new(|| {
SystemTime::now()
.duration_since(UNIX_EPOCH)
.unwrap_or_default()
});

pub fn get_start_time() -> u64 {
START_TIME.as_secs()
}
2 changes: 2 additions & 0 deletions src/main.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
use crate::config::get_start_time;
use crate::proxy::{Server, ServerConf};
use clap::Parser;
use config::PingapConf;
Expand Down Expand Up @@ -116,6 +117,7 @@ fn run() -> Result<(), Box<dyn Error>> {
my_server.add_service(services.lb);
}
info!("server is running");
let _ = get_start_time();
my_server.run_forever();
Ok(())
}
Expand Down
Loading

0 comments on commit 75b936f

Please sign in to comment.