-
Notifications
You must be signed in to change notification settings - Fork 0
/
MainApp.java
53 lines (36 loc) · 1.64 KB
/
MainApp.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
44
45
46
47
48
49
50
51
52
53
package com.electrogrid.PAF;
import com.electrogrid.PAF.controller.*;
import jakarta.ws.rs.core.UriBuilder;
import org.eclipse.jetty.server.Server;
import org.glassfish.jersey.jetty.JettyHttpContainerFactory;
import org.glassfish.jersey.server.ResourceConfig;
import java.util.logging.Level;
import java.util.logging.Logger;
public class MainApp {
public static final String BASE_URI = "http://0.0.0.0/";
public static final int PORT = System.getenv("PORT") != null ? Integer.parseInt(System.getenv("PORT")) : 8030;
public static Server startServer() {
final ResourceConfig config = new ResourceConfig()
.registerInstances(new UserController())
.register(CORSResponseFilter.class);
return JettyHttpContainerFactory.createServer(UriBuilder.fromUri(BASE_URI).port(PORT).build(), config);
}
public static void main(String[] args) {
try {
final Server server = startServer();
Runtime.getRuntime().addShutdownHook(new Thread(() -> {
try {
System.out.println("Shutting down the application...");
server.stop();
System.out.println("Done, exit.");
} catch (Exception e) {
Logger.getLogger(MainApp.class.getName()).log(Level.SEVERE, null, e);
}
}));
System.out.printf("Application started.%nStop the application using CTRL+C%n");
Thread.currentThread().join();
} catch (InterruptedException ex) {
Logger.getLogger(MainApp.class.getName()).log(Level.SEVERE, null, ex);
}
}
}