Dropwizard serving static html
I am currently building an app using dropwizard and angularjs. I configured my AssetsBundle like this:
bootstrap.addBundle(new AssetsBundle("/assets", "/", "index.html"));
My current problem is that I want multiple pages to render my index.html page (main page of angularjs app). Is there anyway I can define a set of urls for this whole index.html file? If I create more asset bundles this works, but this is not how it should be done:
bootstrap.addBundle(new AssetsBundle("/assets", "/login", "index.html", "login"));
bootstrap.addBundle(new AssetsBundle("/assets", "/my-leagues", "index.html", "my-leagues"));
bootstrap.addBundle(new AssetsBundle("/assets", "/registering-leagues", "index.html", "registering-leagues"));
bootstrap.addBundle(new AssetsBundle("/assets", "/league-register/*", "index.html", "league-register"));
bootstrap.addBundle(new AssetsBundle("/assets", "/", "index.html", "home"));
My goal currently is for the index.html page to be served for / login, / my-leagues, / registering-leagues, / league-register / * (where * can be any number), and /. This hacked solution does not work for the "/ league-register / *" asset as the asset bundle does not support wild cards.
Is there an easy way to specify specific endpoints to return my index.html file?
Thank!
source to share
I figured out how to do this, but not sure if this is the best solution. I created a servlet that just serves my index.html file. Inside my launch function, I added:
environment.getApplicationContext().addServlet(new ServletHolder(new BaseServlet()), "/login");
environment.getApplicationContext().addServlet(new ServletHolder(new BaseServlet()), "/my-leagues");
environment.getApplicationContext().addServlet(new ServletHolder(new BaseServlet()), "/registering-leagues");
environment.getApplicationContext().addServlet(new ServletHolder(new BaseServlet()), "/league-register/*");
My BaseServlet looks like this:
public class BaseServlet extends HttpServlet {
public void doGet(HttpServletRequest req, HttpServletResponse resp)
throws IOException, ServletException {
RequestDispatcher view = req.getRequestDispatcher("/index.html");
view.forward(req, resp);
}
}
source to share