Skip to content

Instantly share code, notes, and snippets.

@tarrsalah
Created September 12, 2015 18:42
Show Gist options
  • Select an option

  • Save tarrsalah/0332cb24033e25398d87 to your computer and use it in GitHub Desktop.

Select an option

Save tarrsalah/0332cb24033e25398d87 to your computer and use it in GitHub Desktop.
Grizzly web server with static files and gzip enabled
public static HttpServer startHttpServer() {
HttpServer server = GrizzlyHttpServerFactory.createHttpServer(getApiURL(), new Application());
final StaticHttpHandler staticHandler = new StaticHttpHandler("src/main/webapp/dist");
staticHandler.setFileCacheEnabled(false); // change to true in the deploy time
server.getServerConfiguration().addHttpHandler(staticHandler, "/");
CompressionConfig compressionConfig
= server.getListener("grizzly").getCompressionConfig();
compressionConfig.setCompressionMode(CompressionConfig.CompressionMode.ON); // the mode
compressionConfig.setCompressionMinSize(1); // the min amount of bytes to compress
compressionConfig.setCompressableMimeTypes("text/plain", "text/html"); // the mime types to compress
return server;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment