diff --git a/CAu_NLP_2019/src/main/java/com/nlp/App.java b/CAu_NLP_2019/src/main/java/com/nlp/App.java index c4cc586..d8d0b3a 100644 --- a/CAu_NLP_2019/src/main/java/com/nlp/App.java +++ b/CAu_NLP_2019/src/main/java/com/nlp/App.java @@ -11,8 +11,7 @@ import java.util.ArrayList; import java.util.Arrays; import java.util.List; -import static spark.Spark.get; -import static spark.Spark.port; +import static spark.Spark.*; public class App { @@ -24,6 +23,27 @@ public class App { ArrayList results = getResults(words); return gson.toJson(results); }); + options("/*", + (request, response) -> { + + String accessControlRequestHeaders = request + .headers("Access-Control-Request-Headers"); + if (accessControlRequestHeaders != null) { + response.header("Access-Control-Allow-Headers", + accessControlRequestHeaders); + } + + String accessControlRequestMethod = request + .headers("Access-Control-Request-Method"); + if (accessControlRequestMethod != null) { + response.header("Access-Control-Allow-Methods", + accessControlRequestMethod); + } + + return "OK"; + }); + + before((request, response) -> response.header("Access-Control-Allow-Origin", "*")); } private static ArrayList getResults(String[] words) throws Exception {