Dropwizard AssetsBundle 和 Angular 2 路径
Dropwizard AssetsBundle and Angular 2 path
我正在使用 dropwizard AssetsBundle 服务于 Angular 2 个应用程序。
现在,angular 2 应用程序路径具有以下模式:
http://host.com/base/route,
其中 http://host.com/base has to be rerouted to http://host.com/base/index.html 和 "route" 部分由 Angular 客户端代码解析和处理。
不幸的是,AssetsBundle 无法通过 http://host.com/base/route 路径找到任何资源,并且 returns 404 错误而不是将请求重新路由到 http://host。com/base/index .html.
知道如何处理吗?
我可以编写自己的 AssetsBundle 来处理这种情况,但如果有任何解决方法,我想避免它。
谢谢。
根据 Dropwizard usergroup 的讨论,可以使用 IndexPageBundle 插件来实现:
用户组线程:https://groups.google.com/forum/#!topic/dropwizard-user/a8Gikq_0wcg
@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));
}
我正在使用 dropwizard AssetsBundle 服务于 Angular 2 个应用程序。 现在,angular 2 应用程序路径具有以下模式: http://host.com/base/route, 其中 http://host.com/base has to be rerouted to http://host.com/base/index.html 和 "route" 部分由 Angular 客户端代码解析和处理。
不幸的是,AssetsBundle 无法通过 http://host.com/base/route 路径找到任何资源,并且 returns 404 错误而不是将请求重新路由到 http://host。com/base/index .html.
知道如何处理吗? 我可以编写自己的 AssetsBundle 来处理这种情况,但如果有任何解决方法,我想避免它。
谢谢。
根据 Dropwizard usergroup 的讨论,可以使用 IndexPageBundle 插件来实现:
用户组线程:https://groups.google.com/forum/#!topic/dropwizard-user/a8Gikq_0wcg
@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));
}