Skip to content

Commit 88e2a35

Browse files
committed
serve console index at /settings/*
1 parent 4b133fa commit 88e2a35

File tree

1 file changed

+30
-21
lines changed

1 file changed

+30
-21
lines changed

nexus/src/external_api/console_api.rs

Lines changed: 30 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -558,6 +558,24 @@ pub async fn session_me(
558558
apictx.external_latencies.instrument_dropshot_handler(&rqctx, handler).await
559559
}
560560

561+
async fn console_page_inner(
562+
rqctx: Arc<RequestContext<Arc<ServerContext>>>,
563+
) -> Result<Response<Body>, HttpError> {
564+
let opctx = OpContext::for_external_api(&rqctx).await;
565+
566+
if let Ok(opctx) = opctx {
567+
if opctx.authn.actor().is_some() {
568+
return serve_console_index(rqctx.context()).await;
569+
}
570+
}
571+
572+
// otherwise redirect to idp
573+
Ok(Response::builder()
574+
.status(StatusCode::FOUND)
575+
.header(http::header::LOCATION, get_login_url(None))
576+
.body("".into())?)
577+
}
578+
561579
// Dropshot does not have route match ranking and does not allow overlapping
562580
// route definitions, so we cannot have a catchall `/*` route for console pages
563581
// and then also define, e.g., `/api/blah/blah` and give the latter priority
@@ -575,28 +593,19 @@ pub async fn console_page(
575593
rqctx: Arc<RequestContext<Arc<ServerContext>>>,
576594
_path_params: Path<RestPathParam>,
577595
) -> Result<Response<Body>, HttpError> {
578-
let opctx = OpContext::for_external_api(&rqctx).await;
579-
580-
// if authed, serve HTML page with bundle in script tag
581-
582-
// HTML doesn't need to be static -- we'll probably find a reason to do some
583-
// minimal templating, e.g., putting a CSRF token in the page
584-
585-
// amusingly, at least to start out, I don't think we care about the path
586-
// because the real routing is all client-side. we serve the same HTML
587-
// regardless, the app starts on the client and renders the right page and
588-
// makes the right API requests.
589-
if let Ok(opctx) = opctx {
590-
if opctx.authn.actor().is_some() {
591-
return serve_console_index(rqctx.context()).await;
592-
}
593-
}
596+
console_page_inner(rqctx).await
597+
}
594598

595-
// otherwise redirect to idp
596-
Ok(Response::builder()
597-
.status(StatusCode::FOUND)
598-
.header(http::header::LOCATION, get_login_url(None))
599-
.body("".into())?)
599+
#[endpoint {
600+
method = GET,
601+
path = "/settings/{path:.*}",
602+
unpublished = true,
603+
}]
604+
pub async fn console_settings_page(
605+
rqctx: Arc<RequestContext<Arc<ServerContext>>>,
606+
_path_params: Path<RestPathParam>,
607+
) -> Result<Response<Body>, HttpError> {
608+
console_page_inner(rqctx).await
600609
}
601610

602611
/// Fetch a static asset from `<static_dir>/assets`. 404 on virtually all

0 commit comments

Comments
 (0)