2
0
Fork 0
mirror of https://github.com/ethauvin/rife2.git synced 2025-04-30 18:48:13 -07:00

Split out server root URL and webapp root URL

This commit is contained in:
Geert Bevin 2022-11-08 08:59:29 -05:00
parent eefb7f5a75
commit 62e1d4a31c
4 changed files with 13 additions and 20 deletions

View file

@ -342,7 +342,6 @@ public class RifeConfig {
private boolean fileUploadSizeException_ = DEFAULT_FILE_UPLOAD_SIZE_EXCEPTION;
private boolean gzipCompression_ = DEFAULT_GZIP_COMPRESSION;
private Collection<String> gzipCompressionTypes_ = DEFAULT_GZIP_COMPRESSION_TYPES;
private int localForwardPort_ = DEFAULT_LOCAL_FORWARD_PORT;
private String proxyRootUrl_ = DEFAULT_PROXY_ROOT_URL;
private String webappContextPath_ = DEFAULT_WEBAPP_CONTEXT_PATH;
private Set<String> passThroughSuffixes = DEFAULT_PASS_THROUGH_SUFFIXES;
@ -367,7 +366,6 @@ public class RifeConfig {
"application/xml",
"application/xhtml+xml"
);
public static final int DEFAULT_LOCAL_FORWARD_PORT = -1;
public static final String DEFAULT_PROXY_ROOT_URL = null;
public static final String DEFAULT_WEBAPP_CONTEXT_PATH = null;
public static final Set<String> DEFAULT_PASS_THROUGH_SUFFIXES = new HashSet<>() {{
@ -489,16 +487,6 @@ public class RifeConfig {
return this;
}
public int getLocalForwardPort() {
return localForwardPort_;
}
public EngineConfig setLocalForwardPort(int port) {
if (port <= 0) port = -1;
localForwardPort_ = port;
return this;
}
public String getProxyRootUrl() {
return proxyRootUrl_;
}

View file

@ -222,13 +222,8 @@ public class Context {
return gateUrl_;
}
public String webappRootUrl(int port) {
if (RifeConfig.engine().getProxyRootUrl() != null) {
return RifeConfig.engine().getProxyRootUrl();
}
public String webappRootUrl() {
var webapp_root = new StringBuilder();
webapp_root.append(serverRootUrl(port));
var gate_url = gateUrl();
if (!gate_url.startsWith("/")) {
webapp_root.append("/");
@ -243,7 +238,7 @@ public class Context {
}
public UrlBuilder urlFor(Route route) {
return new UrlBuilder(webappRootUrl(-1), route);
return new UrlBuilder(webappRootUrl(), route);
}
void engineException(Throwable exception) {

View file

@ -8,7 +8,6 @@ import rife.Version;
import rife.config.RifeConfig;
import rife.engine.exceptions.DeferException;
import rife.engine.exceptions.RedirectException;
import rife.template.Template;
import rife.template.TemplateFactory;
import rife.tools.ExceptionFormattingUtils;
import rife.tools.ExceptionUtils;
@ -19,6 +18,7 @@ import java.util.logging.Logger;
public class Gate {
private Site site_;
private Throwable initException_ = null;
private final String webappContextPath_ = RifeConfig.engine().getWebappContextPath();
public void setup(Site site) {
site_ = site;
@ -32,6 +32,12 @@ public class Gate {
}
public boolean handleRequest(String gateUrl, String elementUrl, Request request, Response response) {
// check if the gateUrl hasn't been overridden by a webapp context path configuration parameter
if (webappContextPath_ != null)
{
gateUrl = webappContextPath_;
}
// ensure a valid element url
if (null == elementUrl ||
0 == elementUrl.length()) {

View file

@ -344,6 +344,10 @@ public class HttpRequest implements Request {
@Override
public String getServerRootUrl(int port) {
if (RifeConfig.engine().getProxyRootUrl() != null) {
return RifeConfig.engine().getProxyRootUrl();
}
var server_root = new StringBuilder();
server_root.append(getScheme());
server_root.append("://");