Add CORS
This commit is contained in:
parent
638eb97390
commit
8314a770f1
@ -11,8 +11,7 @@ import java.util.ArrayList;
|
|||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import static spark.Spark.get;
|
import static spark.Spark.*;
|
||||||
import static spark.Spark.port;
|
|
||||||
|
|
||||||
public class App {
|
public class App {
|
||||||
|
|
||||||
@ -24,6 +23,27 @@ public class App {
|
|||||||
ArrayList<Result> results = getResults(words);
|
ArrayList<Result> results = getResults(words);
|
||||||
return gson.toJson(results);
|
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 {
|
private static ArrayList<Result> getResults(String[] words) throws Exception {
|
||||||
|
Loading…
Reference in New Issue
Block a user