Dropwizard 0.8.0:从 / 提供静态资产
Dropwizard 0.8.0: serve static assets from /
我希望我的服务器提供来自 /
的静态 html 文件。此外,css 和 js 文件应分别从 /css
和 /js
提供。所有 json 数据都应该可以在 /api
.
上访问
但是,我得到了 http://localhost:8080/
或任何其他路径的 404。
我在配置文件中使用了以下设置:
server:
type: simple
rootPath: /api/*
application.initialize 方法如下所示:
@Override
public void initialize(io.dropwizard.setup.Bootstrap<MyConfiguration> bootstrap) {
bootstrap.addBundle(new AssetsBundle("/assets/css", "/css", null, "css"));
bootstrap.addBundle(new AssetsBundle("/assets/js", "/js", null, "js"));
bootstrap.addBundle(new AssetsBundle("/assets/pages", "/", "index.html", "html"));
}
我刚刚不得不解决一个类似的问题(The documentation 不是最清楚的,尽管事后看来我猜大部分信息都在某处),我通过设置两者解决了我的应用程序配置中的 applicationContextPath
和 rootPath
:
server:
type: simple
rootPath: /api/*
applicationContextPath: /
default value for applicationContextPath
is "/application
" in a simple server,所以你的完整根路径应该是“/application/api/*
”。如果您不需要使用 simple 服务器,您也可以使用 default 服务器,它的 applicationContextPath 设置为“/
" 默认:
server:
rootPath: /api/*
我希望我的服务器提供来自 /
的静态 html 文件。此外,css 和 js 文件应分别从 /css
和 /js
提供。所有 json 数据都应该可以在 /api
.
但是,我得到了 http://localhost:8080/
或任何其他路径的 404。
我在配置文件中使用了以下设置:
server:
type: simple
rootPath: /api/*
application.initialize 方法如下所示:
@Override
public void initialize(io.dropwizard.setup.Bootstrap<MyConfiguration> bootstrap) {
bootstrap.addBundle(new AssetsBundle("/assets/css", "/css", null, "css"));
bootstrap.addBundle(new AssetsBundle("/assets/js", "/js", null, "js"));
bootstrap.addBundle(new AssetsBundle("/assets/pages", "/", "index.html", "html"));
}
我刚刚不得不解决一个类似的问题(The documentation 不是最清楚的,尽管事后看来我猜大部分信息都在某处),我通过设置两者解决了我的应用程序配置中的 applicationContextPath
和 rootPath
:
server:
type: simple
rootPath: /api/*
applicationContextPath: /
default value for applicationContextPath
is "/application
" in a simple server,所以你的完整根路径应该是“/application/api/*
”。如果您不需要使用 simple 服务器,您也可以使用 default 服务器,它的 applicationContextPath 设置为“/
" 默认:
server:
rootPath: /api/*