8000 GitHub - xtx1130/otp-proxy
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

xtx1130/otp-proxy

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

25 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

otp-proxy

otp代理接口方案,目前otp环境的js部署方案已经比较成熟,修改之后可以进行快速替换。但是在联调的时候,如果接口复杂度较高,需要对接口各种情况进行联调判断,操作起来比较麻烦。

使用方式

  • 在工作目录下安装otp-proxy包:
$ npm install git+http://gitlab.baidu.com/xietianxin/otp-proxy.git
  • package.jsonnpm scripts中添加:
// package.json
"scripts": {
  "proxy": "otproxy"
}
  • 在浏览器中使用SwitchyOmega配置网页代理,把http代理指向到127.0.0.1:8888https不要配置,目前尚不支持https代理

  • 在项目根目录下添加配置文件proxy-data.js:

// proxy-data.js
exports = module.exports = {
  // key 为要代理的path, value为async函数,其中res为请求返回的body内容
  'mo/q/generalplat/generalPlat': async res => {
      res = JSON.parse(res)
      res.data.has_more = 0 //可直接指定修改返回内容中的某个键值对
      res.data.head.show_style = 2
      return res //最后返回res给中间件
  }
}
  • npm run proxy 会对8888端口进行监听,如图所示: img img 在发起对mo/q/generalplat/generalPlat的请求时候,返回的json串会经过proxy-data.js中设计的中间件进行二次加工再返回。

API 接入

let server = require('otp-proxy') //server为代理服务器,是http.Server的实例
server.close() //关闭代理服务器

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Contributors 2

  •  
  •  
0