2015-06-05 53 views
3

我目前正在使用dropwizard和angularjs构建一个应用程序。我安装我的AssetsBundle像这样:Dropwizard服务静态HTML

bootstrap.addBundle(new AssetsBundle("/assets", "/", "index.html")); 

我现在的问题是,我想多页为我的index.html页面(主要angularjs应用页面)。无论如何,我可以定义一组url来为所有这个index.html文件提供服务吗?如果我创造更多的资产包然而,这会工作,这是不应该怎么做:目前

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")); 

我的目标是让index.html页面送达/登录,/我的联赛,/注册/联赛注册/ *(其中*可以是任何数字)和/。这个hacky解决方案不适用于“/ league-register/*”资产,因为资产包不支持通配符。

有没有一种简单的方法来指定某些终点来返回我的index.html文件?

谢谢!

回答

0

我想出了如何做到这一点,但仍不确定这是否是最好的解决方案。我创建了一个只服务于我的index.html文件的servlet。在我的运行功能,我已经加入:

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/*"); 

我BaseServlet看起来是这样的:

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); 
    } 
}