Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Proxy localhost does not work under Windows #866

Closed
hantsy opened this issue Apr 1, 2017 · 2 comments
Closed

Proxy localhost does not work under Windows #866

hantsy opened this issue Apr 1, 2017 · 2 comments
Labels

Comments

@hantsy
Copy link

hantsy commented Apr 1, 2017

Follow the NG CLI wiki page (proxy to backend, I am trying to configure proxy to the backend API.

The backend is a nodejs/express application, served at port 3000. The frontend is NG 2 application generated by Angular CLI.

I added a proxy.conf.json in the root folder of frontend application.

{
  "/api/*": {
    "target": "http://localhost:3000",
    "changeOrigin": true,
    "secure": false,
    "logLevel": "debug"
  }
}

and changed the start command in package.json. I also tried the simplest config in the Wiki page(proxy to backend, it does not work).

 "start": "ng serve --port 4300 --proxy-config proxy.conf.json",

When I run the application, I got error messages from cmd console.

[HPM] GET /api/upload/uploads-1490782788752.png -> http://localhost:3000
[HPM] Error occurred while trying to proxy request /api/upload/uploads-1490782788752.png from localhost:4300 to http://localhost:3000 (ECONNRESET) (https://nodejs.org/api/errors.html#errors_common_system_errors)

The image should be accessed via http://localhost:4300/api/upload/uploads-1490782788752.png, but failed, and it is existed. When access http://localhost:3000/api/upload/uploads-1490782788752.png, it displays the image directly.

When I accessed http://localhost:4300/api/upload/uploads-1490782788752.png, in Chrome browser. It displays a message:

Error occured while trying to proxy to: localhost:4300/api/upload/uploads-1490782788752.png

My local development environment:

  1. Node
node -v
v7.7.4
  1. npm
npm -v
4.1.2
  1. NG 1.0.0
ng -v
    _                      _                 ____ _     ___
   / \   _ __   __ _ _   _| | __ _ _ __     / ___| |   |_ _|
  / △ \ | '_ \ / _` | | | | |/ _` | '__|   | |   | |    | |
 / ___ \| | | | (_| | |_| | | (_| | |      | |___| |___ | |
/_/   \_\_| |_|\__, |\__,_|_|\__,_|_|       \____|_____|___|
               |___/
@angular/cli: 1.0.0
node: 7.7.4
os: win32 x64
@angular/common: 2.4.10
@angular/compiler: 2.4.10
@angular/core: 2.4.10
@angular/forms: 2.4.10
@angular/http: 2.4.10
@angular/platform-browser: 2.4.10
@angular/platform-browser-dynamic: 2.4.10
@angular/router: 3.4.10
@angular/cli: 1.0.0
@angular/compiler-cli: 2.4.10
  1. OS
Windows 10 64 bit, 1607

I have tried to set target in the proxy.conf.json using 127.0.0.1, dev.local(virtual hosts configured in hosts file) instead of localhost, all failed under Windows 10.

But the the internal network ip(192.168.0.110) works.

{
  "/api": {
    "target": "http://192.168.0.110:3000",
    "changeOrigin": true,
    "secure": false,
    "logLevel": "debug"
  }
}

I think this is Windows specific bug.

BTW,1. I also used proxy on localhost in before projects, it works. eg. https://github.com/hantsy/angularjs-springmvc-sample-boot/blob/master/gulpfile.js, proxy configured via proxy-middleware.
2. I have tried to use ng eject to export webpack.config and set proxy in it, and got the same errors.

@shellscape
Copy link
Contributor

Pruning due to age and inactivity.

@ghost
Copy link

ghost commented May 12, 2020

Why would you need a proxy to use an API. Use env files

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants