forked from jooby-project/jooby
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathH2Jetty.java
More file actions
46 lines (36 loc) · 1.15 KB
/
H2Jetty.java
File metadata and controls
46 lines (36 loc) · 1.15 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
package jetty;
import com.google.common.io.ByteStreams;
import org.jooby.Jooby;
import org.jooby.MediaType;
import org.jooby.Results;
import org.jooby.funzy.Throwing;
import org.jooby.funzy.Try;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.nio.charset.StandardCharsets;
public class H2Jetty extends Jooby {
/** The logging system. */
private final Logger log = LoggerFactory.getLogger(getClass());
Throwing.Function<String, String> html = Throwing.<String, String>throwingFunction(path -> {
return Try.with(() -> getClass().getResourceAsStream(path))
.apply(in -> {
byte[] bytes = ByteStreams.toByteArray(in);
return new String(bytes, StandardCharsets.UTF_8);
}).get();
}).memoized();
{
http2();
securePort(8443);
use("*", (req, rsp) -> {
log.info("************ {} ************", req.path());
});
assets("/assets/**");
get("/", req -> {
req.push("/assets/index.js");
return Results.ok(html.apply("/index.html")).type(MediaType.html);
});
}
public static void main(final String[] args) throws Throwable {
run(H2Jetty::new, args);
}
}