2017-12-17 8 views
2

Node.js를 8.9.1, 게요! 16.6.2, H2O2 5.2.0은 역방향 프록시

외부 API를 사용하는 reverse proxy 경로가 공공 파일을 제공.

{ 
    method: '*', 
    path: '/api/v2/{param*}', 
    handler: { 
     proxy: { 
     host: 'host.net', 
     port: 8100, 
     protocol: 'http', 
     passThrough: true, 
     localStatePassThrough: true 
     } 
    } 
    } 

동일한 Node.js 서버에서 AngulaJS UI를 제공해야합니다. 다음 경로가 추가되었습니다.

{ 
    method: 'GET', 
    path: '/{param*}', 
    handler: { 
     directory: { 
     path: 'public' 
     } 
    } 
    } 

이제 UI가 보입니다. 하지만 더 이상 외부 API에서 데이터를 가져올 수 없습니다.

curl -XGET localhost:8001/api/v2/birds 
{"statusCode":404,"error":"Not Found","message":"Not Found"} 

동일한 Node.js 서버에서 UI와 역방향 프록시를 모두 제공하려면 어떻게해야합니까?

답변

2

리버스 프록시 경로를 좀 더 구체적으로 만들어서 만들었습니다. 이제는 하나가 아닌 3 개의 역방향 프록시 경로가 있습니다.

{ 
    method: 'GET', 
    path: '/api/v2/{param*}', 
    handler: { 
     proxy: { 
     host: 'host.net', 
     port: 8100, 
     protocol: 'http', 
     passThrough: true, 
     localStatePassThrough: true 
     } 
    } 
    }, 
    { 
    method: 'POST', 
    path: '/api/v2/{param*}', 
    handler: { 
     proxy: { 
     host: 'host.net', 
     port: 8100, 
     protocol: 'http', 
     passThrough: true, 
     localStatePassThrough: true 
     } 
    } 
    }, 
    { 
    method: 'PUT', 
    path: '/api/v2/{param*}', 
    handler: { 
     proxy: { 
     host: 'host.net', 
     port: 8100, 
     protocol: 'http', 
     passThrough: true, 
     localStatePassThrough: true 
     } 
    } 
    }