2015-06-05 56 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); 
    } 
}