2
0
Fork 0
mirror of https://github.com/ethauvin/rife2.git synced 2025-05-01 02:58:12 -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 fileUploadSizeException_ = DEFAULT_FILE_UPLOAD_SIZE_EXCEPTION;
private boolean gzipCompression_ = DEFAULT_GZIP_COMPRESSION; private boolean gzipCompression_ = DEFAULT_GZIP_COMPRESSION;
private Collection<String> gzipCompressionTypes_ = DEFAULT_GZIP_COMPRESSION_TYPES; private Collection<String> gzipCompressionTypes_ = DEFAULT_GZIP_COMPRESSION_TYPES;
private int localForwardPort_ = DEFAULT_LOCAL_FORWARD_PORT;
private String proxyRootUrl_ = DEFAULT_PROXY_ROOT_URL; private String proxyRootUrl_ = DEFAULT_PROXY_ROOT_URL;
private String webappContextPath_ = DEFAULT_WEBAPP_CONTEXT_PATH; private String webappContextPath_ = DEFAULT_WEBAPP_CONTEXT_PATH;
private Set<String> passThroughSuffixes = DEFAULT_PASS_THROUGH_SUFFIXES; private Set<String> passThroughSuffixes = DEFAULT_PASS_THROUGH_SUFFIXES;
@ -367,7 +366,6 @@ public class RifeConfig {
"application/xml", "application/xml",
"application/xhtml+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_PROXY_ROOT_URL = null;
public static final String DEFAULT_WEBAPP_CONTEXT_PATH = null; public static final String DEFAULT_WEBAPP_CONTEXT_PATH = null;
public static final Set<String> DEFAULT_PASS_THROUGH_SUFFIXES = new HashSet<>() {{ public static final Set<String> DEFAULT_PASS_THROUGH_SUFFIXES = new HashSet<>() {{
@ -489,16 +487,6 @@ public class RifeConfig {
return this; return this;
} }
public int getLocalForwardPort() {
return localForwardPort_;
}
public EngineConfig setLocalForwardPort(int port) {
if (port <= 0) port = -1;
localForwardPort_ = port;
return this;
}
public String getProxyRootUrl() { public String getProxyRootUrl() {
return proxyRootUrl_; return proxyRootUrl_;
} }

View file

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

View file

@ -8,7 +8,6 @@ import rife.Version;
import rife.config.RifeConfig; import rife.config.RifeConfig;
import rife.engine.exceptions.DeferException; import rife.engine.exceptions.DeferException;
import rife.engine.exceptions.RedirectException; import rife.engine.exceptions.RedirectException;
import rife.template.Template;
import rife.template.TemplateFactory; import rife.template.TemplateFactory;
import rife.tools.ExceptionFormattingUtils; import rife.tools.ExceptionFormattingUtils;
import rife.tools.ExceptionUtils; import rife.tools.ExceptionUtils;
@ -19,6 +18,7 @@ import java.util.logging.Logger;
public class Gate { public class Gate {
private Site site_; private Site site_;
private Throwable initException_ = null; private Throwable initException_ = null;
private final String webappContextPath_ = RifeConfig.engine().getWebappContextPath();
public void setup(Site site) { public void setup(Site site) {
site_ = site; site_ = site;
@ -32,6 +32,12 @@ public class Gate {
} }
public boolean handleRequest(String gateUrl, String elementUrl, Request request, Response response) { 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 // ensure a valid element url
if (null == elementUrl || if (null == elementUrl ||
0 == elementUrl.length()) { 0 == elementUrl.length()) {

View file

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