aboutsummaryrefslogtreecommitdiffstats
path: root/subprojects/language-web
diff options
context:
space:
mode:
authorLibravatar Kristóf Marussy <kristof@marussy.com>2023-09-04 18:08:59 +0200
committerLibravatar Kristóf Marussy <kristof@marussy.com>2023-09-04 20:33:55 +0200
commit0e7c55f7ab8d496e81a3dbd53f14e0c46cb27fa6 (patch)
tree3df27544768e96ec8508452d07b9c20c30f374b0 /subprojects/language-web
parentrefactor(frontend): graph visualizer performance (diff)
downloadrefinery-0e7c55f7ab8d496e81a3dbd53f14e0c46cb27fa6.tar.gz
refinery-0e7c55f7ab8d496e81a3dbd53f14e0c46cb27fa6.tar.zst
refinery-0e7c55f7ab8d496e81a3dbd53f14e0c46cb27fa6.zip
refactor: server environemntal variables
* Prefix each variable with REFINERY_ * If not public host is specified, allow all origings and compute the WebSocket address on the client from the origin.
Diffstat (limited to 'subprojects/language-web')
-rw-r--r--subprojects/language-web/build.gradle.kts12
-rw-r--r--subprojects/language-web/src/main/java/tools/refinery/language/web/ServerLauncher.java24
-rw-r--r--subprojects/language-web/src/main/java/tools/refinery/language/web/config/BackendConfigServlet.java3
3 files changed, 22 insertions, 17 deletions
diff --git a/subprojects/language-web/build.gradle.kts b/subprojects/language-web/build.gradle.kts
index 9f772d41..88dccdf3 100644
--- a/subprojects/language-web/build.gradle.kts
+++ b/subprojects/language-web/build.gradle.kts
@@ -64,8 +64,18 @@ tasks {
64 classpath(mainRuntimeClasspath) 64 classpath(mainRuntimeClasspath)
65 mainClass.set(application.mainClass) 65 mainClass.set(application.mainClass)
66 standardInput = System.`in` 66 standardInput = System.`in`
67 environment("BASE_RESOURCE", webapp.singleFile) 67 environment("REFINERY_BASE_RESOURCE", webapp.singleFile)
68 group = "run" 68 group = "run"
69 description = "Start a Jetty web server serving the Xtext API and assets." 69 description = "Start a Jetty web server serving the Xtext API and assets."
70 } 70 }
71
72 register<JavaExec>("serveBackendOnly") {
73 val mainRuntimeClasspath = sourceSets.main.map { it.runtimeClasspath }
74 dependsOn(mainRuntimeClasspath)
75 classpath(mainRuntimeClasspath)
76 mainClass.set(application.mainClass)
77 standardInput = System.`in`
78 group = "run"
79 description = "Start a Jetty web server serving the Xtext API without assets."
80 }
71} 81}
diff --git a/subprojects/language-web/src/main/java/tools/refinery/language/web/ServerLauncher.java b/subprojects/language-web/src/main/java/tools/refinery/language/web/ServerLauncher.java
index 3e1d811b..d633b3fc 100644
--- a/subprojects/language-web/src/main/java/tools/refinery/language/web/ServerLauncher.java
+++ b/subprojects/language-web/src/main/java/tools/refinery/language/web/ServerLauncher.java
@@ -33,7 +33,7 @@ import java.util.EnumSet;
33import java.util.Set; 33import java.util.Set;
34 34
35public class ServerLauncher { 35public class ServerLauncher {
36 public static final String DEFAULT_LISTEN_ADDRESS = "localhost"; 36 public static final String DEFAULT_LISTEN_HOST = "localhost";
37 37
38 public static final int DEFAULT_LISTEN_PORT = 1312; 38 public static final int DEFAULT_LISTEN_PORT = 1312;
39 39
@@ -105,7 +105,7 @@ public class ServerLauncher {
105 105
106 private Resource getBaseResource() { 106 private Resource getBaseResource() {
107 var factory = ResourceFactory.of(server); 107 var factory = ResourceFactory.of(server);
108 var baseResourceOverride = System.getenv("BASE_RESOURCE"); 108 var baseResourceOverride = System.getenv("REFINERY_BASE_RESOURCE");
109 if (baseResourceOverride != null) { 109 if (baseResourceOverride != null) {
110 // If a user override is provided, use it. 110 // If a user override is provided, use it.
111 return factory.newResource(baseResourceOverride); 111 return factory.newResource(baseResourceOverride);
@@ -155,15 +155,15 @@ public class ServerLauncher {
155 } 155 }
156 156
157 private static String getListenAddress() { 157 private static String getListenAddress() {
158 var listenAddress = System.getenv("LISTEN_ADDRESS"); 158 var listenAddress = System.getenv("REFINERY_LISTEN_HOST");
159 if (listenAddress == null) { 159 if (listenAddress == null) {
160 return DEFAULT_LISTEN_ADDRESS; 160 return DEFAULT_LISTEN_HOST;
161 } 161 }
162 return listenAddress; 162 return listenAddress;
163 } 163 }
164 164
165 private static int getListenPort() { 165 private static int getListenPort() {
166 var portStr = System.getenv("LISTEN_PORT"); 166 var portStr = System.getenv("REFINERY_LISTEN_PORT");
167 if (portStr != null) { 167 if (portStr != null) {
168 return Integer.parseInt(portStr); 168 return Integer.parseInt(portStr);
169 } 169 }
@@ -177,7 +177,7 @@ public class ServerLauncher {
177 } 177 }
178 178
179 private static String getPublicHost() { 179 private static String getPublicHost() {
180 var publicHost = System.getenv("PUBLIC_HOST"); 180 var publicHost = System.getenv("REFINERY_PUBLIC_HOST");
181 if (publicHost != null) { 181 if (publicHost != null) {
182 return publicHost.toLowerCase(); 182 return publicHost.toLowerCase();
183 } 183 }
@@ -185,7 +185,7 @@ public class ServerLauncher {
185 } 185 }
186 186
187 private static int getPublicPort() { 187 private static int getPublicPort() {
188 var portStr = System.getenv("PUBLIC_PORT"); 188 var portStr = System.getenv("REFINERY_PUBLIC_PORT");
189 if (portStr != null) { 189 if (portStr != null) {
190 return Integer.parseInt(portStr); 190 return Integer.parseInt(portStr);
191 } 191 }
@@ -193,7 +193,7 @@ public class ServerLauncher {
193 } 193 }
194 194
195 private static String[] getAllowedOrigins() { 195 private static String[] getAllowedOrigins() {
196 var allowedOrigins = System.getenv("ALLOWED_ORIGINS"); 196 var allowedOrigins = System.getenv("REFINERY_ALLOWED_ORIGINS");
197 if (allowedOrigins != null) { 197 if (allowedOrigins != null) {
198 return allowedOrigins.split(ALLOWED_ORIGINS_SEPARATOR); 198 return allowedOrigins.split(ALLOWED_ORIGINS_SEPARATOR);
199 } 199 }
@@ -222,12 +222,10 @@ public class ServerLauncher {
222 int port; 222 int port;
223 var publicHost = getPublicHost(); 223 var publicHost = getPublicHost();
224 if (publicHost == null) { 224 if (publicHost == null) {
225 host = getListenAddress(); 225 return null;
226 port = getListenPort();
227 } else {
228 host = publicHost;
229 port = getPublicPort();
230 } 226 }
227 host = publicHost;
228 port = getPublicPort();
231 var scheme = port == HTTPS_DEFAULT_PORT ? "wss" : "ws"; 229 var scheme = port == HTTPS_DEFAULT_PORT ? "wss" : "ws";
232 return String.format("%s://%s:%d/xtext-service", scheme, host, port); 230 return String.format("%s://%s:%d/xtext-service", scheme, host, port);
233 } 231 }
diff --git a/subprojects/language-web/src/main/java/tools/refinery/language/web/config/BackendConfigServlet.java b/subprojects/language-web/src/main/java/tools/refinery/language/web/config/BackendConfigServlet.java
index a2f04e34..7d0a5122 100644
--- a/subprojects/language-web/src/main/java/tools/refinery/language/web/config/BackendConfigServlet.java
+++ b/subprojects/language-web/src/main/java/tools/refinery/language/web/config/BackendConfigServlet.java
@@ -25,9 +25,6 @@ public class BackendConfigServlet extends HttpServlet {
25 public void init(ServletConfig config) throws ServletException { 25 public void init(ServletConfig config) throws ServletException {
26 super.init(config); 26 super.init(config);
27 var webSocketUrl = config.getInitParameter(WEBSOCKET_URL_INIT_PARAM); 27 var webSocketUrl = config.getInitParameter(WEBSOCKET_URL_INIT_PARAM);
28 if (webSocketUrl == null) {
29 throw new IllegalArgumentException("Init parameter " + WEBSOCKET_URL_INIT_PARAM + " is mandatory");
30 }
31 var backendConfig = new BackendConfig(webSocketUrl); 28 var backendConfig = new BackendConfig(webSocketUrl);
32 var gson = new Gson(); 29 var gson = new Gson();
33 serializedConfig = gson.toJson(backendConfig); 30 serializedConfig = gson.toJson(backendConfig);