I have the following configuration in my Main.java file. I check if the ZKUI_BASEURL is set in env or in properties file and then accordingly set the contextPath.
When I do this, the GET requests for the following css and js files which are in src/main/resources/webapp/ return 404. All the controller requests are working fine its just the static content which is not loaded.
What I want to do is serve static content and rest apis on /org/zkui/ base path, so that in future we can run this behind a reverse proxy.
String webFolder = "webapp";
Server server = new Server();
WebAppContext servletContextHandler = new WebAppContext();
String serverBaseUrl;
if( (serverBaseUrl = System.getenv("ZKUI_BASEURL")) == null) {
if((serverBaseUrl = globalProps.getProperty("baseURL")) == null) {
serverBaseUrl = "/";
}
}
servletContextHandler.setContextPath(serverBaseUrl);
servletContextHandler.setResourceBase("src/main/resources/" + webFolder);
servletContextHandler.setAttribute("org.eclipse.jetty.server.webapp.ContainerIncludeJarPattern", ".*(/target/classes/|.*.jar)");
servletContextHandler.setParentLoaderPriority(true);
servletContextHandler.setInitParameter("useFileMappedBuffer", "false");
servletContextHandler.setAttribute("globalProps", globalProps);
ResourceHandler staticResourceHandler = new ResourceHandler();
staticResourceHandler.setDirectoriesListed(false);
Resource staticResources = Resource.newClassPathResource(webFolder);
staticResourceHandler.setBaseResource(staticResources);
staticResourceHandler.setWelcomeFiles(new String[]{"html/index.html"});
Essentially what should happen is - /org/zkui/home should be handled by a controller.
/org/zkui/images/image.png or org/zkui/js/bootstrap.min.js should be returned by a static resource handler from /webapp/images or webapp/js.