Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
servers - allowing to specify bindInterface on SimpleWebServer's builder
  • Loading branch information
fcamblor committed Sep 9, 2017
1 parent f24469d commit ad67870
Showing 1 changed file with 12 additions and 6 deletions.
Expand Up @@ -33,6 +33,7 @@ public static class SimpleWebServerBuilder {
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;
Expand All @@ -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
Expand All @@ -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;
Expand All @@ -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);
Expand Down Expand Up @@ -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();
}
};
}
Expand Down

0 comments on commit ad67870

Please sign in to comment.