O
O
opopsel_86x642021-11-30 14:42:58
Angular
opopsel_86x64, 2021-11-30 14:42:58

Why should I enable cross-site request support in Spring boot & Angular?

When developing a project with Spring and Angular, I must add the @CrossOrigin annotation to Spring controllers to enable CORS support.

A-priory

Cross-origin resource sharing is a modern browser technology that allows web pages to access resources from another domain.


If, during development, my Angular application starts on port 4200, and Spring boot on port 8080, then this is 2 domains.

Note: Even if your backend server is running on localhost with a different port, it is treated as a different domain.


But if I compile angular and put the sources in resources, then I already have 1 domain, why is CORS support required then, why is it not required if I create a simple ajax / fetch + spring application?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
D
Dmitry Roo, 2021-11-30
@opopsel_86x64

Use cross-origin for development.
In prod. environment, you will have some kind of http server (nginx, for example), which will solve all these issues

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question