public sealed interface StaticContentConfig
Builder for a static resource exchange handler.
-
Nested Class Summary
Nested ClassesModifier and TypeInterfaceDescriptionstatic enumResource location -
Method Summary
Modifier and TypeMethodDescriptionstatic StaticContentConfigcreate()Create and return a new static content configuration.Return a new ExchangeHandler that will serve the resourcesdirectoryIndex(String directoryIndex) Sets the index file to be served when a directory is requests.httpPath()Gets the current HTTP path.Sets the HTTP path for the static resource handler.location(StaticContentConfig.ResourceLocation location) Sets the resource location (CLASSPATH or FILE).putMimeTypeMapping(String ext, String mimeType) Adds a new MIME type mapping to the configuration.putResponseHeader(String key, String value) Adds a new response header to the configuration.Sets the file to serve, or the folder your files are located in.resourceLoader(ClassResourceLoader resourceLoader) Sets a custom resource loader for loading class/module path resources.skipFilePredicate(Predicate<Context> skipFilePredicate) Sets a predicate to filter files based on the request context.
-
Method Details
-
create
Create and return a new static content configuration. -
createHandler
ExchangeHandler createHandler()Return a new ExchangeHandler that will serve the resources -
httpPath
Sets the HTTP path for the static resource handler.- Parameters:
path- the HTTP path prefix- Returns:
- the updated configuration
-
httpPath
String httpPath()Gets the current HTTP path.- Returns:
- the current HTTP path
-
resource
Sets the file to serve, or the folder your files are located in. (default: "/public/")- Parameters:
resource- the root directory- Returns:
- the updated configuration
-
directoryIndex
Sets the index file to be served when a directory is requests.- Parameters:
directoryIndex- the index file- Returns:
- the updated configuration
-
resourceLoader
Sets a custom resource loader for loading class/module path resources. This is normally used when running the application on the module path when files cannot be discovered.Example usage:
config.resourceLoader(ClassResourceLoader.create(getClass()))- Parameters:
resourceLoader- the custom resource loader- Returns:
- the updated configuration
-
putMimeTypeMapping
Adds a new MIME type mapping to the configuration. (Default: usesURLConnection.getFileNameMap()- Parameters:
ext- the file extension (e.g., "html", "css", "js")mimeType- the corresponding MIME type (e.g., "text/html", "text/css", "application/javascript")- Returns:
- the updated configuration
-
putResponseHeader
Adds a new response header to the configuration.- Parameters:
key- the header namevalue- the header value- Returns:
- the updated configuration
-
skipFilePredicate
Sets a predicate to filter files based on the request context.- Parameters:
skipFilePredicate- the predicate to use- Returns:
- the updated configuration
-
location
Sets the resource location (CLASSPATH or FILE).- Parameters:
location- the resource location- Returns:
- the updated configuration
-