-
Notifications
You must be signed in to change notification settings - Fork 8
/
roq.java
executable file
·43 lines (32 loc) · 1.3 KB
/
roq.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
43
///usr/bin/env jbang "$0" "$@" ; exit $?
//DEPS io.vertx:vertx-core:4.5.7
//DEPS io.vertx:vertx-web:4.5.7
//DEPS io.netty:netty-all:4.1.109.Final
import io.vertx.core.Vertx;
import io.vertx.ext.web.Router;
import io.vertx.ext.web.handler.StaticHandler;
import java.nio.file.Path;
import java.nio.file.Files;
public class roq {
public static void main(String[] args) {
String directory = args.length > 0 ? args[0] : "target/roq/";
if (!Files.isDirectory(Path.of(directory))) {
System.err.println("Directory not found: " + directory);
System.exit(1);
}
System.out.println("Serving: " + directory);
String port = args.length > 1 ? args[1]: "8181";
Vertx vertx = Vertx.vertx();
Router router = Router.router(vertx);
router.route().handler(StaticHandler.create().setWebRoot(directory));
vertx.createHttpServer()
.requestHandler(router)
.listen(Integer.parseInt(port), result -> {
if (result.succeeded()) {
System.out.println("Server started on port http://localhost:" + port);
} else {
System.err.println("Failed to start server: " + result.cause());
}
});
}
}