CORS errors when deploying Spring Boot and Angular app in Docker

awesomemypro :

I have deployed 3 docker containers - for the database, the backend (Spring boot) and the frontend (Angular). However, when I am visiting the website (Google Cloud VM), I am getting CORS error for all the requests to backends. The backend is run on 8080.

I am getting CORS when I am visiting the IP:80

Why is this happening? What is the workaround?

Here is the way I have used CrossOrigin in the controller.

@CrossOrigin("*")
@RestController
@RequestMapping("/api")
public class CustomerController {

Any help is appreciated.

markusw :

You are not allowed to call URLs from your scripts that are not found under the same domain that you page was rendered:

For security reasons, browsers restrict cross-origin HTTP requests initiated from scripts. For example, XMLHttpRequest and the Fetch API follow the same-origin policy. This means that a web application using those APIs can only request resources from the same origin the application was loaded from, unless the response from other origins includes the right CORS headers.

Source: https://developer.mozilla.org/en-US/docs/Web/HTTP/CORS

You actually have 3 Options:

  1. Add the 8080 port (port of your Spring Boots Tomcat server) to your exceptions (see: https://spring.io/guides/gs/rest-service-cors/)
  2. Use a reverse proxy like nginx that routes your requests to the API or serves the Angular resources depending on the request
  3. Serve the Angualr resources from your Spring Boot app

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

Externalising Spring Boot properties when deploying to Docker

SQLSyntaxErrorException when deploying Spring Boot app to Heroku

Deploying Spring boot App, to Heroku With Docker using github

Docker error when containerizing a spring boot app

[SOLVED]:'Unknown Error' when sending a POST request to my Spring Boot API Gateway from my Angular app and CORS is configured correctly

Error while deploying Spring boot app to Heroku

Deploying Spring boot app to digital ocean

A Problem while deploying Spring Boot + Angular application

NoSuchMethodError when deploying Spring Boot to Weblogic

java.lang.NoSuchMethodException when deploying spring-boot app to cloud foundry

Exception when running Spring Boot app inside of Docker

CORS errors using Spring Boot, Spring Security and React

Failure when deploying Spring App to Heroku

Error when deploying Angular app to Heroku

Spring Boot JWT CORS with Angular 6

Spring Boot JWT Cors Not Working with Angular 8

Unable to fix CORS issue with Spring Boot and Angular

How to enable CORS in Spring Boot and Angular

Angular 2 Spring Boot Login CORS Problems

Getting errors when deploying cordova app from visual studio 2015

How to containerize the spring boot application without installing docker and deploying in centos

Docker + nginx + angular +Spring Boot

CORS error when trying to fetch from Github API + Spring Boot to Angular

Deploying React App with Spring Boot REST API in AWS BeanStalk

Deploying embedded tomcat enabled spring-boot app using IntelliJ

Deploying Spring Boot App on Heroku - Build Success, but then: page could not be served

React Based app with spring boot bundled together as a WAR deploying in websphere

Not able to deploying spring boot app (1.2.5) war in tomcat 8

Deploying Existing Spring Boot Application on Google App Engine