I am trying to decide how to support Angular 2 PathLocationHandler with an integrated Jetty server. To do this, as I understand it, I need to redirect any 404 request to the top-level index.html file ( https://stackoverflow.com/a/135479/ )
I figured out how to do this in order to provide ContextHandler and ErrorHandler that redirected all 404 requests back to /index.html with something like the code below (I actually do this in a context text file, but it might be easier to conceptualize / debug).
What I see is that my error handler is completely ignored, and I'm not sure how to fix it, or, alternatively, how I should configure things.
import org.eclipse.jetty.server.Server;
import org.eclipse.jetty.server.handler.ContextHandler;
import org.eclipse.jetty.server.handler.ResourceHandler;
import org.eclipse.jetty.servlet.ErrorPageErrorHandler;
public class JettyTest {
public static void main(String[] args) throws Exception {
Server server = new Server(8080);
ResourceHandler resourceHandler = new ResourceHandler();
resourceHandler.setResourceBase("/tmp/directory-with-just-an-index.html-file");
ContextHandler contextHandler = new ContextHandler("/context-path");
ErrorPageErrorHandler errorHandler = new ErrorPageErrorHandler();
errorHandler.addErrorPage(404, "/index.html");
contextHandler.setHandler(resourceHandler);
contextHandler.setErrorHandler(errorHandler);
server.setHandler(contextHandler);
server.start();
System.out.println("Started!");
server.join();
}
}
Jetty http://localhost:8080/context-path/some-file-which-is-not-present.html, , ResourceHandler resourceBase, ...
//no resource - try other handlers
super.handle(target, baseRequest, request, response);
return;
... ContextHandler, HttpChannelOverHttp 404, .
if (!_response.isCommitted() && !_request.isHandled())
_response.sendError(404);
, Jetty , ResourceHandler 404 - ? , , - , .
, https://www.eclipse.org/jetty/documentation/9.3.x/resource-handler.html ResourceHandler " , , (, 404s).", , , " ", .
!