Skip to content
Toggle navigation
P
Projects
G
Groups
S
Snippets
Help
Álvaro Herrera Arjonilla
/
f1_spark
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Merge Requests
0
Pipelines
Settings
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Commit
7f87ddb2
authored
Apr 27, 2023
by
Álvaro Herrera Arjonilla
Browse files
Options
_('Browse Files')
Download
Email Patches
Plain Diff
Soluciono problema para recibir peticiones incorporando CORS
parent
91dbd540
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
15 additions
and
1 deletions
src/main/java/com/example/demo/AppConfig.java
src/main/java/com/example/demo/SparkRest.java
src/main/java/com/example/demo/AppConfig.java
View file @
7f87ddb2
...
@@ -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
)
->
{
...
...
src/main/java/com/example/demo/SparkRest.java
View file @
7f87ddb2
...
@@ -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
);
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment