1- package io .avaje .jex ;
1+ package io .avaje .jex . staticcontent ;
22
33import java .net .URLConnection ;
44import java .util .function .Predicate ;
55
6+ import io .avaje .jex .Context ;
7+ import io .avaje .jex .Routing .HttpService ;
8+
69/** Builder for a static resource exchange handler. */
7- public sealed interface StaticContentConfig permits StaticResourceHandlerBuilder {
10+ public sealed interface StaticContentService extends HttpService
11+ permits StaticResourceHandlerBuilder {
812
9- /** Create and return a new static content configuration. */
10- static StaticContentConfig create () {
11- return StaticResourceHandlerBuilder .builder ();
13+ /**
14+ * Create and return a new static content configuration.
15+ *
16+ * @param resourceRoot The file to serve, or the directory the files are located in.
17+ */
18+ static StaticContentService createCP (String resourceRoot ) {
19+ return StaticResourceHandlerBuilder .builder (resourceRoot );
1220 }
1321
14- /** Return a new ExchangeHandler that will serve the resources */
15- ExchangeHandler createHandler ();
16-
1722 /**
18- * Sets the HTTP path for the static resource handler.
19- *
20- * @param path the HTTP path prefix
21- * @return the updated configuration
23+ * Create and return a new static class path content configuration with the `/public` directory as
24+ * the root.
2225 */
23- StaticContentConfig httpPath (String path );
26+ static StaticContentService createCP () {
27+ return StaticResourceHandlerBuilder .builder ("/public/" );
28+ }
2429
2530 /**
26- * Gets the current HTTP path .
31+ * Create and return a new static content configuration for a File .
2732 *
28- * @return the current HTTP path
33+ * @param resourceRoot The path of the file to serve, or the directory the files are located in.
2934 */
30- String httpPath ();
35+ static StaticContentService createFile (String resourceRoot ) {
36+ return StaticResourceHandlerBuilder .builder (resourceRoot ).file ();
37+ }
3138
3239 /**
33- * Sets the file to serve, or the folder your files are located in. (default: "/public/")
40+ * Sets the HTTP path for the static resource handler.
3441 *
35- * @param resource the root directory
42+ * @param path the HTTP path prefix
3643 * @return the updated configuration
3744 */
38- StaticContentConfig resource (String resource );
45+ StaticContentService httpPath (String path );
3946
4047 /**
4148 * Sets the index file to be served when a directory is requests.
4249 *
4350 * @param directoryIndex the index file
4451 * @return the updated configuration
4552 */
46- StaticContentConfig directoryIndex (String directoryIndex );
53+ StaticContentService directoryIndex (String directoryIndex );
4754
4855 /**
4956 * Sets a custom resource loader for loading class/module path resources. This is normally used
@@ -54,7 +61,7 @@ static StaticContentConfig create() {
5461 * @param resourceLoader the custom resource loader
5562 * @return the updated configuration
5663 */
57- StaticContentConfig resourceLoader (ClassResourceLoader resourceLoader );
64+ StaticContentService resourceLoader (ClassResourceLoader resourceLoader );
5865
5966 /**
6067 * Adds a new MIME type mapping to the configuration. (Default: uses {@link
@@ -65,7 +72,7 @@ static StaticContentConfig create() {
6572 * "application/javascript")
6673 * @return the updated configuration
6774 */
68- StaticContentConfig putMimeTypeMapping (String ext , String mimeType );
75+ StaticContentService putMimeTypeMapping (String ext , String mimeType );
6976
7077 /**
7178 * Adds a new response header to the configuration.
@@ -74,27 +81,13 @@ static StaticContentConfig create() {
7481 * @param value the header value
7582 * @return the updated configuration
7683 */
77- StaticContentConfig putResponseHeader (String key , String value );
84+ StaticContentService putResponseHeader (String key , String value );
7885
7986 /**
8087 * Sets a predicate to filter files based on the request context.
8188 *
8289 * @param skipFilePredicate the predicate to use
8390 * @return the updated configuration
8491 */
85- StaticContentConfig skipFilePredicate (Predicate <Context > skipFilePredicate );
86-
87- /**
88- * Sets the resource location (CLASSPATH or FILE).
89- *
90- * @param location the resource location
91- * @return the updated configuration
92- */
93- StaticContentConfig location (ResourceLocation location );
94-
95- /** Resource location */
96- enum ResourceLocation {
97- CLASS_PATH ,
98- FILE
99- }
92+ StaticContentService skipFilePredicate (Predicate <Context > skipFilePredicate );
10093}
0 commit comments