Class NextDashboardRouteProvider

java.lang.Object
com.kingsrook.qqq.middleware.javalin.routeproviders.NextDashboardRouteProvider
All Implemented Interfaces:
QJavalinRouteProviderInterface

public final class NextDashboardRouteProvider extends Object implements QJavalinRouteProviderInterface
Serves the QQQ Next dashboard (qqq-frontend-next static export) from the classpath at the server root. The export prerenders each dynamic route once, with the placeholder directory name "_" (for example app/_/_/index.html for /app/{table}/{id}). A request path is resolved one segment at a time, preferring an exact file or directory and otherwise the placeholder directory; directories serve their index.html. The same rule serves the router payload files (*.txt) that Next fetches during client-side navigation. Requests are only handled after no other route matched (via the shared SpaNotFoundHandlerRegistry), so API endpoints, including their own 404 responses, and path-scoped SPAs are never shadowed. Every response carries the NextDashboardSecurityHeaders; HTML documents also get a Content-Security-Policy whose script-src lists the SHA-256 hash of each inline script in that document (the export's router payload bootstrap), so no other inline script can run (QRun-IO/qqq#695).
  • Field Details

  • Constructor Details

    • NextDashboardRouteProvider

      public NextDashboardRouteProvider()
      Serve the dashboard packaged under the default classpath folder.
    • NextDashboardRouteProvider

      public NextDashboardRouteProvider(String resourceRoot)
      Serve a static export found under the given classpath folder.
      Parameters:
      resourceRoot - classpath folder, without leading or trailing slash
  • Method Details

    • withSecurityHeadersCustomizer

      public NextDashboardRouteProvider withSecurityHeadersCustomizer(Consumer<NextDashboardSecurityHeaders> customizer)
      Adjust the security headers (for example extra CSP sources, or allowing the dashboard to be framed). The customizer receives the defaults with the instance's identity provider, QuickSight, customComponent and configured analytics origins already added, and runs again whenever the QInstance is set or hot-swapped.
      Parameters:
      customizer - changes the headers in place, or null for the defaults
      Returns:
      this
    • getSecurityHeaders

      public NextDashboardSecurityHeaders getSecurityHeaders()
      The headers currently sent (after the instance additions and customizer).
    • isAvailable

      public static boolean isAvailable()
      Whether the default Next dashboard export is on the classpath.
    • setQInstance

      public void setQInstance(QInstance qInstance)
      Description copied from interface: QJavalinRouteProviderInterface
      For initial setup when server boots, set the qInstance - but also, e.g., for development, to do a hot-swap.
      Specified by:
      setQInstance in interface QJavalinRouteProviderInterface
    • inlineScriptHashes

      public static List<String> inlineScriptHashes(String html)
      CSP hash sources ('sha256-...') of the inline scripts in an HTML document. Line breaks are normalized first, as the HTML parser does before hashing.
      Parameters:
      html - the document
      Returns:
      one source per distinct inline script, in document order
    • acceptJavalinConfig

      public void acceptJavalinConfig(io.javalin.config.JavalinConfig config)
      Register the root fallback that serves the export.
      Specified by:
      acceptJavalinConfig in interface QJavalinRouteProviderInterface
    • resolve

      public String resolve(String requestPath)
      Resolve a request path to an exported file, or null when there is none.
      Parameters:
      requestPath - URL path, for example /app/person/1
      Returns:
      the file path relative to the resource root