Skip to content

Commit

Permalink
move old proxied routes to using middleware
Browse files Browse the repository at this point in the history
  • Loading branch information
arik-so committed Jan 28, 2025
1 parent 65465b0 commit f3886f0
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 30 deletions.
12 changes: 6 additions & 6 deletions src/subcommand/server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -260,12 +260,6 @@ impl Server {
"/r/children/{inscription_id}/inscriptions/{page}",
get(r::children_inscriptions_paginated),
)
.route(
"/r/children/{inscription_id}/{page}",
get(r::children_paginated),
)
.route("/r/inscription/{inscription_id}", get(r::inscription))
.route("/r/metadata/{inscription_id}", get(r::metadata))
.route("/r/parents/{inscription_id}", get(r::parents))
.route(
"/r/parents/{inscription_id}/{page}",
Expand All @@ -286,6 +280,12 @@ impl Server {

let proxy_routes = Router::new()
.route("/content/{inscription_id}", get(r::content))
.route(
"/r/children/{inscription_id}/{page}",
get(r::children_paginated),
)
.route("/r/inscription/{inscription_id}", get(r::inscription))
.route("/r/metadata/{inscription_id}", get(r::metadata))
.route("/r/sat/{sat_number}/at/{index}", get(r::sat_at_index));

async fn proxy_fallback(
Expand Down
36 changes: 12 additions & 24 deletions src/subcommand/server/r.rs
Original file line number Diff line number Diff line change
Expand Up @@ -225,14 +225,10 @@ pub(super) async fn children_paginated(
) -> ServerResult {
task::block_in_place(|| {
let Some(parent) = index.get_inscription_entry(parent)? else {
return if let Some(proxy) = server_config.proxy.as_ref() {
Server::proxy(proxy, &format!("r/children/{}/{}", parent, page))
} else {
Err(ServerError::NotFound(format!(
"inscription {} not found",
parent
)))
};
return Err(ServerError::NotFound(format!(
"inscription {} not found",
parent
)));
};

let parent_sequence_number = parent.sequence_number;
Expand Down Expand Up @@ -353,14 +349,10 @@ pub(super) async fn inscription(
) -> ServerResult {
task::block_in_place(|| {
let Some(inscription) = index.get_inscription_by_id(inscription_id)? else {
return if let Some(proxy) = server_config.proxy.as_ref() {
Server::proxy(proxy, &format!("r/inscription/{}", inscription_id))
} else {
Err(ServerError::NotFound(format!(
"inscription {} not found",
inscription_id
)))
};
return Err(ServerError::NotFound(format!(
"inscription {} not found",
inscription_id
)));
};

let entry = index
Expand Down Expand Up @@ -425,14 +417,10 @@ pub(super) async fn metadata(
) -> ServerResult {
task::block_in_place(|| {
let Some(inscription) = index.get_inscription_by_id(inscription_id)? else {
return if let Some(proxy) = server_config.proxy.as_ref() {
Server::proxy(proxy, &format!("r/metadata/{}", inscription_id))
} else {
Err(ServerError::NotFound(format!(
"inscription {} not found",
inscription_id
)))
};
return Err(ServerError::NotFound(format!(
"inscription {} not found",
inscription_id
)));
};

let metadata = inscription
Expand Down

0 comments on commit f3886f0

Please sign in to comment.