ExpressGateway / express-gateway

A microservices API Gateway built on top of Express.js
https://www.express-gateway.io
Apache License 2.0
2.97k stars 344 forks source link

How to resolve `unsupported proxy protocol: "127.0.0.1"` #1019

Closed railway17 closed 3 years ago

railway17 commented 3 years ago

Hello, @dougwilson , @kevinswiber , @XVincentX Here is my gateway config file.

http:
  port: 8080
admin:
  port: 9876
  host: localhost
apiEndpoints:
  api:
    host: localhost
    paths: '/ip'
serviceEndpoints:
  httpbin:
    url: 'https://httpbin.org'
policies:
  - basic-auth
  - cors
  - expression
  - key-auth
  - log
  - oauth2
  - proxy
  - rate-limit
pipelines:
  - name: api-basic
    apiEndpoints:
      - api
    policies:
      - key-auth:
          - disableQueryParam: true # disable api keys in the query string
      - proxy:
          - action:
              serviceEndpoint: httpbin
              changeOrigin: true

Looks like this config is correct but I am getting below error

> node server.js

(node:9524) UnhandledPromiseRejectionWarning: TypeError: unsupported proxy protocol: "127.0.0.1"
    at mapOptsToProxy (E:\workspace\Peter\backend\crm-gateway\node_modules\proxy-agent\index.js:112:11)
    at new ProxyAgent (E:\workspace\Peter\backend\crm-gateway\node_modules\proxy-agent\index.js:150:17)
    at module.exports (E:\workspace\Peter\backend\crm-gateway\node_modules\express-gateway\lib\policies\proxy\proxy.js:61:26)
    at policyOptions.policy (E:\workspace\Peter\backend\crm-gateway\node_modules\express-gateway\lib\policies\index.js:15:14)
    at E:\workspace\Peter\backend\crm-gateway\node_modules\express-gateway\lib\gateway\pipelines.js:161:32
    at arrayMap (E:\workspace\Peter\backend\crm-gateway\node_modules\lodash.flatmap\index.js:140:21)
    at map (E:\workspace\Peter\backend\crm-gateway\node_modules\lodash.flatmap\index.js:1928:10)
    at flatMap (E:\workspace\Peter\backend\crm-gateway\node_modules\lodash.flatmap\index.js:1881:22)
    at E:\workspace\Peter\backend\crm-gateway\node_modules\express-gateway\lib\gateway\pipelines.js:146:25
    at Array.forEach (<anonymous>)
(Use `node --trace-warnings ...` to show where the warning was created)
(node:9524) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was 
not handled with .catch(). To terminate the node process on unhandled promise rejection, use the CLI flag `--unhandled-rejections=strict` (see https://nodejs.org/api/cli.html#cli_unhandled_rejections_mode). (rejection id: 2)
(node:9524) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.2021-05-11T13:36:16.982Z [EG:admin] info: admin http server listening on 127.0.0.1:9876

It means gateway server is not running correctly What's wrong?

railway17 commented 3 years ago

Ok, finally, I found the reason. It was my windows pc proxy setting issue. Sorry for this. It is working in my Mac.