-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMain.java
More file actions
69 lines (55 loc) · 1.64 KB
/
Main.java
File metadata and controls
69 lines (55 loc) · 1.64 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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
package tanin.ejwf;
import com.renomad.minum.web.FullSystem;
import com.renomad.minum.web.Response;
import com.renomad.minum.web.StatusLine;
import java.io.IOException;
import java.util.Map;
import java.util.logging.LogManager;
import java.util.logging.Logger;
import static com.renomad.minum.web.RequestLine.Method.GET;
public class Main {
private static final Logger logger = Logger.getLogger(Main.class.getName());
static {
try (var configFile = Main.class.getResourceAsStream("/ejwf_default_logging.properties")) {
LogManager.getLogManager().readConfiguration(configFile);
logger.info("The log config (default_logging.properties) has been loaded.");
} catch (IOException e) {
logger.warning("Could not load the log config file (default_logging.properties): " + e.getMessage());
}
}
public static void main(String[] args) {
var main = new Main(9090);
main.start();
main.minum.block();
}
int port;
public FullSystem minum;
Main(int port) {
this.port = port;
}
public void start() {
minum = MinumBuilder.build(port);
var wf = minum.getWebFramework();
wf.registerPath(
GET,
"",
r -> {
logger.info("Serve /");
String content = new String(Main.class.getResourceAsStream("/html/index.html").readAllBytes());
return Response.htmlOk(content);
}
);
wf.registerPath(
GET,
"healthcheck",
req -> {
return Response.buildResponse(StatusLine.StatusCode.CODE_200_OK, Map.of("Content-Type", "text/plain"), "OK EWJF");
}
);
}
public void stop() {
if (minum != null) {
minum.shutdown();
}
}
}