From cf4d7a849644303e89c34257918d3f7259b01872 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Przemek=20Draga=C5=84czuk?= Date: Fri, 14 Feb 2020 18:40:14 +0100 Subject: [PATCH] Added static file configuration to main --- src/main/java/tk/draganczuk/url/App.java | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) diff --git a/src/main/java/tk/draganczuk/url/App.java b/src/main/java/tk/draganczuk/url/App.java index 4ced994..6cf03a4 100644 --- a/src/main/java/tk/draganczuk/url/App.java +++ b/src/main/java/tk/draganczuk/url/App.java @@ -4,9 +4,24 @@ import static spark.Spark.*; public class App { - public static void main(String[] args) { + 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? + if (System.getenv("dev").equals("true")) { + String projectDir = System.getProperty("user.dir"); + String staticDir = "/src/main/resources/public"; + staticFiles.externalLocation(projectDir + staticDir); + } else { + staticFiles.location("/public"); + } + + get("/", (req, res) -> { + res.redirect("/index.html"); + return "Redirect"; + }); + get("/all", Routes::getAll); post("/new", Routes::addUrl); get("/:shortUrl", Routes::goToLongUrl); - } + } }