Gathering detailed insights and metrics for koa-proxies
Gathering detailed insights and metrics for koa-proxies
Gathering detailed insights and metrics for koa-proxies
Gathering detailed insights and metrics for koa-proxies
@types/koa-proxies
Stub TypeScript definitions entry for koa-proxies, which provides its own types definitions
koa-better-proxies
Http Proxy Middleware for Koa@2.x/next, change by koa-proxies
koa-proxies-better
Http Proxy Middleware for Koa@2.x/next
koa-proxies-filter
Http Proxy Middleware for Koa@2.x/next
npm install koa-proxies
Typescript
Module System
Node Version
NPM Version
49.7
Supply Chain
95.9
Quality
73.2
Maintenance
100
Vulnerability
100
License
JavaScript (100%)
Total Downloads
4,621,307
Last Day
1,270
Last Week
7,586
Last Month
59,190
Last Year
952,027
161 Stars
91 Commits
45 Forks
3 Watching
3 Branches
14 Contributors
Latest Version
0.12.4
Package Id
koa-proxies@0.12.4
Unpacked Size
13.39 kB
Size
5.39 kB
File Count
8
NPM Version
10.1.0
Node Version
20.8.1
Publised On
04 Nov 2023
Cumulative downloads
Total Downloads
Last day
-39.3%
1,270
Compared to previous day
Last week
-45.9%
7,586
Compared to previous week
Last month
-15%
59,190
Compared to previous month
Last year
-23.4%
952,027
Compared to previous year
3
1
Koa@2.x/next middlware for http proxy
Powered by http-proxy
.
1$ npm install koa-proxies --save
1options.events = { 2 error (err, req, res) { }, 3 proxyReq (proxyReq, req, res) { }, 4 proxyRes (proxyRes, req, res) { } 5}
1// enable log
2options.logs = true; // or false
3
4// custom log function
5options.logs = (ctx, target) {
6 console.log('%s - %s %s proxy to -> %s', new Date().toISOString(), ctx.req.method, ctx.req.oldPath, new URL(ctx.req.url, target))
7}
1// dependencies 2const Koa = require('koa') 3const proxy = require('koa-proxies') 4const httpsProxyAgent = require('https-proxy-agent') 5 6const app = new Koa() 7 8// middleware 9app.use(proxy('/octocat', { 10 target: 'https://api.github.com/users/', 11 changeOrigin: true, 12 agent: new httpsProxyAgent('http://1.2.3.4:88'), // if you need or just delete this line 13 rewrite: path => path.replace(/^\/octocat(\/|\/\w+)?$/, '/vagusx'), 14 logs: true 15}))
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:
1// dependencies 2const Koa = require('koa') 3const proxy = require('koa-proxies') 4 5const app = new Koa() 6 7// middleware 8app.use(proxy('/octocat/:name', (params, ctx) => { 9 return { 10 target: 'https://api.github.com/', 11 changeOrigin: true, 12 rewrite: () => `/users/${params.name}`, 13 logs: true 14 }}) 15)
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
1const Koa = require('koa') 2const app = new Koa() 3const proxy = require('koa-proxies') 4const bodyParser = require('koa-bodyparser') 5 6app.use(proxy('/user', { 7 target: 'http://example.com', 8 changeOrigin: true 9})) 10 11app.use(bodyParser())
No vulnerabilities found.
Reason
no dangerous workflow patterns detected
Reason
no binaries found in the repo
Reason
0 existing vulnerabilities detected
Reason
license file detected
Details
Reason
Found 8/26 approved changesets -- score normalized to 3
Reason
dependency not pinned by hash detected -- score normalized to 2
Details
Reason
0 commit(s) and 0 issue activity found in the last 90 days -- score normalized to 0
Reason
detected GitHub workflow tokens with excessive permissions
Details
Reason
no effort to earn an OpenSSF best practices badge detected
Reason
security policy file not detected
Details
Reason
project is not fuzzed
Details
Reason
SAST tool is not run on all commits -- score normalized to 0
Details
Score
Last Scanned on 2024-12-23
The Open Source Security Foundation is a cross-industry collaboration to improve the security of open source software (OSS). The Scorecard provides security health metrics for open source projects.
Learn More