将dropwizard配置为(几乎)所有路由到服务器index.html? [英] Configure dropwizard to server index.html for (almost) all routes?

查看:116
本文介绍了将dropwizard配置为(几乎)所有路由到服务器index.html?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在构建一个单页面应用程序,该应用程序在客户端执行所有的html请求路由,在后端它使用dropwizard提供一堆JSON服务。

I'm building a single page application which does all of it's html request routing on the client side and on the backend it uses dropwizard to provide a bunch of JSON services.

从本质上来说,我很难在dropwizard中为每个请求提供index.html,但以下路径除外:

Essentially I'm having trouble getting the jetty in dropwizard to serve index.html for every request except to the following paths:

  /css
  /i18n
  /img
  /js
  /lib
  /services
  /templates

实际上,我在查找文档时遇到很多麻烦,这些文档告诉您如何设置所有http路由。 (我不是Java人)。

In fact I'm having a lot of trouble finding documentation that tells you how to setup any http routing at all. (I'm not a java guy).

这是我简单的yaml配置:

Here's my simple yaml config:`

http:
  port: 8082
  adminPort: 8083
  rootPath: /service/*`

我需要添加些什么来达到目的。

What do I need to add to acheive this.

谢谢

推荐答案

我无需更改配置即可完成此操作。实际上,我只花了一行代码就将其放入 Application 类的 initialize 方法中:

I've done this without changing my configuration. In fact, it only took me one line of code, to be put in the initialize method of my Application class:

bootstrap.addBundle(new AssetsBundle("/app", "/", "index.html", "static"));

基本上说要在 / app 在URL模式为 / 的我的JAR文件中,并以 index.html 作为默认文件。该捆绑软件将命名为 static ,但是您可以选择任何喜欢的名称。

Which basically says to serve anything under /app inside my JAR file under the URL pattern /, with index.html as the default file. This bundle will be named static, but you could pick whatever name you like.

请注意,我使用的版本是0.7.0-rc2 Dropwizard的版本,我不确定它是否也适用于早期版本。

Note that I'm using version 0.7.0-rc2 of Dropwizard, I'm not sure whether it works for earlier versions as well.

这篇关于将dropwizard配置为(几乎)所有路由到服务器index.html?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆