Skip to content

Commit

Permalink
Warn if application uses a reserved route
Browse files Browse the repository at this point in the history
Signed-off-by: itowlson <[email protected]>
  • Loading branch information
itowlson committed Jan 22, 2025
1 parent 0817a0e commit e7bca95
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 0 deletions.
8 changes: 8 additions & 0 deletions crates/http/src/routes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,14 @@ impl Router {
.map(|(_spec, handler)| (&handler.parsed_based_route, &handler.component_id))
}

/// true if one or more routes is under the reserved `/.well-known/spin/*`
/// prefix; otherwise false.
pub fn contains_reserved_route(&self) -> bool {
self.router
.iter()
.any(|(_spec, handker)| handker.based_route.starts_with(crate::WELL_KNOWN_PREFIX))
}

/// This returns the component ID that should handle the given path, or an error
/// if no component matches.
///
Expand Down
6 changes: 6 additions & 0 deletions crates/trigger-http/src/server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,12 @@ impl<F: RuntimeFactors> HttpServer<F> {
);
}
}
if router.contains_reserved_route() {
tracing::error!(
"Routes under {} are handled by the Spin runtime and will never be reached",
spin_http::WELL_KNOWN_PREFIX
);
}
tracing::trace!(
"Constructed router: {:?}",
router.routes().collect::<Vec<_>>()
Expand Down

0 comments on commit e7bca95

Please sign in to comment.