Skip to content

Commit

Permalink
Merge pull request quarkusio#39611 from phillip-kruger/dev-ui-endpoin…
Browse files Browse the repository at this point in the history
…ts-update

Update Dev UI Endpoints page to use new NotFoundHandler
  • Loading branch information
FroMage authored Mar 21, 2024
2 parents 937f4ba + f640a66 commit 3650cb4
Show file tree
Hide file tree
Showing 8 changed files with 175 additions and 183 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,6 @@ public class TemplateHtmlBuilder {

private static final String RESOURCES_START = "<div class=\"intro\">%1$s</div><div class=\"resources\">";

private static final String ANCHOR_TEMPLATE = "<a href=\"/%1$s\">/%2$s</a>";
private static final String ANCHOR_TEMPLATE_ABSOLUTE = "<a href=\"%1$s\">%2$s</a>";

private static final String DESCRIPTION_TEMPLATE = "%1$s — %2$s";
Expand Down Expand Up @@ -247,10 +246,10 @@ public TemplateHtmlBuilder servletMapping(String title) {
private TemplateHtmlBuilder resourcePath(String title, boolean withListStart, boolean withAnchor, String description) {
String content;
if (withAnchor) {
String text = title;
if (title.startsWith("/")) {
title = title.substring(1);
}
String text = title;

if (!title.startsWith("http") && baseUrl != null) {
title = baseUrl + title;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@ void registerDevUiHandlers(
.handler(uihandler);

if (route.endsWith(DEVUI + SLASH)) {
builder = builder.displayOnNotFoundPage("Dev UI (v2)");
builder = builder.displayOnNotFoundPage("Dev UI");
routeProducer.produce(builder.build());
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,41 +1,17 @@
package io.quarkus.devui.deployment.menu;

import static io.quarkus.deployment.annotations.ExecutionTime.STATIC_INIT;

import java.util.List;
import java.util.stream.Collectors;

import io.quarkus.deployment.IsDevelopment;
import io.quarkus.deployment.annotations.BuildStep;
import io.quarkus.deployment.annotations.Record;
import io.quarkus.devui.deployment.InternalPageBuildItem;
import io.quarkus.devui.runtime.DevUIRecorder;
import io.quarkus.devui.runtime.EndpointInfo;
import io.quarkus.devui.spi.page.Page;
import io.quarkus.vertx.http.deployment.HttpRootPathBuildItem;
import io.quarkus.vertx.http.deployment.NonApplicationRootPathBuildItem;
import io.quarkus.vertx.http.deployment.devmode.NotFoundPageDisplayableEndpointBuildItem;

/**
* This creates Endpoints Page
*/
public class EndpointsProcessor {
private static final String DEVUI = "dev-ui";

@Record(STATIC_INIT)
@BuildStep(onlyIf = IsDevelopment.class)
void addEndpointInfos(List<NotFoundPageDisplayableEndpointBuildItem> displayableEndpoints,
DevUIRecorder recorder, HttpRootPathBuildItem httpRoot) {

List<EndpointInfo> endpoints = displayableEndpoints
.stream()
.map(v -> new EndpointInfo(v.getEndpoint(httpRoot), v.getDescription()))
.sorted()
.collect(Collectors.toList());

recorder.setEndpoints(endpoints);
}

@BuildStep(onlyIf = IsDevelopment.class)
InternalPageBuildItem createEndpointsPage(NonApplicationRootPathBuildItem nonApplicationRootPathBuildItem) {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ export class QwcEndpoints extends LitElement {
static styles = css`
.infogrid {
width: 99%;
height: 99%;
}
a {
cursor: pointer;
Expand All @@ -37,7 +36,7 @@ export class QwcEndpoints extends LitElement {
`;

static properties = {
_info: {state: true},
_info: {state: true}
}

constructor() {
Expand All @@ -51,19 +50,37 @@ export class QwcEndpoints extends LitElement {
}

async load() {
const response = await fetch(basepath + "/endpoints/endpoints.json");
const response = await fetch("/quarkus404", {
method: 'GET',
headers: {
'Accept': 'application/json'
}
});
const data = await response.json();
this._info = data;
}

render() {
if (this._info) {
const items = [];
for (const [key, value] of Object.entries(this._info)) {
items.push({"uri" : key, "description": value});
}

return html`<vaadin-grid .items="${items}" class="infogrid">
const typeTemplates = [];
for (const [type, list] of Object.entries(this._info)) {
typeTemplates.push(html`${this._renderType(type,list)}`);
}
return html`${typeTemplates}`;
}else{
return html`
<div style="color: var(--lumo-secondary-text-color);width: 95%;" >
<div>Fetching information...</div>
<vaadin-progress-bar indeterminate></vaadin-progress-bar>
</div>
`;
}
}

_renderType(type, items){
return html`<h3>${type}</h3>
<vaadin-grid .items="${items}" class="infogrid" all-rows-visible>
<vaadin-grid-sort-column header='URL'
path="uri"
${columnBodyRenderer(this._uriRenderer, [])}>
Expand All @@ -75,14 +92,6 @@ export class QwcEndpoints extends LitElement {
${columnBodyRenderer(this._descriptionRenderer, [])}>
</vaadin-grid-sort-column>
</vaadin-grid>`;
}else{
return html`
<div style="color: var(--lumo-secondary-text-color);width: 95%;" >
<div>Fetching information...</div>
<vaadin-progress-bar indeterminate></vaadin-progress-bar>
</div>
`;
}
}

_uriRenderer(endpoint) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -93,10 +93,6 @@ public Handler<RoutingContext> endpointInfoHandler(String basePath) {
return new EndpointInfoHandler(basePath);
}

public void setEndpoints(List<EndpointInfo> endpointInfos) {
EndpointInfoHandler.setEndpoints(endpointInfos);
}

public Handler<RoutingContext> vaadinRouterHandler(String basePath) {
return new VaadinRouterHandler(basePath);
}
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,26 +1,16 @@
package io.quarkus.devui.runtime;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import jakarta.enterprise.inject.spi.CDI;

import io.vertx.core.Handler;
import io.vertx.core.json.Json;
import io.vertx.core.json.JsonArray;
import io.vertx.core.json.JsonObject;
import io.vertx.ext.web.RoutingContext;

/**
* Handler to return the endpoint info
*/
public class EndpointInfoHandler implements Handler<RoutingContext> {
private static volatile List<EndpointInfo> endpointInfos;

static void setEndpoints(List<EndpointInfo> endpointInfos) {
EndpointInfoHandler.endpointInfos = endpointInfos;
}

private String basePath; // Like /q/dev-ui

Expand All @@ -47,14 +37,7 @@ public void handle(RoutingContext event) {
int si = normalizedPath.lastIndexOf(SLASH) + 1;
String path = normalizedPath.substring(0, si);
String fileName = normalizedPath.substring(si);
if (path.startsWith(basePath) && fileName.equals("endpoints.json")) {
event.response()
.setStatusCode(STATUS)
.setStatusMessage(OK)
.putHeader(CONTENT_TYPE, "application/json")
.end(Json.encodePrettily(getContent()));

} else if (path.startsWith(basePath) && fileName.equals("routes.json")) {
if (path.startsWith(basePath) && fileName.equals("routes.json")) {
VertxRouteInfoService vertxRouteInfoService = CDI.current().select(VertxRouteInfoService.class).get();
JsonArray info = vertxRouteInfoService.getInfo();
event.response()
Expand All @@ -70,18 +53,6 @@ public void handle(RoutingContext event) {
}
}

private JsonObject getContent() {

Map<String, Object> info = new HashMap<>();

for (EndpointInfo endpoint : EndpointInfoHandler.endpointInfos) {
info.put(endpoint.getUri(), endpoint.getDescription());
}

return new JsonObject(info);

}

private static final int STATUS = 200;
private static final String OK = "OK";
private static final String SLASH = "/";
Expand Down
Loading

0 comments on commit 3650cb4

Please sign in to comment.