Added Basic auth and GZIP compression

This commit is contained in:
Przemek Dragańczuk
2020-02-16 15:46:29 +01:00
parent eba16d518e
commit 59b6d43aea
4 changed files with 39 additions and 4 deletions

View File

@@ -1,5 +1,7 @@
package tk.draganczuk.url;
import spark.Filter;
import static spark.Spark.*;
public class App {
@@ -17,13 +19,25 @@ public class App {
port(Integer.parseInt(System.getProperty("port", "4567")));
// Add GZIP compression
after(Filters::addGZIP);
// Authenticate
Filter authFilter = Filters.createAuthFilter();
before("/index.html", authFilter);
get("/", (req, res) -> {
res.redirect("/index.html");
return "Redirect";
});
get("/all", Routes::getAll);
post("/new", Routes::addUrl);
path("/api", () -> {
before("/*", authFilter);
get("/all", Routes::getAll);
post("/new", Routes::addUrl);
});
get("/:shortUrl", Routes::goToLongUrl);
}
}