angular: Angular Origin requests continue to be rejected by GCP/AWS server

RESOLVED: MAKE SURE YOU ARE USING THE RIGHT PORT.

I’m submitting a … (check one with “x”)

[x] bug report => search github for a similar issue or PR before submitting
[ ] feature request
[ ] support request => Please do not submit support request here, instead see https://github.com/angular/angular/blob/master/CONTRIBUTING.md#question

Current behavior

Making a call from localhost:4200 (by running ng serve) to a Node.JS/Express server returns this error: Response to preflight request doesn't pass access control check: No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://localhost:4200' is therefore not allowed access.

Expected behavior

The server should return relevant data in JSON format (which it usually does).

Minimal reproduction of the problem with instructions

  1. Make a service that calls to an HTTP endpoint.
headers = new Headers();
    constructor(public http: Http) {
        console.log('Hello RssFeedProvider Provider');
        this.headers.append('Content-Type', 'application/json');
    }
    getTeam(teamId) {
        return this.http.get(this.url + 'teams/' + teamId, {
            headers: this.headers
        }).map((results: Response) => {
            return results.json();
        });
    }
  1. Pipe the returned data into a component.
  2. Error in console

What is the motivation / use case for changing the behavior?

So people can test their HTTP services in Angular live reload before production.

Please tell us about your environment:

macOS 10.12 VS Code npm 4.0.5 node 6.9.1 Google App Engine

  • Angular version: 2.0.X

2.2.1

  • Browser: [all | Chrome XX | Firefox XX | IE XX | Safari XX | Mobile Chrome XX | Android X.X Web Browser | iOS XX Safari | iOS XX UIWebView | iOS XX WKWebView ]

Chrome 55.0.2883.95/Firefox 50.1.0

  • Language: [all | TypeScript X.X | ES6/7 | ES5] TypeScript 2.0.10
  • Node (for AoT issues): node --version = 6.9.1

About this issue

  • Original URL
  • State: closed
  • Created 8 years ago
  • Comments: 23 (7 by maintainers)

Most upvoted comments

I’m sorry, you’ll have to forgive me for being such an idiot.

I was testing several weeks ago on port 8080, and nothing was working, so I switched to 3000. When I began pushing to my server, I continually got errors, but locally I was not.

That’s because locally, I was specifying a port, but on my server, my reverse proxy kept pointing to 8080 when stuff was running on 3000.

Thank you everyone for your help, I am going to go cry and make sure I never make this mistake again 😭