in webindex/modules/ui/src/main/java/webindex/ui/WebServer.java [98:138]
public void start(IndexClient client, int port, Path templatePath) {
this.client = client;
Spark.port(port);
staticFiles.location("/assets");
FreeMarkerEngine freeMarkerEngine = new FreeMarkerEngine();
if (templatePath != null && Files.exists(templatePath)) {
log.info("Serving freemarker templates from {}", templatePath.toAbsolutePath());
Configuration freeMarkerConfig = new Configuration();
try {
freeMarkerConfig.setDirectoryForTemplateLoading(templatePath.toFile());
} catch (IOException e) {
throw new IllegalStateException(e);
}
freeMarkerEngine.setConfiguration(freeMarkerConfig);
}
get("/", (req, res) -> new ModelAndView(null, "home.ftl"), freeMarkerEngine);
get("/top",
(req, res) -> new ModelAndView(Collections.singletonMap("top", getTop(req)), "top.ftl"),
freeMarkerEngine);
Gson gson = new Gson();
get("/api/top", (req, res) -> getTop(req), gson::toJson);
get("/page",
(req, res) -> new ModelAndView(Collections.singletonMap("page", getPage(req)), "page.ftl"),
freeMarkerEngine);
get("/api/page", (req, res) -> getPage(req), gson::toJson);
get("/pages", (req, res) -> new ModelAndView(Collections.singletonMap("pages", getPages(req)),
"pages.ftl"), freeMarkerEngine);
get("/api/pages", (req, res) -> getPages(req), gson::toJson);
get("/links", (req, res) -> new ModelAndView(Collections.singletonMap("links", getLinks(req)),
"links.ftl"), freeMarkerEngine);
get("/api/links", (req, res) -> getLinks(req), gson::toJson);
}