Research
Security News
Quasar RAT Disguised as an npm Package for Detecting Vulnerabilities in Ethereum Smart Contracts
Socket researchers uncover a malicious npm package posing as a tool for detecting vulnerabilities in Etherium smart contracts.
koa2-nginx
Advanced tools
Proxy middleware for koa2 based on http-proxy-middleware wrapper and support for configuring multiple proxy rules. The way to use is inspired by the proxy option of webpack-dev-server
Proxy /api
requests to http://www.example.com
var koa = require('koa');
var proxy = require('koa2-nginx');
var app = koa();
app.use(
proxy({ '/api': { target: 'http://www.example.com', changeOrigin: true } })
);
app.listen(3000);
// http://localhost:3000/api/v1 -> http://www.example.com/api/v1
All http-proxy-middleware
options can be used.
Tip: Set the option changeOrigin
to true
for name-based virtual hosted sites.
koa2-nginx@1.x
context-length
is removed, and we think this should be handled by the developer itself in the events hooks.$ npm i koa2-nginx
An example with koa2
server.
// include dependencies
const Koa = require('koa');
const proxy = require('koa2-nginx');
// proxy middleware options
const options = {
'/api': {
target: 'http://www.example.com',
changeOrigin: true,
},
'**/*.html': {
target: 'http://www.example2.com',
changeOrigin: true
},
'/user': 'http://localhost:3000'
};
// create the proxy (without context)
const exampleProxy = proxy(options);
// mount `exampleProxy` in web server
const app = new Koa();
app.use(exampleProxy);
app.listen(3000);
autoProcessReqBody
to true can proxy the request body in json
and form
content-type.Can refer option to http-proxy-middleware for each forwarding rule.
Can refer option to http-proxy for each forwarding rule.
Option supports multiple pattern-matching proxy
let option = {
'/api': {
target: 'http://www.example.com',
changeOrigin: true,
onProxyRes(proxyRes, req, res) {
proxyRes.headers['x-added'] = 'foobar'; // add new header to response
delete proxyRes.headers['x-removed'];
},
onProxyReq(proxyReq, req, res) {
proxyReq.setHeader('x-added', 'foobar');
}
}
}
let option = {
'/api': function() {
// your custom logic
return {
target: 'http://www.example.com',
changeOrigin: true,
}
}
}
If you want to proxy multiple, specific paths to the same target, you can use an array of one or more objects with a context
property:
let option = [{
context: ['/auth', '/api'], target: 'http://localhost:3000'
}]
autoProcessReqBody
to true
FAQs
This is an http-proxy koa proxy middleware that can be used after bodyparse
The npm package koa2-nginx receives a total of 59 weekly downloads. As such, koa2-nginx popularity was classified as not popular.
We found that koa2-nginx demonstrated a not healthy version release cadence and project activity because the last version was released 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.
Research
Security News
Socket researchers uncover a malicious npm package posing as a tool for detecting vulnerabilities in Etherium smart contracts.
Security News
Research
A supply chain attack on Rspack's npm packages injected cryptomining malware, potentially impacting thousands of developers.
Research
Security News
Socket researchers discovered a malware campaign on npm delivering the Skuld infostealer via typosquatted packages, exposing sensitive data.