Module io.avaje.jex
Package io.avaje.jex

Interface StaticContentConfig


public sealed interface StaticContentConfig
Builder for a static resource exchange handler.
  • Method Details

    • create

      static StaticContentConfig create()
      Create and return a new static content configuration.
    • createHandler

      ExchangeHandler createHandler()
      Return a new ExchangeHandler that will serve the resources
    • httpPath

      StaticContentConfig httpPath(String path)
      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

      StaticContentConfig resource(String 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

      StaticContentConfig directoryIndex(String directoryIndex)
      Sets the index file to be served when a directory is requests.
      Parameters:
      directoryIndex - the index file
      Returns:
      the updated configuration
    • resourceLoader

      StaticContentConfig resourceLoader(ClassResourceLoader 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

      StaticContentConfig putMimeTypeMapping(String ext, String mimeType)
      Adds a new MIME type mapping to the configuration. (Default: uses URLConnection.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

      StaticContentConfig putResponseHeader(String key, String value)
      Adds a new response header to the configuration.
      Parameters:
      key - the header name
      value - the header value
      Returns:
      the updated configuration
    • skipFilePredicate

      StaticContentConfig skipFilePredicate(Predicate<Context> 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