0

I have a frontend webapp developed with React JS, and a rest API built with Spring boot. When I try to access to API from my react-app I get a 403 Error. My API Rest is deploy in tomcat server.

POST http://localhost:8080/fantasy/api/auth/signin 403
PostData.js:3 Uncaught (in promise) SyntaxError: Unexpected end of JSON input
2
  • 1
    Not enough information Commented Jun 7, 2019 at 6:46
  • We need more information in order to tell you something. First, you could provide us with some log from your frontend app. Then, give us the rest endpoints you are trying to reach. Additionally, tell us the configuration your rest api has. Commented Jun 7, 2019 at 6:50

1 Answer 1

2

Most likely your ReactJs app and Spring Boot app are running under different ports and you did not configure CORS in the Spring Rest mapped methods in order enable incoming requests from the host:port on which ReactJs is running:

@CrossOrigin(origins = "http://localhost:4200")
@GetMapping("/user")
public Greeting getUser(){}

You can also define it on the Controller itself:

@CrossOrigin(origins = "http://localhost:4200")
@RestController

You can also register a separate CORS filter for entire application: reference

Sign up to request clarification or add additional context in comments.

8 Comments

In development is a good idea, but if in production my application change port number?
You then use the CORS filter strategy. In the filter you inject a port number from your properties file which will be different for a dev and prod of course.
How I could do that?
I have placed a reference in the answer. Look it up
CORS filter strategy in my spring boot could be in conflict with Tomcat CORS configuration?
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.