Class IsolatedSpaRouteProvider
java.lang.Object
com.kingsrook.qqq.middleware.javalin.routeproviders.IsolatedSpaRouteProvider
- All Implemented Interfaces:
QJavalinRouteProviderInterface
Complete isolated SPA route provider with deep linking support.
This provider offers full SPA functionality including:
- Static file serving from classpath or filesystem
- Deep linking support (404 -> index.html fallback)
- Path-scoped before/after handlers
- Complete isolation from other SPAs
- Support for root path ("/") with exclusions for other SPAs
Usage Examples:
// Admin SPA at /admin
new IsolatedSpaRouteProvider("/admin", "admin-spa/dist/")
.withSpaIndexFile("admin-spa/dist/index.html")
.withAuthenticator(new QCodeReference(AdminAuthenticator.class))
// Root SPA at / (excluding other SPAs)
new IsolatedSpaRouteProvider("/", "public-site/")
.withSpaIndexFile("public-site/index.html")
.withExcludedPaths(List.of("/admin", "/api"))
-
Constructor Summary
ConstructorsConstructorDescriptionIsolatedSpaRouteProvider(String spaPath, String staticFilesPath) Constructor -
Method Summary
Modifier and TypeMethodDescriptionvoidacceptJavalinConfig(io.javalin.config.JavalinConfig config) Configure static file serving during Javalin config phase.voidacceptJavalinService(io.javalin.Javalin service) Register path-scoped handlers after Javalin service is created.Getter for spaIndexFile.Getter for spaPath.Getter for staticFilesPath.voidsetQInstance(QInstance qInstance) Set the QInstance (required by interface).withAfterHandler(io.javalin.http.Handler handler) Fluent setter: Add a custom after handler.withAuthenticator(QCodeReference authenticator) Fluent setter: Set the authenticator.withBeforeHandler(io.javalin.http.Handler handler) Fluent setter: Add a custom before handler.withCustomAssetDetector(Predicate<String> detector) Fluent setter: Add custom detection logic for static assets Use this for complex cases where file extensions and path patterns aren't sufficient.withCustomAssetExtensions(String... extensions) Fluent setter: Add custom file extensions to detect as static assets Use this when your SPA uses non-standard file extensions that should be treated as static assets rather than client-side routes.withCustomAssetPathPatterns(String... patterns) Fluent setter: Add custom path patterns to detect as static assets Use this when your SPA uses non-standard directory structures for assets.withDeepLinking(boolean enable) Fluent setter: Enable/disable deep linking (default: true).withExcludedPath(String path) Fluent setter: Add a single excluded path.withExcludedPaths(List<String> paths) Fluent setter: Add paths to exclude (for root SPA only).withLoadFromJar(boolean loadFromJar) Fluent setter: Set whether to load from JAR (overrides system property).withSpaIndexFile(String spaIndexFile) Fluent setter: Set the SPA index file path.Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface com.kingsrook.qqq.middleware.javalin.QJavalinRouteProviderInterface
getJavalinEndpointGroup
-
Constructor Details
-
IsolatedSpaRouteProvider
-
-
Method Details
-
setQInstance
Set the QInstance (required by interface). The QInstance is needed for authentication when an authenticator is configured.- Specified by:
setQInstancein interfaceQJavalinRouteProviderInterface- Parameters:
qInstance- The QInstance containing metadata and configuration
-
acceptJavalinConfig
public void acceptJavalinConfig(io.javalin.config.JavalinConfig config) Configure static file serving during Javalin config phase. Called by Javalin during server initialization to set up static file serving.- Specified by:
acceptJavalinConfigin interfaceQJavalinRouteProviderInterface- Parameters:
config- The Javalin configuration to add static file settings to
-
acceptJavalinService
public void acceptJavalinService(io.javalin.Javalin service) Register path-scoped handlers after Javalin service is created. Called after Javalin is created to register before/after handlers and the 404 handler for deep linking support.- Specified by:
acceptJavalinServicein interfaceQJavalinRouteProviderInterface- Parameters:
service- The Javalin service instance to register handlers with
-
withSpaIndexFile
Fluent setter: Set the SPA index file path.- Parameters:
spaIndexFile- The classpath path to the index.html file (e.g., "admin-spa/dist/index.html")- Returns:
- this provider instance for method chaining
-
withAuthenticator
Fluent setter: Set the authenticator.- Parameters:
authenticator- QCodeReference to a RouteAuthenticatorInterface implementation- Returns:
- this provider instance for method chaining
-
withExcludedPaths
Fluent setter: Add paths to exclude (for root SPA only). Excluded paths will not be handled by this SPA, allowing other route providers to handle them (e.g., exclude "/api" from a root SPA).- Parameters:
paths- List of paths to exclude (e.g., "/api", "/admin")- Returns:
- this provider instance for method chaining
-
withExcludedPath
Fluent setter: Add a single excluded path.- Parameters:
path- The path to exclude (e.g., "/api")- Returns:
- this provider instance for method chaining
-
withBeforeHandler
Fluent setter: Add a custom before handler. Before handlers run before request processing, useful for logging, custom authentication, or request modification.- Parameters:
handler- The Javalin Handler to run before request processing- Returns:
- this provider instance for method chaining
-
withAfterHandler
Fluent setter: Add a custom after handler. After handlers run after request processing, useful for logging, response modification, or cleanup.- Parameters:
handler- The Javalin Handler to run after request processing- Returns:
- this provider instance for method chaining
-
withDeepLinking
Fluent setter: Enable/disable deep linking (default: true). When enabled, 404 errors for non-static-asset paths under this SPA's path will serve index.html, allowing client-side routing to handle the URL.- Parameters:
enable- true to enable deep linking, false to disable- Returns:
- this provider instance for method chaining
-
withLoadFromJar
Fluent setter: Set whether to load from JAR (overrides system property). When true, loads static files from classpath (for production JAR deployment). When false, loads from filesystem (for development with hot reload).- Parameters:
loadFromJar- true to load from classpath, false to load from filesystem- Returns:
- this provider instance for method chaining
-
withCustomAssetExtensions
Fluent setter: Add custom file extensions to detect as static assets Use this when your SPA uses non-standard file extensions that should be treated as static assets rather than client-side routes. Example: .myext, .customdata- Parameters:
extensions- Custom extensions to add (e.g., ".myext", ".custom")- Returns:
- this for method chaining
-
withCustomAssetPathPatterns
Fluent setter: Add custom path patterns to detect as static assets Use this when your SPA uses non-standard directory structures for assets. Example: /my-assets/, /resources/, /cdn/- Parameters:
patterns- Path patterns to add (should contain "/" to avoid false positives)- Returns:
- this for method chaining
-
withCustomAssetDetector
Fluent setter: Add custom detection logic for static assets Use this for complex cases where file extensions and path patterns aren't sufficient. The custom detector runs FIRST, before extension/path checks. Example: Detect all paths starting with /cdn/ as assets provider.withCustomAssetDetector(path -> path.startsWith("/cdn/"))- Parameters:
detector- Predicate that returns true if path is a static asset- Returns:
- this for method chaining
-
getSpaPath
Getter for spaPath.- Returns:
- The path where this SPA is hosted (e.g., "/admin", "/")
-
getStaticFilesPath
Getter for staticFilesPath.- Returns:
- The classpath or filesystem path to static files
-
getSpaIndexFile
Getter for spaIndexFile.- Returns:
- The path to the SPA's index.html file
-