Class SimpleFileSystemDirectoryRouter
java.lang.Object
com.kingsrook.qqq.middleware.javalin.routeproviders.SimpleFileSystemDirectoryRouter
- All Implemented Interfaces:
QJavalinRouteProviderInterface
public class SimpleFileSystemDirectoryRouter
extends Object
implements QJavalinRouteProviderInterface
Route provider that serves static files and SPAs from the file system or JAR.
This is a simpler alternative to IsolatedSpaRouteProvider, suitable for cases
where you need basic file serving with optional SPA deep linking support but
don't need the advanced isolation and handler features.
Features:
- Serves static files from file system or JAR classpath
- Optional SPA deep linking (404 -> root file fallback)
- Authentication support via RouteAuthenticatorInterface
- Static asset detection to distinguish between missing assets and SPA routes
Usage Examples:
// Serve static files from dist directory
new SimpleFileSystemDirectoryRouter("/app", "dist/")
// Serve SPA with deep linking
new SimpleFileSystemDirectoryRouter("/app", "dist/")
.withSpaRootPath("/app")
.withSpaRootFile("dist/index.html")
.withRouteAuthenticator(new QCodeReference(AppAuthenticator.class))
-
Field Summary
Fields -
Constructor Summary
ConstructorsConstructorDescriptionSimpleFileSystemDirectoryRouter(JavalinRouteProviderMetaData routeProvider) Constructor that builds router from meta-data configuration.SimpleFileSystemDirectoryRouter(String hostedPath, String fileSystemPath) Constructor -
Method Summary
Modifier and TypeMethodDescriptionvoidacceptJavalinConfig(io.javalin.config.JavalinConfig config) Configure Javalin to serve static files from the configured location.voidacceptJavalinService(io.javalin.Javalin service) Setup SPA deep linking support and authentication handlers.Getter for routeAuthenticatorGetter for spaRootFileGetter for spaRootPathvoidsetQInstance(QInstance qInstance) Set the QInstance for this route provider.voidsetRouteAuthenticator(QCodeReference routeAuthenticator) Setter for routeAuthenticatorvoidsetSpaRootFile(String spaRootFile) Setter for spaRootFilevoidsetSpaRootPath(String spaRootPath) Setter for spaRootPathwithRouteAuthenticator(QCodeReference routeAuthenticator) Fluent setter for routeAuthenticatorwithSpaRootFile(String spaRootFile) Fluent setter for spaRootFilewithSpaRootPath(String spaRootPath) Fluent setter for spaRootPathMethods 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
-
Field Details
-
loadStaticFilesFromJar
public static boolean loadStaticFilesFromJar
-
-
Constructor Details
-
SimpleFileSystemDirectoryRouter
-
SimpleFileSystemDirectoryRouter
Constructor that builds router from meta-data configuration.- Parameters:
routeProvider- meta-data containing route configuration including hosted path, file system path, SPA settings, and authenticator
-
-
Method Details
-
setQInstance
Set the QInstance for this route provider. Called by the framework during initialization to provide access to the QQQ instance configuration.- Specified by:
setQInstancein interfaceQJavalinRouteProviderInterface- Parameters:
qInstance- the QInstance containing meta-data and configuration
-
acceptJavalinConfig
public void acceptJavalinConfig(io.javalin.config.JavalinConfig config) Configure Javalin to serve static files from the configured location. Registers the static file configuration with Javalin during initialization. The actual configuration is handled by handleJavalinStaticFileConfig().- Specified by:
acceptJavalinConfigin interfaceQJavalinRouteProviderInterface- Parameters:
config- the Javalin configuration object
-
acceptJavalinService
public void acceptJavalinService(io.javalin.Javalin service) Setup SPA deep linking support and authentication handlers. This method is called AFTER Javalin config phase, which allows us to register handlers that run after static file serving. This is critical for proper SPA deep linking support with multiple SPAs.- Specified by:
acceptJavalinServicein interfaceQJavalinRouteProviderInterface
-
getRouteAuthenticator
-
setRouteAuthenticator
Setter for routeAuthenticator- See Also:
-
withRouteAuthenticator
Fluent setter for routeAuthenticator- Parameters:
routeAuthenticator- code reference to the route authenticator implementation- Returns:
- this
-
getSpaRootPath
-
setSpaRootPath
-
withSpaRootPath
Fluent setter for spaRootPath- Parameters:
spaRootPath- the URL path prefix for the SPA (e.g., "/app" or "/")- Returns:
- this
-
getSpaRootFile
-
setSpaRootFile
-
withSpaRootFile
Fluent setter for spaRootFile- Parameters:
spaRootFile- path to the SPA index file for deep linking (e.g., "dist/index.html")- Returns:
- this
-