Permalink
Browse files

servers - allowing to specify bindInterface on SimpleWebServer's builder

  • Loading branch information...
fcamblor committed Aug 24, 2017
1 parent f24469d commit ad678703697ab34abf8750968487a666a3e3d33c
Showing with 12 additions and 6 deletions.
  1. +12 −6 restx-server-simple/src/main/java/restx/server/simple/simple/SimpleWebServer.java
@@ -33,6 +33,7 @@
private int port;
private String routerPath = "/api";
private String appBase = null;
private String bindInterface = "0.0.0.0";
private RestxMainRouter router;
public SimpleWebServerBuilder setPort(int port) {
this.port = port;
@@ -49,19 +50,24 @@ public SimpleWebServerBuilder setAppBase(String appBase) {
return this;
}
public SimpleWebServerBuilder setBindInterface(String bindInterface) {
this.bindInterface = bindInterface;
return this;
}
public SimpleWebServerBuilder setRouter(RestxMainRouter router) {
this.router = router;
return this;
}
public SimpleWebServer build() {
if (router == null) {
return new SimpleWebServer(routerPath, appBase, port) {
return new SimpleWebServer(routerPath, appBase, port, bindInterface) {
@Override
protected RestxMainRouter setupRouter() {
return RestxMainRouterFactory.newInstance(
serverId,
Optional.of(WebServers.baseUri("0.0.0.0", port, routerPath)));
Optional.of(WebServers.baseUri(bindInterface, port, routerPath)));
}
@Override
@@ -72,7 +78,7 @@ public synchronized void stop() throws Exception {
}
};
} else {
return new SimpleWebServer(routerPath, appBase, port) {
return new SimpleWebServer(routerPath, appBase, port, bindInterface) {
@Override
protected RestxMainRouter setupRouter() {
return router;
@@ -94,8 +100,8 @@ public static SimpleWebServerBuilder builder() {
private RestxMainRouter router;
private Connection connection;
private SimpleWebServer(String routerPath, String appBase, int port) {
super(appBase, port, "localhost", "SimpleFrameowkr", "org.simpleframework", "simple");
private SimpleWebServer(String routerPath, String appBase, int port, String bindInterface) {
super(appBase, port, bindInterface, "SimpleFrameowkr", "org.simpleframework", "simple");
this.routerPath = routerPath;
this.httpSettings = Factory.getInstance().getComponent(HttpSettings.class);
@@ -154,7 +160,7 @@ public static WebServerSupplier simpleWebServerSupplier() {
return new WebServerSupplier() {
@Override
public WebServer newWebServer(int port) {
return SimpleWebServer.builder().setPort(port).build();
return SimpleWebServer.builder().setPort(port).setBindInterface("0.0.0.0").build();
}
};
}

0 comments on commit ad67870

Please sign in to comment.