Security News
tea.xyz Spam Plagues npm and RubyGems Package Registries
Tea.xyz, a crypto project aimed at rewarding open source contributions, is once again facing backlash due to an influx of spam packages flooding public package registries.
koa-proxies
Advanced tools
Changelog
Readme
Koa@2.x/next middlware for http proxy
Powered by http-proxy
.
$ npm install koa-proxies --save
options.events = {
error (err, req, res) { },
proxyReq (proxyReq, req, res) { },
proxyRes (proxyRes, req, res) { }
}
// 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))
}
// 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
}))
The 2nd parameter options
can be a function. It will be called with the path matching result (see path-match for details) and Koa ctx
object. You can leverage this feature to dynamically set proxy. Here is an example:
// dependencies
const Koa = require('koa')
const proxy = require('koa-proxies')
const app = new Koa()
// middleware
app.use(proxy('/octocat/:name', (params, ctx) => {
return {
target: 'https://api.github.com/',
changeOrigin: true,
rewrite: () => `/users/${params.name}`,
logs: true
}})
)
Moreover, if the options
function return false
, then the proxy will be bypassed. This allows the middleware to bail out even if path matching succeeds, which could be helpful if you need complex logic to determine whether to proxy or not.
Please make sure that koa-proxies
is in front of koa-bodyparser
to avoid this issue 55
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())
FAQs
Http Proxy Middleware for Koa@2.x/next
The npm package koa-proxies receives a total of 13,817 weekly downloads. As such, koa-proxies popularity was classified as popular.
We found that koa-proxies demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Tea.xyz, a crypto project aimed at rewarding open source contributions, is once again facing backlash due to an influx of spam packages flooding public package registries.
Security News
As cyber threats become more autonomous, AI-powered defenses are crucial for businesses to stay ahead of attackers who can exploit software vulnerabilities at scale.
Security News
UnitedHealth Group disclosed that the ransomware attack on Change Healthcare compromised protected health information for millions in the U.S., with estimated costs to the company expected to reach $1 billion.