最新消息: 电脑我帮您提供丰富的电脑知识,编程学习,软件下载,win7系统下载。

使用反向代理服务公共文件

IT培训 admin 11浏览 0评论

使用反向代理服务公共文件

见Z.8.9.1,Happy 16.6.2,H2O2 5.2.0

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

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

我需要在同一个Node.js服务器上提供AngularJS 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和反向代理?

回答如下:

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

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

使用反向代理服务公共文件

见Z.8.9.1,Happy 16.6.2,H2O2 5.2.0

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

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

我需要在同一个Node.js服务器上提供AngularJS 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和反向代理?

回答如下:

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

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

与本文相关的文章

发布评论

评论列表 (0)

  1. 暂无评论