mirror of
https://codeberg.org/YGGverse/psocks.git
synced 2026-03-31 16:35:28 +00:00
create namespace for json api; make temporarily index page reference to api/totals
This commit is contained in:
parent
24cbc3012e
commit
06228c577f
2 changed files with 15 additions and 7 deletions
18
src/main.rs
18
src/main.rs
|
|
@ -18,11 +18,16 @@ use tokio::{net::TcpListener, task};
|
|||
|
||||
#[rocket::get("/")]
|
||||
async fn index(totals: &State<Arc<Total>>, startup_time: &State<Instant>) -> Json<Snap> {
|
||||
Json(totals.inner().snap(startup_time.elapsed().as_secs())) // @TODO implement Web UI
|
||||
}
|
||||
|
||||
#[rocket::get("/api/totals")]
|
||||
async fn api_totals(totals: &State<Arc<Total>>, startup_time: &State<Instant>) -> Json<Snap> {
|
||||
Json(totals.inner().snap(startup_time.elapsed().as_secs()))
|
||||
}
|
||||
|
||||
#[rocket::get("/allow/<rule>")]
|
||||
async fn allow(
|
||||
#[rocket::get("/api/allow/<rule>")]
|
||||
async fn api_allow(
|
||||
rule: &str,
|
||||
list: &State<Arc<List>>,
|
||||
totals: &State<Arc<Total>>,
|
||||
|
|
@ -36,8 +41,8 @@ async fn allow(
|
|||
})?))
|
||||
}
|
||||
|
||||
#[rocket::get("/block/<rule>")]
|
||||
async fn block(
|
||||
#[rocket::get("/api/block/<rule>")]
|
||||
async fn api_block(
|
||||
rule: &str,
|
||||
list: &State<Arc<List>>,
|
||||
totals: &State<Arc<Total>>,
|
||||
|
|
@ -84,7 +89,10 @@ async fn rocket() -> _ {
|
|||
.manage(list)
|
||||
.manage(totals)
|
||||
.manage(Instant::now())
|
||||
.mount("/", rocket::routes![index, allow, block])
|
||||
.mount(
|
||||
"/",
|
||||
rocket::routes![index, api_totals, api_allow, api_block],
|
||||
)
|
||||
}
|
||||
|
||||
async fn spawn_socks_server(opt: &'static Opt, list: Arc<List>, totals: Arc<Total>) -> Result<()> {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue