Skip to content

Commit 71095c4

Browse files
committed
Serve Ember bootstrap HTML for all non-api requests
The backend no longer checks for an "html" in the `Accept` header. With the exception of 3 session related routes, all paths not starting with "/api" will be redirected to the static Ember bootstrap page. As a result of this change all non-api requests that don't contain "html" in the `Accept` header will now unconditionally return `200`, rather than `404`. In a sense, this expands the scope of rust-lang#556 to all requests, not just those that set the header. It also inverts the problem described in rust-lang#788, effectively turning it into a duplicate of rust-lang#556. Fixes: rust-lang#163
1 parent 882749b commit 71095c4

File tree

2 files changed

+14
-13
lines changed

2 files changed

+14
-13
lines changed

src/middleware/ember_index_rewrite.rs

Lines changed: 12 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -25,21 +25,20 @@ impl AroundMiddleware for EmberIndexRewrite {
2525

2626
impl Handler for EmberIndexRewrite {
2727
fn call(&self, req: &mut dyn Request) -> Result<Response, Box<dyn Error + Send>> {
28-
// If the client is requesting html, then we've only got one page so
29-
// rewrite the request.
30-
let wants_html = req
31-
.headers()
32-
.find("Accept")
33-
.map(|accept| accept.iter().any(|s| s.contains("html")))
34-
.unwrap_or(false);
35-
// If the route starts with /api, just assume they want the API
36-
// response and fall through.
37-
let is_api_path = req.path().starts_with("/api");
3828
let handler = self.handler.as_ref().unwrap();
39-
if wants_html && !is_api_path {
40-
handler.call(&mut RequestProxy::rewrite_path(req, "/index.html"))
41-
} else {
29+
let is_backend_path = match req.path() {
30+
// Special case routes used for authentication
31+
"/authorize" | "/authorize_url" | "/logout" => true,
32+
// Paths starting with `/api` are intended for the backend
33+
path if path.starts_with("/api") => true,
34+
_ => false,
35+
};
36+
37+
if is_backend_path {
4238
handler.call(req)
39+
} else {
40+
// Serve static Ember page to bootstrap the frontend
41+
handler.call(&mut RequestProxy::rewrite_path(req, "/index.html"))
4342
}
4443
}
4544
}

src/router.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,8 @@ pub fn build_router(app: &App) -> R404 {
108108
router.head("/api/v1/*path", R(Arc::clone(&api_router)));
109109
router.delete("/api/v1/*path", R(api_router));
110110

111+
// These routes are special cased in the EmberIndexRewrite middleware.
112+
// Avoid adding new ones and keep in sync with the list there!
111113
router.get("/authorize_url", C(user::session::github_authorize));
112114
router.get("/authorize", C(user::session::github_access_token));
113115
router.delete("/logout", C(user::session::logout));

0 commit comments

Comments
 (0)