-
Notifications
You must be signed in to change notification settings - Fork 15
/
Copy pathundertow.java
42 lines (34 loc) · 1.32 KB
/
undertow.java
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
import com.fizzed.blaze.Config;
import com.fizzed.blaze.Contexts;
import io.undertow.Undertow;
import io.undertow.server.HttpHandler;
import io.undertow.server.HttpServerExchange;
import io.undertow.util.Headers;
import io.undertow.server.handlers.resource.PathResourceManager;
import static io.undertow.Handlers.resource;
import java.nio.file.Path;
import org.slf4j.Logger;
public class undertow {
public void main() throws Exception {
Path dir = Contexts.baseDir();
Logger log = Contexts.logger();
Config config = Contexts.config();
String host = config.value("undertow.host").get();
int port = config.value("undertow.port", int.class).get();
boolean in_try_all_example = config.value("examples.try_all", Boolean.class).getOr(false);
Undertow undertow = Undertow.builder()
.addHttpListener(port, host)
.setHandler(resource(new PathResourceManager(dir, 100)).setDirectoryListingEnabled(true))
.build();
undertow.start();
log.info("Open browser to http://{}:{}", host, port);
if (in_try_all_example) {
// simply for stopping server if we're in try_all example
undertow.stop();
} else {
synchronized (undertow) {
undertow.wait();
}
}
}
}