use of com.linecorp.armeria.server.file.FileService in project curiostack by curioswitch.
the class StaticSiteService method addToServer.
/**
* Creates a new {@link StaticSiteService}.
*
* @param staticPath the URL path from which static resources will be served, e.g., "/static".
* @param classpathRoot the root directory in the classpath to serve resources from.
*/
public static void addToServer(String urlRoot, String staticPath, String classpathRoot, ServerBuilder sb) {
FileService staticFileService = FileService.builder(StaticSiteService.class.getClassLoader(), classpathRoot).serveCompressedFiles(true).cacheControl(ServerCacheControl.IMMUTABLE).addHeader(HttpHeaderNames.VARY, "Accept-Encoding").build();
HttpService indexHtmlService = HttpFile.builder(StaticSiteService.class.getClassLoader(), classpathRoot + "/index.html").cacheControl(ServerCacheControl.DISABLED).build().asService();
TrailingSlashAddingService indexService = FileService.builder(StaticSiteService.class.getClassLoader(), classpathRoot).serveCompressedFiles(true).cacheControl(ServerCacheControl.DISABLED).build().orElse(indexHtmlService).decorate(TrailingSlashAddingService::new);
String urlRootWithTrailingSlash = urlRoot.endsWith("/") ? urlRoot : urlRoot + "/";
String staticPathWithoutLeadingSlash = staticPath.startsWith("/") ? staticPath.substring(1) : staticPath;
sb.serviceUnder(urlRootWithTrailingSlash + staticPathWithoutLeadingSlash, staticFileService).serviceUnder(urlRootWithTrailingSlash, indexService);
}
Aggregations