Skip to content

Commit

Permalink
fix: extract routes
Browse files Browse the repository at this point in the history
  • Loading branch information
blelump committed Dec 5, 2024
1 parent c3d1049 commit e5e2ea2
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 41 deletions.
38 changes: 38 additions & 0 deletions components/watcher/src/http_routing.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
use crate::watcher_listener::http_handlers;
use actix_web::web;

pub fn configure_routes(cfg: &mut web::ServiceConfig) {
cfg.route(
"/introduce",
actix_web::web::get().to(http_handlers::introduce),
)
.route(
"/oobi/{id}",
actix_web::web::get().to(http_handlers::resolve_location),
)
.route(
"/oobi/{cid}/{role}/{eid}",
actix_web::web::get().to(http_handlers::resolve_role),
)
.route(
"/process",
actix_web::web::post().to(http_handlers::process_notice),
)
.route(
"/query",
actix_web::web::post().to(http_handlers::process_query),
)
.route(
"/register",
actix_web::web::post().to(http_handlers::process_reply),
)
.route(
"/resolve",
actix_web::web::post().to(http_handlers::resolve_oobi),
)
.route(
"/query/tel",
actix_web::web::post().to(http_handlers::process_tel_query),
)
.route("info", actix_web::web::get().to(http_handlers::info));
}
1 change: 1 addition & 0 deletions components/watcher/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ pub use crate::{
watcher_listener::WatcherListener,
};

mod http_routing;
#[cfg(test)]
mod test;
mod watcher;
Expand Down
47 changes: 6 additions & 41 deletions components/watcher/src/watcher_listener.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
use crate::http_routing::configure_routes;
use std::{net::ToSocketAddrs, sync::Arc};

use actix_web::{dev::Server, web, App, HttpServer};
Expand Down Expand Up @@ -27,42 +28,7 @@ impl WatcherListener {
HttpServer::new(move || {
App::new()
.app_data(state.clone())
.route(
"/introduce",
actix_web::web::get().to(http_handlers::introduce),
)
.route(
"/oobi/{id}",
actix_web::web::get().to(http_handlers::resolve_location),
)
.route(
"/oobi/{cid}/{role}/{eid}",
actix_web::web::get().to(http_handlers::resolve_role),
)
.route(
"/process",
actix_web::web::post().to(http_handlers::process_notice),
)
.route(
"/query",
actix_web::web::post().to(http_handlers::process_query),
)
.route(
"/register",
actix_web::web::post().to(http_handlers::process_reply),
)
.route(
"/resolve",
actix_web::web::post().to(http_handlers::resolve_oobi),
)
.route(
"/query/tel",
actix_web::web::post().to(http_handlers::process_tel_query),
)
.route(
"info",
actix_web::web::get().to(http_handlers::info),
)
.configure(configure_routes)
})
.disable_signals()
.bind(addr)
Expand Down Expand Up @@ -99,7 +65,8 @@ pub mod http_handlers {
use std::sync::Arc;

use actix_web::{
http::{header::ContentType, StatusCode}, web, HttpResponse, Responder, ResponseError
http::{header::ContentType, StatusCode},
web, HttpResponse, Responder, ResponseError,
};
use itertools::Itertools;
use keri_core::{
Expand Down Expand Up @@ -273,17 +240,15 @@ pub mod http_handlers {
}
}

pub async fn info(
) -> impl Responder {
pub async fn info() -> impl Responder {
let version = option_env!("CARGO_PKG_VERSION");
if let Some(version) = version {
HttpResponse::Ok().json(serde_json::json!({ "version": version }))
} else {
HttpResponse::InternalServerError()
.json(serde_json::json!({ "error": "Failed to retrieve version information" }))
}

}
}
}

mod test {
Expand Down

0 comments on commit e5e2ea2

Please # to comment.