From 5c0f8b8a405595b915afb00384326477350aa4d0 Mon Sep 17 00:00:00 2001 From: Andrew Guibert Date: Fri, 19 Oct 2018 12:04:27 -0500 Subject: [PATCH] Use external IP address for open task --- auth-service/build.gradle | 2 +- build.gradle | 16 ++++++++++++++++ frontend/build.gradle | 2 +- game-service/build.gradle | 2 +- player-service/build.gradle | 2 +- 5 files changed, 20 insertions(+), 4 deletions(-) diff --git a/auth-service/build.gradle b/auth-service/build.gradle index dc42b0e..7bca0a7 100644 --- a/auth-service/build.gradle +++ b/auth-service/build.gradle @@ -1,7 +1,7 @@ ext { httpPort = 8082 httpsPort = 8482 - appUrl = "http://localhost:${httpPort}/openapi/ui" + appUrl = "http://${hostname}:${httpPort}/openapi/ui" } liberty { diff --git a/build.gradle b/build.gradle index 6a8cfcb..fee4445 100644 --- a/build.gradle +++ b/build.gradle @@ -12,6 +12,22 @@ task clean(type: Delete) { delete 'build' } +ext.hostname = 'localhost' +// Find the public IP address for this machine (if one exists) +NetworkInterface.getNetworkInterfaces() +.findAll { it.isUp() && !it.isLoopback() && !it.isVirtual() } +.each { + it.getInetAddresses() + .findAll { !it.isLoopbackAddress() && it instanceof Inet4Address } + .each { + if (hostname.equals('localhost')) { + def hn = it.toString(); + hostname = hn.startsWith("/") ? hn.substring(1, hn.length()) : hn; + // ${it} is in the format /, so only use http:/ instead of http:// + } + } +} + subprojects { apply plugin: 'liberty' apply plugin: 'war' diff --git a/frontend/build.gradle b/frontend/build.gradle index aa982ee..cb49670 100644 --- a/frontend/build.gradle +++ b/frontend/build.gradle @@ -19,7 +19,7 @@ ext { httpPort = 12000 httpsPort = 12005 applicationName = "${war.archiveName}" - appUrl = "http://localhost:${httpPort}/" + appUrl = "http://${hostname}:${httpPort}/" } war { diff --git a/game-service/build.gradle b/game-service/build.gradle index a8103cd..1e0713e 100644 --- a/game-service/build.gradle +++ b/game-service/build.gradle @@ -6,7 +6,7 @@ dependencies { ext { httpPort = 8080 httpsPort = 8443 - appUrl = "http://localhost:${httpPort}/openapi/ui" + appUrl = "http://${hostname}:${httpPort}/openapi/ui" } liberty { diff --git a/player-service/build.gradle b/player-service/build.gradle index 1b9a8f2..5fe2327 100644 --- a/player-service/build.gradle +++ b/player-service/build.gradle @@ -1,7 +1,7 @@ ext { httpPort = 8081 httpsPort = 8444 - appUrl = "http://localhost:${httpPort}/openapi/ui" + appUrl = "http://${hostname}:${httpPort}/openapi/ui" } liberty {