Dropwizard服务静态HTML

时间:2015-06-05 21:10:18

标签: java angularjs dropwizard

我目前正在使用dropwizard和angularjs构建应用程序。我已经设置了我的AssetsBundle:

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

我当前的问题是我想要多个页面来提供我的index.html页面(主要的angularjs应用程序页面)。无论如何我可以定义一组url来为这个index.html文件提供服务吗?如果我创建更多资产包,这将有效,但这不是应该如何完成的:

    bootstrap.addBundle(new AssetsBundle("/assets", "/login", "index.html", "login"));
    bootstrap.addBundle(new AssetsBundle("/assets", "/my-leagues", "index.html", "my-leagues"));
    bootstrap.addBundle(new AssetsBundle("/assets", "/registering-leagues", "index.html", "registering-leagues"));
    bootstrap.addBundle(new AssetsBundle("/assets", "/league-register/*", "index.html", "league-register"));
    bootstrap.addBundle(new AssetsBundle("/assets", "/", "index.html", "home"));

我目前的目标是为/ login,/ my-leagues,/ registrationing-leagues,/ league-register / *(其中*可以是任意数字)和/提供index.html页面。这个hacky解决方案不适用于" / league-register / *"资产捆绑资产不支持外卡。

是否有一种简单的方法可以指定某些端点来返回我的index.html文件?

谢谢!

1 个答案:

答案 0 :(得分:0)

我想出了如何做到这一点,但仍然不确定这是否是最好的解决方案。我创建了一个servlet来提供我的index.html文件。在我的运行功能中,我添加了:

public class BaseServlet extends HttpServlet {

    public void doGet(HttpServletRequest req, HttpServletResponse resp)
        throws IOException, ServletException {

        RequestDispatcher view = req.getRequestDispatcher("/index.html");

        view.forward(req, resp);
    }
}

我的BaseServlet如下所示:

SELECT hosts.HostName,
       clients.Name,
       GROUP_CONCAT(cimdata.CIM_Item SEPARATOR ", ") AS CIM_Items,
       types.DataStatus,
       datediff(NOW(), scans.Time)
FROM plugin_sw_vmware_healthmon_hosts AS hosts
JOIN (SELECT ClientID,
             LocationID,
             HostName,
             max(ScanTime) AS 'Time'
      FROM labtech.plugin_sw_vmware_healthmon_scans
      GROUP BY ClientID,
            LocationID,
            HostName) AS scans ON hosts.ClientID=scans.ClientID
  AND hosts.LocationID=scans.LocationID
  AND hosts.HostName=scans.HostName
JOIN clients ON hosts.ClientID=clients.ClientID
JOIN plugin_sw_vmware_healthmon_cimdata AS cimdata ON hosts.ClientID=cimdata.ClientID
  AND hosts.LocationID=cimdata.LocationID
  AND hosts.HostName=cimdata.HostName
JOIN plugin_sw_vmware_healthmon_types AS types ON cimdata.CIM_Value=types.DataValue
  AND hosts.Vender=types.DataType
WHERE cimdata.CIM_Item LIKE '%critical array%'
GROUP BY hosts.HostName,
       clients.Name,
       types.DataStatus,
       datediff(NOW(), scans.Time)
ORDER BY clients.Name;