Skip to content

Commit 441f563

Browse files
authored
Create README for avaje-jex-static-content plugin
Added README.md with installation and usage instructions for the static content plugin.
1 parent 43e4628 commit 441f563

File tree

1 file changed

+43
-0
lines changed

1 file changed

+43
-0
lines changed

avaje-jex-static-content/README.md

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
# Static Resources
2+
3+
[![Maven Central](https://img.shields.io/maven-central/v/io.avaje/avaje-jex-static-content.svg?label=Maven%20Central)](https://mvnrepository.com/artifact/io.avaje/avaje-jex-static-content)
4+
[![javadoc](https://javadoc.io/badge2/io.avaje/avaje-jex-static-content/javadoc.svg?color=purple)](https://javadoc.io/doc/io.avaje/avaje-jex-static-content)
5+
6+
PLugin for serving static resources from the classpath or filesystem.
7+
8+
It provides a `StaticContent` class to configure the location and HTTP path of your static resources, as well as other attributes.
9+
10+
## Installation
11+
12+
Add the static content dependency to your project:
13+
```xml
14+
<dependency>
15+
<groupId>io.avaje</groupId>
16+
<artifactId>avaje-jex-static-content</artifactId>
17+
<version>${avaje.jex.version}</version>
18+
</dependency>
19+
```
20+
21+
## Basic Usage
22+
```java
23+
StaticContent singleFile =
24+
StaticContent.ofFile("src/main/resources/example.txt").httpPath("/single").build();
25+
StaticContent directoryCP =
26+
StaticContent.ofClassPath("/public/").httpPath("/").directoryIndex("index.html").build();
27+
Jex app =
28+
Jex.create()
29+
.plugin(singleFile) // will serve the src/main/resources/example.txt
30+
.plugin(directoryCP); // will serve files from the /public classpath directory
31+
```
32+
33+
## Configuration Options
34+
35+
| Method | Description |
36+
|--------|-------------|
37+
| `directoryIndex("index.html")` | The index file to be served when a directory is requested. |
38+
| `route("/public")` | Sets the HTTP path and security role for the static resource handler. |
39+
| `preCompress()` | Sent resources will be pre-compressed and cached in memory when this is enabled. |
40+
| `putMimeTypeMapping("sus", "application/sus")` | Adds a custom file extension MIME mapping to the configuration. |
41+
| `putResponseHeader("key", value)` | Adds a new response header to the configuration. |
42+
| `resourceLoader(clazz)` | Sets a custom resource loader for loading class/module path resources. |
43+
| `skipFilePredicate(ctx -> !ctx.path().contains("/skip"))` | Sets a predicate to filter files based on the request context. |

0 commit comments

Comments
 (0)