mirror of
https://github.com/xpipe-io/xpipe.git
synced 2026-05-03 19:30:31 +00:00
Rotate service URLs [stage] [arm]
This commit is contained in:
Vendored
+1
@@ -1,2 +1,3 @@
|
||||
- Fix some types connection entries being moved to default category after their configuration was edited
|
||||
- Fix bitwarden login issues when using custom server
|
||||
- Rotate service URLs to avoid browser cache issues when running multiple services on localhost
|
||||
|
||||
@@ -40,15 +40,7 @@ public abstract class AbstractServiceStore implements SingletonSessionStore<Netw
|
||||
}
|
||||
|
||||
public String getOpenTargetUrl() {
|
||||
var s = getSession();
|
||||
if (s == null) {
|
||||
var host = getHost().getStore().getTunnelHostName() != null
|
||||
? getHost().getStore().getTunnelHostName()
|
||||
: "localhost";
|
||||
return host + ":" + remotePort;
|
||||
}
|
||||
|
||||
return "localhost:" + s.getLocalPort();
|
||||
return ServiceAddressRotation.getRotatedAddress(this);
|
||||
}
|
||||
|
||||
public boolean requiresTunnel() {
|
||||
|
||||
@@ -0,0 +1,38 @@
|
||||
package io.xpipe.ext.base.service;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
public class ServiceAddressRotation {
|
||||
|
||||
private static final Map<String, String> replacedUrls = new HashMap<>();
|
||||
private static int counter = 0;
|
||||
private static final String[] aliases = new String[]{ "localhost", "127.0.0.1" };
|
||||
|
||||
private static String getRotatedLocalhost(String url) {
|
||||
if (!url.startsWith("localhost")) {
|
||||
return url;
|
||||
}
|
||||
|
||||
if (replacedUrls.containsKey(url)) {
|
||||
return replacedUrls.get(url);
|
||||
}
|
||||
|
||||
var alias = aliases[counter++ % aliases.length];
|
||||
var replaced = url.replace("localhost", alias);
|
||||
replacedUrls.put(url, replaced);
|
||||
return replaced;
|
||||
}
|
||||
|
||||
public static String getRotatedAddress(AbstractServiceStore serviceStore) {
|
||||
var s = serviceStore.getSession();
|
||||
if (s == null) {
|
||||
var host = serviceStore.getHost().getStore().getTunnelHostName() != null
|
||||
? serviceStore.getHost().getStore().getTunnelHostName()
|
||||
: "localhost";
|
||||
return getRotatedLocalhost(host + ":" + serviceStore.getRemotePort());
|
||||
}
|
||||
|
||||
return getRotatedLocalhost("localhost:" + s.getLocalPort());
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user