在线时间:8:00-16:00
迪恩网络APP
随时随地掌握行业动态
扫描二维码
关注迪恩网络微信公众号
开源软件名称:vagusX/koa-proxies开源软件地址:https://github.com/vagusX/koa-proxies开源编程语言:JavaScript 100.0%开源软件介绍:Koa Proxies
Powered by Installation$ npm install koa-proxies --save Optionshttp-proxy eventsoptions.events = {
error (err, req, res) { },
proxyReq (proxyReq, req, res) { },
proxyRes (proxyRes, req, res) { }
} log option// enable log
options.logs = true; // or false
// custom log function
options.logs = (ctx, target) {
console.log('%s - %s %s proxy to -> %s', new Date().toISOString(), ctx.req.method, ctx.req.oldPath, new URL(ctx.req.url, target))
} Usage// dependencies
const Koa = require('koa')
const proxy = require('koa-proxies')
const httpsProxyAgent = require('https-proxy-agent')
const app = new Koa()
// middleware
app.use(proxy('/octocat', {
target: 'https://api.github.com/users',
changeOrigin: true,
agent: new httpsProxyAgent('http://1.2.3.4:88'), // if you need or just delete this line
rewrite: path => path.replace(/^\/octocat(\/|\/\w+)?$/, '/vagusx'),
logs: true
})) AttentionPlease make sure that const Koa = require('koa')
const app = new Koa()
const proxy = require('koa-proxies')
const bodyParser = require('koa-bodyparser')
app.use(proxy('/user', {
target: 'http://example.com',
changeOrigin: true
}))
app.use(bodyParser()) |
2023-10-27
2022-08-15
2022-08-17
2022-09-23
2022-08-13
请发表评论