Skip to content

Commit e7bca95

Browse files
committed
Warn if application uses a reserved route
Signed-off-by: itowlson <[email protected]>
1 parent 0817a0e commit e7bca95

File tree

2 files changed

+14
-0
lines changed

2 files changed

+14
-0
lines changed

crates/http/src/routes.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,14 @@ impl Router {
141141
.map(|(_spec, handler)| (&handler.parsed_based_route, &handler.component_id))
142142
}
143143

144+
/// true if one or more routes is under the reserved `/.well-known/spin/*`
145+
/// prefix; otherwise false.
146+
pub fn contains_reserved_route(&self) -> bool {
147+
self.router
148+
.iter()
149+
.any(|(_spec, handker)| handker.based_route.starts_with(crate::WELL_KNOWN_PREFIX))
150+
}
151+
144152
/// This returns the component ID that should handle the given path, or an error
145153
/// if no component matches.
146154
///

crates/trigger-http/src/server.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,12 @@ impl<F: RuntimeFactors> HttpServer<F> {
9090
);
9191
}
9292
}
93+
if router.contains_reserved_route() {
94+
tracing::error!(
95+
"Routes under {} are handled by the Spin runtime and will never be reached",
96+
spin_http::WELL_KNOWN_PREFIX
97+
);
98+
}
9399
tracing::trace!(
94100
"Constructed router: {:?}",
95101
router.routes().collect::<Vec<_>>()

0 commit comments

Comments
 (0)