在线时间:8:00-16:00
迪恩网络APP
随时随地掌握行业动态
扫描二维码
关注迪恩网络微信公众号
开源软件名称:eugeneCN/koa-server-http-proxy开源软件地址:https://github.com/eugeneCN/koa-server-http-proxy开源编程语言:JavaScript 84.3%开源软件介绍:koa-server-http-proxyA koa2 http-proxy-middleware. Installation$ npm install koa-server-http-proxy --save Exampleconst Koa = require('koa')
const app = new Koa()
const proxy = require('koa-server-http-proxy')
app.use(proxy('/api', {
target: 'https://news-at.zhihu.com',
pathRewrite: { '^/api': 'api/4/' },
changeOrigin: true
}))
app.listen(3000)
Browser
Example2const Koa = require('koa')
const app = new Koa()
const proxy = require('koa-server-http-proxy')
const proxyTable = {
'/json': {
target: 'http://jsonplaceholder.typicode.com',
pathRewrite: { '^/json': '' },
changeOrigin: true
},
'/api': {
target: 'https://news-at.zhihu.com',
pathRewrite: { '^/api': 'api/4/' },
changeOrigin: true
}
}
Object.keys(proxyTable).forEach((context) => {
var options = proxyTable[context]
app.use(proxy(context, options))
})
app.listen(3000)
OptionsAll options are passed to See http-proxy-middleware for full list of accepted options. LicenseMIT |
2023-10-27
2022-08-15
2022-08-17
2022-09-23
2022-08-13
请发表评论