Tag - 反向代理

微服务 MicroService nodejs http 反向代理    2017-07-19 20:20:45    3

最近在做微服务相关产品,其中需要有API网关相关产品,虽然早有研究过API网关产品TYK,但是感觉其太重,想起之前研究开源BI产品saiku的时候,记得其有NodeJS的代理代码,于是看了下,颇有启发,略微修改了一些,拿出来跟大家分享下,虽然简单,不可用于生产,但是对于学习还是不错的

package.json

  1. {
  2. "name": "SmartHttpProxy",
  3. "description": "An simplest Http Proxy",
  4. "version": "0.0.1",
  5. "author": "liuyg@liuyingguang.cn",
  6. "license": {
  7. "type": "Apache License Version 2"
  8. },
  9. "main": "server.js",
  10. "scripts": {
  11. "start": "node server.js 8088 127.0.0.1 80 / "
  12. },
  13. "dependencies": {
  14. "express": "~4.13.4"
  15. }
  16. }

server.js

  1. /*
  2. *
  3. * Licensed under the Apache License, Version 2.0 (the "License");
  4. * you may not use this file except in compliance with the License.
  5. * You may obtain a copy of the License at
  6. *
  7. * http://www.apache.org/licenses/LICENSE-2.0
  8. *
  9. * Unless required by applicable law or agreed to in writing, software
  10. * distributed under the License is distributed on an "AS IS" BASIS,
  11. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either e