Skip to content

Commit

Permalink
put in a kludge to account for quinoa not being able to serve SPA fro…
Browse files Browse the repository at this point in the history
…m non-root path.

can probably be removed when  quarkiverse/quarkus-quinoa#302 is implemented.
  • Loading branch information
pahjbo committed Mar 20, 2024
1 parent 08ed4c8 commit f989509
Show file tree
Hide file tree
Showing 6 changed files with 66 additions and 6 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# pst-gui Project
qu# pst-gui Project

[![main build](https://github.com/orppst/pst-gui/actions/workflows/gradle.yml/badge.svg)](https://github.com/orppst/pst-gui/actions/workflows/gradle.yml/)

Expand Down
3 changes: 2 additions & 1 deletion build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@ version = "0.1"
dependencies {
implementation("io.quarkus:quarkus-resteasy-reactive-jackson")
implementation("io.quarkus:quarkus-rest-client-reactive-jackson")
implementation("io.quarkiverse.quinoa:quarkus-quinoa:2.0.8")
implementation("io.quarkiverse.quinoa:quarkus-quinoa:2.2.5")
implementation("io.quarkus:quarkus-reactive-routes")
implementation("io.quarkus:quarkus-websockets")
implementation("io.quarkus:quarkus-smallrye-jwt")
implementation("io.quarkus:quarkus-oidc")
Expand Down
4 changes: 3 additions & 1 deletion src/main/java/org/orph2020/pst/gui/info/PathInfo.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@

import java.net.URI;
import java.net.URISyntaxException;
import java.net.URL;

@Path("/api-info")
public class PathInfo {
Expand All @@ -33,7 +34,8 @@ public Response info(@Context UriInfo uriInfo) {
}
else {
//when deployed the api is on same server (as far as the client side can see things).
URI uriLoc = UriBuilder.fromUri(requestUri.resolve("../../../")).scheme("https").build();

URI uriLoc = UriBuilder.fromPath("/").scheme("https").host(requestUri.getHost()).build();
return Response.ok(uriLoc).build();
}
}
Expand Down
50 changes: 50 additions & 0 deletions src/main/java/org/orph2020/pst/gui/routes/Routing.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
package org.orph2020.pst.gui.routes;

import io.quarkus.vertx.web.RoutingExchange;
import io.vertx.ext.web.Router;
import io.vertx.ext.web.RoutingContext;
import jakarta.enterprise.context.ApplicationScoped;
import io.quarkus.vertx.web.Route;
import jakarta.enterprise.event.Observes;
import org.jboss.logging.Logger;


/*
* Created on 18/03/2024 by Paul Harrison (paul.harrison@manchester.ac.uk).
*/

/**
* Mess around with routing to have SPA at non-root path.
* TODO - hopefully can be removed when https://github.com/quarkiverse/quarkus-quinoa/issues/302 is implemented.
*
*/
@ApplicationScoped
public class Routing {

private static final Logger log = Logger.getLogger(Routing.class);

// put some routes before all the others to sort out the spa routing.
void spa (@Observes Router router) {
router.get("/").order(1).handler(rc ->{
rc.reroute("/pst/gui/index.html");
});
router.get("/tool/*").order(2).handler(rc -> {
final String path = rc.normalizedPath();
log.debugf("SPA redirection "+ path);
if(path.equals("/pst/gui/tool/index.html"))
rc.next();
else
rc.reroute("/pst/gui/tool/index.html");
});

for (var r: router.getRoutes())
{
log.info(r.toString());
}



}


}
9 changes: 6 additions & 3 deletions src/main/resources/application.properties
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,12 @@ quarkus.quinoa.package-manager-install=false
quarkus.quinoa.dev-server.port=5173
quarkus.quinoa.build-dir=dist
#see https://docs.quarkiverse.io/quarkus-quinoa/dev/index.html#spa-routing
quarkus.quinoa.enable-spa-routing=true
quarkus.quinoa.ignored-path-prefixes=/aai
%dev.quarkus.quinoa.enable-spa-routing=true
%prod.quarkus.quinoa.enable-spa-routing=true
quarkus.quinoa.ignored-path-prefixes=/aai,/logout
quarkus.quinoa.index-page=/tool/index.html
quarkus.log.category."io.quarkiverse.quinoa".level=DEBUG
quarkus.log.category."org.orph2020.pst.gui.routes".level=DEBUG

#want this exposed to outside world
quarkus.kubernetes.ingress.expose=true
Expand Down Expand Up @@ -85,5 +88,5 @@ quarkus.oidc.authentication.java-script-auto-redirect=false

#HTTP logging - see https://quarkus.io/guides/http-reference#configuring-http-access-logs
%prod.quarkus.http.access-log.enabled=true
%prod.quarkus.http.access-log.pattern=long
%prod.quarkus.http.access-log.pattern=combined

4 changes: 4 additions & 0 deletions src/main/webui/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,10 @@ Other client side libraries used

* https://reactrouter.com/ - see https://tkdodo.eu/blog/react-query-meets-react-router

## Security

follows https://datatracker.ietf.org/doc/html/draft-ietf-oauth-browser-based-apps-14#name-token-mediating-backend architecture where the refresh token is not exposed to the javascript.

## Misc

* see https://github.com/quarkiverse/quarkus-quinoa/issues/299 for issues regarding serving
Expand Down

0 comments on commit f989509

Please sign in to comment.