Interface StaticResourceBuilder<R extends RequestContext<?>>

All Known Implementing Classes:
StaticResourceBuilderDefault

public interface StaticResourceBuilder<R extends RequestContext<?>>
Builder to create static resources.
  • Method Details

    • spicastOrPluginAddedResource

      StaticResourceBuilder<R> spicastOrPluginAddedResource()
      This should only by called by *plugins*.

      When this method is called, the resulting route for the resource won't be remove by default when the Router.removeAllRoutes() method is used. The Router.removeAllRoutes(boolean) with true will have to be called to actually remove it.

      This is useful during development, when an hotreload mecanism is used to reload the Router without restarting the application, when the application routes changed. By default only the routes for which the #isSpicastCoreRouteOrPluginRoute() method has been called would then be reloaded.

    • url

      The URL pointing to the resource.
    • classpath

      StaticResourceBuilder<R> classpath(String path)
      The path to the resource, on the classpath.
    • pathAbsolute

      StaticResourceBuilder<R> pathAbsolute(String absolutePath)
      The absolute path to the resource, on the file system.
      Parameters:
      absolutePath - the absolute path to the resource. If this is a file and not a directory, remember that it will be served as a static resource, so its extension is important for the correct Content-Type to be sent!
    • pathRelative

      StaticResourceBuilder<R> pathRelative(String relativePath)
      The path to the resource, on the file system, relative to the temp Spincast directory, as returned by SpincastConfig::getSpincastTempDir()
      Parameters:
      relativePath - the relative path to the resource. If this is a file and not a directory, remember that it will be served as a static resource, so its extension is important for the correct Content-Type to be sent!
    • cors

      Enables Cross-Origin Resource Sharing (Cors)
      See Also:
      • SpincastFilters#cors(R context)
    • cors

      StaticResourceBuilder<R> cors(Set<String> allowedOrigins)
      Enables Cross-Origin Resource Sharing (Cors)
      See Also:
      • SpincastFilters#cors(R context, Set<String> allowedOrigins)
    • cors

      StaticResourceBuilder<R> cors(Set<String> allowedOrigins, Set<String> extraHeadersAllowedToBeRead)
      Enables Cross-Origin Resource Sharing (Cors)
      See Also:
      • SpincastFilters#cors(R context, Set<String> allowedOrigins, Set<String> extraHeadersAllowedToBeRead)
    • cors

      StaticResourceBuilder<R> cors(Set<String> allowedOrigins, Set<String> extraHeadersAllowedToBeRead, Set<String> extraHeadersAllowedToBeSent)
      Enables Cross-Origin Resource Sharing (Cors)
      See Also:
      • SpincastFilters#cors(R context, Set<String> allowedOrigins, Set<String> extraHeadersAllowedToBeRead, Set<String> extraHeadersAllowedToBeSent)
    • cors

      StaticResourceBuilder<R> cors(Set<String> allowedOrigins, Set<String> extraHeadersAllowedToBeRead, Set<String> extraHeadersAllowedToBeSent, boolean allowCookies)
      Enables Cross-Origin Resource Sharing (Cors)
      See Also:
      • SpincastFilters#cors(R context, Set<String> allowedOrigins, Set<String> extraHeadersAllowedToBeRead, Set<String> extraHeadersAllowedToBeSent, boolean allowCookies)
    • cors

      StaticResourceBuilder<R> cors(Set<String> allowedOrigins, Set<String> extraHeadersAllowedToBeRead, Set<String> extraHeadersAllowedToBeSent, boolean allowCookies, int maxAgeInSeconds)
      Enables Cross-Origin Resource Sharing (Cors)
      See Also:
      • SpincastFilters#cors(R context, Set<String> allowedOrigins, Set<String> extraHeadersAllowedToBeRead, Set<String> extraHeadersAllowedToBeSent, boolean allowCookies, int maxAgeInSeconds )
    • cache

      StaticResourceBuilder<R> cache(int seconds)
      Adds public cache headers.
      Parameters:
      seconds - The number of seconds the resource associated with this route should be cached.
    • cache

      StaticResourceBuilder<R> cache(int seconds, boolean isPrivate)
      Adds cache headers.
      Parameters:
      seconds - The number of seconds the resource associated with this route should be cached.
      isPrivate - should the cache be private? (help)
    • cache

      StaticResourceBuilder<R> cache(int seconds, boolean isPrivate, Integer secondsCdn)
      Adds cache headers.
      Parameters:
      seconds - The number of seconds the resource associated with this route should be cached.
      isPrivate - should the cache be private? (help)
      secondsCdn - The number of seconds the resource associated with this route should be cached by a CDN/proxy. If null, it won't be used.
    • hotlinkingProtected

      StaticResourceBuilder<R> hotlinkingProtected()
      When a static resource is flagged as being *hotlinking protected*, the server will validate the origin and referer of the request. If those don't matche the host of the application, a protection will be apply, the one provided by the default .
    • hotlinkingProtected

      StaticResourceBuilder<R> hotlinkingProtected(HotlinkingManager hotlinkingManager)
      When a static resource is flagged as being *hotlinking protected*, the server will validate the origin and referer of the request. If those don't matche the host of the application, a protection will be apply, the one provided by the specified hotlinkingManager.
    • handle

      void handle()
      Saves the static resource route to the router.

      If the creation of the resource was not started using an Router object, an exception will be thrown.

    • handle

      void handle(Handler<R> generator)
      Saves the static resource route. Note that the generated resource won't be cached if there is a queryString on the request : it will always be generated.

      If the creation of the resource was not started using an Router object, an exception will be thrown.

      Parameters:
      generator - If the resource is not found, the specified generator will be used to generate it and the result will be saved.
    • handle

      void handle(Handler<R> generator, boolean ignoreQueryString)
      Saves the static resource route.

      If the creation of the resource was not started using an Router object, an exception will be thrown.

      Parameters:
      generator - If the resource is not found, the specified generator will be used to generate it and the result will be saved.
      ignoreQueryString - If true, only one instance of the resource will be generated and cached. If false (the default), the resource will always be generated if there is a queryString.
    • create

      StaticResource<R> create()
      Creates and returns the static resource without adding it to the router. NOTE : use handle(...) instead to save the static resource to the router at the end of the build process!