From 719be86e94a9ac865ec231573a635509844d27a2 Mon Sep 17 00:00:00 2001 From: Darin Kelkhoff Date: Mon, 6 Jan 2025 08:36:23 -0600 Subject: [PATCH] Add guard around serving of material-dashboard-overlay, to allow server to start up without that path existing --- .../javalin/QApplicationJavalinServer.java | 25 ++++++++++++------- 1 file changed, 16 insertions(+), 9 deletions(-) diff --git a/qqq-middleware-javalin/src/main/java/com/kingsrook/qqq/middleware/javalin/QApplicationJavalinServer.java b/qqq-middleware-javalin/src/main/java/com/kingsrook/qqq/middleware/javalin/QApplicationJavalinServer.java index d18a6a03..eb633f4d 100644 --- a/qqq-middleware-javalin/src/main/java/com/kingsrook/qqq/middleware/javalin/QApplicationJavalinServer.java +++ b/qqq-middleware-javalin/src/main/java/com/kingsrook/qqq/middleware/javalin/QApplicationJavalinServer.java @@ -38,6 +38,7 @@ import com.kingsrook.qqq.middleware.javalin.specs.v1.MiddlewareVersionV1; import io.javalin.Javalin; import io.javalin.http.Context; import org.apache.commons.lang.BooleanUtils; +import org.eclipse.jetty.util.resource.Resource; /******************************************************************************* @@ -102,17 +103,23 @@ public class QApplicationJavalinServer { //////////////////////////////////////////////////////////////////////////////////////// // If you have any assets to add to the web server (e.g., logos, icons) place them at // - // src/main/resources/material-dashboard-overlay (or a directory of your choice // - // under src/main/resources) and use this line of code to tell javalin about it. // - // Make sure to add your app-specific directory to the javalin config before the core // - // material-dashboard directory, so in case the same file exists in both (e.g., // - // favicon.png), the app-specific one will be used. // + // src/main/resources/material-dashboard-overlay // + // we'll use the same check that javalin (jetty?) internally uses to see if this // + // directory exists - because if it doesn't, then it'll fail to start the server... // + // note that that Resource object is auto-closable, hence the try-with-resources // //////////////////////////////////////////////////////////////////////////////////////// - config.staticFiles.add("/material-dashboard-overlay"); + try(Resource resource = Resource.newClassPathResource("/material-dashboard-overlay")) + { + if(resource !=null) + { + config.staticFiles.add("/material-dashboard-overlay"); + } + } - ///////////////////////////////////////////////////////////////////// - // tell javalin where to find material-dashboard static web assets // - ///////////////////////////////////////////////////////////////////// + //////////////////////////////////////////////////////////////////////////////////// + // tell javalin where to find material-dashboard static web assets // + // in this case, this path is coming from the qqq-frontend-material-dashboard jar // + //////////////////////////////////////////////////////////////////////////////////// config.staticFiles.add("/material-dashboard"); ////////////////////////////////////////////////////////////