2017-07-07 67 views
0

我使用的是提供Angular 2應用程序的dropwizard AssetsBundle。 現在,角2應用程序路徑有以下模式: http://host.com/base/route, 其中http://host.com/base必須重新路由到http://host.com/base/index.html,和「路由」部分由Angular客戶端代碼解析和處理。Dropwizard AssetsBundle和Angular 2路徑

不幸的是,AssetsBundle通過http://host.com/base/route路徑找不到任何資源,並返回404錯誤而不是重新路由請求到http://host.com/base/index.html

任何想法如何處理? 我可以編寫自己的AssetsBundle來處理這種情況,但如果有任何解決方法,我想避免它。

謝謝。

回答

0

Dropwizard usergroup的討論中,可以使用IndexPageBundle插件來實現這一目標:

Usergoup螺紋:https://groups.google.com/forum/#!topic/dropwizard-user/a8Gikq_0wcg

代碼示例:https://gitlab.com/linagora/petals-cockpit/blob/master/cockpit/src/main/java/org/ow2/petals/cockpit/PetalsCockpitApplication.java

@Override 
public void initialize(@Nullable Bootstrap<PetalsCockpitConfiguration> bootstrap) { 
    assert bootstrap != null; 

    super.initialize(bootstrap); 

    // TODO this is not the best because every new prefix must be added... if not, the static asset servlet will 
    // take over instead of returning index.html 
    // Improve when https://github.com/palantir/dropwizard-index-page/issues/38 is fixed 
    bootstrap.addBundle(new IndexPageBundle("frontend/index.html", 
      ImmutableSet.of("/", "/index.html", "/setup", "/login", "/workspaces", "/workspaces/*"))); 
    // no index file parameter because index is served by IndexPageBundle 
    bootstrap.addBundle(new AssetsBundle("/frontend", "/", null)); 
}