1

I'm following this project angular2-authentication-sample for angular2 js for authentication. I'm getting this problem Cross-Origin Request Blocked: The Same Origin Policy disallows reading the remote resource at http://localhost:8000/api/auth/register. (Reason: CORS header ‘Access-Control-Allow-Origin’ missing). when requesting to an signup endpoint.

I check different question and i added extra header in headers.

headers.ts

import { Headers } from '@angular/http';

export const contentHeaders = new Headers();
contentHeaders.append('Accept', 'application/json');
contentHeaders.append('Content-Type', 'application/json');
contentHeaders.append('Access-Control-Allow-Origin', '*');
contentHeaders.append('Access-Control-Request-Method', '*');
contentHeaders.append('Access-Control-Allow-Methods', '');
contentHeaders.append('Access-Control-Request-Headers', 'Origin, Content-Type, Accept');

I'm not able to slove this CROS problem.

Community
  • 1
  • 1
Seenu S
  • 3,381
  • 6
  • 30
  • 45

1 Answers1

1

This needs to be solved on the server side, The server that provides whichever service you are calling from your localhost angular app.

If i understood your description the problem is that your are trying to add headers configurations in your client side app. But in order to allow CORS sharing some headers should be added on the server.

See MDN detailed explanation

The Cross-Origin Resource Sharing standard works by adding new HTTP headers that allow servers to describe the set of origins that are permitted to read that information using a web browser.

Yinon
  • 697
  • 7
  • 13