Answers for "'http://localhost:3000/api/posts' from origin 'http://localhost:4200' has been blocked by CORS policy: No 'Access-Control-Allow-Origin' header is present on the requested resource in Angular"

0

'http://localhost:3000/api/posts' from origin 'http://localhost:4200' has been blocked by CORS policy: No 'Access-Control-Allow-Origin' header is present on the requested resource in Angular

just add below code to you app.js and your all the error are gone thank me later 

app.use((req, res, next) => {
  res.setHeader("Access-Control-Allow-Origin", "*");
  res.setHeader(
    "Access-Control-Allow-Headers",
    "Origin,X-Requested-With,Content-Type,Accept"
  );
  res.setHeader(
    "Access-Control-Allow-Methods",
    "GET,POST,PUT,PATCH,DELETE,OPTIONS"
  );
  next();
});
Posted by: Guest on March-11-2022
0

from origin 'http://localhost:4200' has been blocked by CORS policy: No 'Access-Control-Allow-Origin' header is present on the requested resource.

@CrossOrigin(origins = "http://localhost:4200")
@GetMapping("/yourPath")
Posted by: Guest on December-31-2020

Code answers related to "'http://localhost:3000/api/posts' from origin 'http://localhost:4200' has been blocked by CORS policy: No 'Access-Control-Allow-Origin' header is present on the requested resource in Angular"

Code answers related to "Javascript"

Browse Popular Code Answers by Language