@Provides
@Singleton
public Server getServer(final Injector injector, Connector connector) {
WebServerConfig webServerConfig = injector.getInstance(WebServerConfig.class);
String staticDir = webServerConfig.getStaticDirectory();
Server server = new Server();
server.addConnector(connector);
ServletContextHandler servletHandler = new ServletContextHandler();
servletHandler.addEventListener(new GuiceServletContextListener() {
@Override
protected Injector getInjector() {
return injector;
}
});
servletHandler.setSecurityHandler(makeSecurityHandler(webServerConfig.getPassword()));
servletHandler.addFilter(GuiceFilter.class, "/*", null);
servletHandler.addServlet(DefaultServlet.class, "/*");
servletHandler.setInitParameter("org.eclipse.jetty.servlet.Default.resourceBase", staticDir);
servletHandler.setInitParameter("maxCacheSize", "0");
servletHandler.setInitParameter("cacheControl", "no-cache, max-age=0");
server.setHandler(servletHandler);
return server;
}