Class FileServerUtility
java.lang.Object
com.pixelservices.flash.components.fileserver.FileServerUtility
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic interface
Callback interface for file watcher events. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic boolean
autodetectSPA
(Path dirPath) Attempts to auto-detect if the given directory is a modern SPA (e.g.static String
getContentType
(String fileName) static void
registerAllSubdirectories
(Path startPath, WatchService watchService) Registers the given directory and all its subdirectories with the provided WatchService.static String
rewriteHtml
(String htmlContent, String endpoint) Rewrites HTML content by prefixing static asset URLs with the given endpoint.static String
Rewrites JavaScript content by prefixing asset URLs with the given endpoint.static String
rewriteRoute
(String route, String endpoint) Rewrites a route by prefixing it with the given endpoint if it isn’t already.static void
startDirectoryWatcher
(Path rootPath, FileServerUtility.FileWatcherCallback callback) Starts a directory watcher on the given rootPath.
-
Constructor Details
-
FileServerUtility
public FileServerUtility()
-
-
Method Details
-
registerAllSubdirectories
public static void registerAllSubdirectories(Path startPath, WatchService watchService) throws IOException Registers the given directory and all its subdirectories with the provided WatchService.- Throws:
IOException
-
startDirectoryWatcher
public static void startDirectoryWatcher(Path rootPath, FileServerUtility.FileWatcherCallback callback) Starts a directory watcher on the given rootPath. For every watch event, the callback is invoked. Note: This method blocks the current thread. -
autodetectSPA
Attempts to auto-detect if the given directory is a modern SPA (e.g. React, Next.js, Svelte). This method checks for the presence of an index.html along with either an asset-manifest.json or next.config.js. -
rewriteHtml
Rewrites HTML content by prefixing static asset URLs with the given endpoint. -
rewriteJs
Rewrites JavaScript content by prefixing asset URLs with the given endpoint. -
rewriteRoute
Rewrites a route by prefixing it with the given endpoint if it isn’t already. -
getContentType
-