Soluciono problema para recibir peticiones incorporando CORS

parent 91dbd540
...@@ -10,6 +10,12 @@ import spark.*; ...@@ -10,6 +10,12 @@ import spark.*;
public class AppConfig { public class AppConfig {
public static void main(String[] args) { public static void main(String[] args) {
before((request, response) -> {
response.header("Access-Control-Allow-Origin", "*");
response.header("Access-Control-Allow-Methods", "GET, POST, PUT, DELETE, OPTIONS");
response.header("Access-Control-Allow-Headers", "Content-Type, Authorization, X-Requested-With");
response.type("application/json");
});
get("/hello", (req, res) -> "Respeto"); get("/hello", (req, res) -> "Respeto");
get("/hello", (req, res) -> { get("/hello", (req, res) -> {
......
...@@ -7,11 +7,19 @@ import static spark.Spark.*; ...@@ -7,11 +7,19 @@ import static spark.Spark.*;
public class SparkRest public class SparkRest
{ {
public static void main(String[] args) { public static void main(String[] args) {
port(8088); port(8088);
final CircuitoService circuitoService = new CircuitoServiceMapImpl() final CircuitoService circuitoService = new CircuitoServiceMapImpl()
{}; {};
post("/circuito", (request, response) -> { before((request, response) -> {
response.header("Access-Control-Allow-Origin", "*");
response.header("Access-Control-Allow-Methods", "GET, POST, PUT, DELETE, OPTIONS");
response.header("Access-Control-Allow-Headers", "Content-Type, Authorization, X-Requested-With");
response.type("application/json");
});
post("/circuitos", (request, response) -> {
response.type("application/json"); response.type("application/json");
Circuito circuito = new Gson().fromJson(request.body(), Circuito.class); Circuito circuito = new Gson().fromJson(request.body(), Circuito.class);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment