Dropwizard AssetsBundle and Angular 2 path



我正在使用dropwizard AssetsBundle服务于Angular 2应用程序。 现在,角度 2 应用路径具有以下模式: http://host.com/base/route, 其中 http://host.com/base 必须重新路由到 http://host.com/base/index.html,"路由"部分由 Angular 客户端代码解析和处理。

不幸的是,AssetsBundle 无法通过路径 http://host.com/base/route 找到任何资源,并返回 404 错误,而不是将请求重新路由到 http://host.com/base/index.html。

知道如何处理吗? 我可以编写自己的 AssetsBundle 来处理这种情况,但如果有任何解决方法,我想避免它。

谢谢。

从 Dropwizard 用户组的讨论中,可以使用 IndexPageBundle 插件来实现这一点:

用户组线程: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));
}

最新更新