aboutsummaryrefslogtreecommitdiff
path: root/src/lib.rs
diff options
context:
space:
mode:
authorFuwn <[email protected]>2022-03-20 02:28:29 -0700
committerFuwn <[email protected]>2022-03-20 02:28:29 -0700
commitaba6f24079d5d41eb193f41f2c490e4d13a69405 (patch)
treed98b7dd0da2b71fdccb548fb10ef5d5c21ac578a /src/lib.rs
parentMerge branch 'main' of https://github.com/senpy-club/api-worker (diff)
downloadapi-worker-aba6f24079d5d41eb193f41f2c490e4d13a69405.tar.xz
api-worker-aba6f24079d5d41eb193f41f2c490e4d13a69405.zip
feat(api): /me route
Diffstat (limited to 'src/lib.rs')
-rw-r--r--src/lib.rs9
1 files changed, 8 insertions, 1 deletions
diff --git a/src/lib.rs b/src/lib.rs
index 6f86f33..2287e89 100644
--- a/src/lib.rs
+++ b/src/lib.rs
@@ -35,6 +35,7 @@ mod routes;
mod structures;
mod utils;
+use serde_json::json;
use worker::Response;
/// # Errors
@@ -63,12 +64,18 @@ pub async fn main(
})
.get_async("/v2/random", |_, _| async move { routes::random().await })
.get("/v2/version", |_, _| {
- Response::from_json(&serde_json::json!({
+ Response::from_json(&json!({
"crate_version": env!("CARGO_PKG_VERSION"),
"git_commit_hash": env!("VERGEN_GIT_SHA"),
}))?
.with_cors(&utils::cors())
})
+ .get("/v2/me", |req, _| {
+ Response::from_json(&json!({
+ "ip": req.clone().unwrap().headers().get("CF-Connecting-IP").unwrap().unwrap(),
+ }))?
+ .with_cors(&utils::cors())
+ })
.run(request, environment)
.await
}