Created
September 12, 2015 18:42
-
-
Save tarrsalah/0332cb24033e25398d87 to your computer and use it in GitHub Desktop.
Grizzly web server with static files and gzip enabled
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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