2017-07-07 69 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)); 
}