【问题标题】:Serve public files with reverse proxy使用反向代理服务公共文件
【发布时间】:2017-12-17 17:38:43
【问题描述】:

Node.js 8.9.1、hapi 16.6.2、h2o2 5.2.0

有一个reverse proxy 路由可以使用外部 API。

  {
    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 和反向代理?

【问题讨论】:

    标签: node.js hapijs


    【解决方案1】:

    我通过使反向代理路由更具体来使其工作。现在我有三个反向代理路由而不是一个。

      {
        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
          }   
        }   
      } 
    

    【讨论】:

      猜你喜欢
      • 2018-12-19
      • 1970-01-01
      • 2018-09-05
      • 2010-09-21
      • 1970-01-01
      • 1970-01-01
      • 2018-09-10
      • 1970-01-01
      • 2019-08-17
      相关资源
      最近更新 更多