This commit is contained in:
Mathieu Sanchez 2019-06-12 17:33:54 +09:00
parent 638eb97390
commit 8314a770f1

View File

@ -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<Result> 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<Result> getResults(String[] words) throws Exception {