44 lines
1.0 KiB
Java
Raw Normal View History

2020-02-13 23:52:33 +01:00
package tk.draganczuk.url;
2020-02-16 15:46:29 +01:00
import spark.Filter;
2020-02-13 23:52:33 +01:00
import static spark.Spark.*;
public class App {
public static void main(String[] args) {
// Useful for developing the frontend
// http://sparkjava.com/documentation#examples-and-faq -> How do I enable automatic refresh of static files?
2020-02-14 20:11:02 +01:00
if (System.getenv("dev") != null) {
String projectDir = System.getProperty("user.dir");
String staticDir = "/src/main/resources/public";
staticFiles.externalLocation(projectDir + staticDir);
} else {
staticFiles.location("/public");
}
2020-02-14 18:42:21 +01:00
port(Integer.parseInt(System.getProperty("port", "4567")));
2020-02-16 15:46:29 +01:00
// Add GZIP compression
after(Filters::addGZIP);
// Authenticate
Filter authFilter = Filters.createAuthFilter();
before("/index.html", authFilter);
get("/", (req, res) -> {
res.redirect("/index.html");
return "Redirect";
});
2020-02-16 15:46:29 +01:00
path("/api", () -> {
before("/*", authFilter);
get("/all", Routes::getAll);
post("/new", Routes::addUrl);
});
2020-02-13 23:52:33 +01:00
get("/:shortUrl", Routes::goToLongUrl);
}
2020-02-13 23:52:33 +01:00
}