Angular-cli: ng serve --proxy-config proxy.conf.json doesn't work

Created on 27 Jul 2017  路  4Comments  路  Source: angular/angular-cli

Bug Report or Feature Request (mark with an x)

- [x ] bug report -> please search issues before submitting
- [ ] feature request

Versions.


@angular/cli: 1.2.5
node: 6.11.0
os: win32 x64
@angular/animations: 4.3.1
@angular/common: 4.3.1
@angular/compiler: 4.3.1
@angular/core: 4.3.1
@angular/forms: 4.3.1
@angular/http: 4.3.1
@angular/platform-browser: 4.3.1
@angular/platform-browser-dynamic: 4.3.1
@angular/router: 4.3.1
@angular/cli: 1.2.5
@angular/compiler-cli: 4.3.1
@angular/language-service: 4.3.1

Repro steps.

ng new proxy-config-project
cd proxy-config-project

Create a file next to projects package.json called proxy.conf.json with the content
{
"/api": {
"target": "http://localhost:3000",
"secure": false
}
}

Run following command

ng serve --proxy-config proxy.conf.json

The log given by the failure.


There is no error message, but something is expected like:
[HPM] Proxy created: /api -> http://localhost:3000

Desired functionality.

Mention any other details that might be useful.

Most helpful comment

Can you elaborate on what your fault was? Very relevant for me right now.

All 4 comments

My fault, this is not an issue.

Can you elaborate on what your fault was? Very relevant for me right now.

I've just encountered the same problem:

  • no "[HPM] Proxy created" message,
  • proxy appearing not to be working.

Then I've found a dumb mistake of mine.
The proxy processes only requests to localhost:4200 (or whatever the port you use to serve) so you need your request URLs to be relative, such as starting with / and not http://somedomain/.
Then the proxy catches such relative requests, redirects them to a target set in the config file and disables security by messing with headers.
Building and deploying won't be affected as soon as your frontend is on the same domain as your backend. You may config some angular environments with specific domains otherwise.
The "[HPM] Proxy created" message is still missing and this doesn't mean it doesn't work.

This issue has been automatically locked due to inactivity.
Please file a new issue if you are encountering a similar or related problem.

Read more about our automatic conversation locking policy.

_This action has been performed automatically by a bot._

Was this page helpful?
0 / 5 - 0 ratings