
Security News
Open Source Maintainers Demand Ability to Block Copilot-Generated Issues and PRs
Open source maintainers are urging GitHub to let them block Copilot from submitting AI-generated issues and pull requests to their repositories.
A proxy event handler for h3
, using proxyRequest
.
proxyRequest
of h3
.# pnpm
$ pnpm add h3-proxy
# yarn
$ yarn add h3-proxy
# npm
$ npm i h3-proxy
import { createServer } from 'node:http'
import { createApp, eventHandler, toNodeListener } from 'h3'
import { createProxyEventHandler } from 'h3-proxy'
const app = createApp()
const port = process.env.PORT || 3000
const proxyEventHandler = createProxyEventHandler({
target: `http://127.0.0.1:${port}`,
pathRewrite: {
'^/api': '',
},
pathFilter: ['/api/**'],
// enableLogger: true
})
app.use(
'/test',
eventHandler(() => 'Hello world!')
)
app.use(eventHandler(proxyEventHandler))
createServer(toNodeListener(app)).listen(port)
Create a h3
event handler that can handle proxy requests.
Key | Type | Required | Default value | Description |
---|---|---|---|---|
target | string | true | undefined | Proxy target address, including protocol, host and port. url string to be parsed with the node:url module |
pathFilter | string, string[], glob, glob[], Function | false | undefined | Narrow down which requests should be proxied. |
pathRewrite | object/Function | false | undefined | Rewrite target's url path. Object-keys will be used as RegExp to match paths. |
configureProxyRequest | Function | false | undefined | Configure options of proxyRequest . More details see built-in util proxyRequest of h3 |
enableLogger | boolean | false | true | Whether to enable logger which is created by consola. |
loggerOptions | ConsolaOptions | false | {} | Configure the options of consola. |
changeOrigin | boolean | false | false | Whether to changes the origin of the host header to the target URL |
path matching
createProxyEventHandler({...})
- matches any path, all requests will be proxied when pathFilter
is not configured.createProxyEventHandler({ pathFilter: '/api', ...})
- matches paths starting with /api
multiple path matching
createProxyEventHandler({ pathFilter: ['/api', '/ajax', '/someotherpath'], ...})
wildcard path matching
For fine-grained control you can use wildcard matching. Glob pattern matching is done by micromatch. Visit micromatch or glob for more globbing examples.
createProxyEventHandler({ pathFilter: '**', ...})
matches any path, all requests will be proxied.createProxyEventHandler({ pathFilter: '**/*.html', ...})
matches any path which ends with .html
createProxyEventHandler({ pathFilter: '/*.html', ...})
matches paths directly under path-absolutecreateProxyEventHandler({ pathFilter: '/api/**/*.html', ...})
matches requests ending with .html
in the path of /api
createProxyEventHandler({ pathFilter: ['/api/**', '/ajax/**'], ...})
combine multiple patternscreateProxyEventHandler({ pathFilter: ['/api/**', '!**/bad.json'], ...})
exclusion:warning: TIPS, In multiple path matching, you cannot use string paths and wildcard paths together.
custom matching
For full control you can provide a custom function to determine which requests should be proxied or not.
/**
* @return {Boolean}
*/
const pathFilter = function (path, req) {
return path.match('^/api') && req.method === 'GET';
};
const apiProxy = createProxyEventHandler({
target: 'http://www.example.org',
pathFilter: pathFilter,
});
Rewrite target's url path. Object-keys will be used as RegExp to match paths.
// rewrite path
pathRewrite: {'^/old/api' : '/new/api'}
// remove path
pathRewrite: {'^/remove/api' : ''}
// add base path
pathRewrite: {'^/' : '/basepath/'}
// custom rewriting
pathRewrite: function (path, req) { return path.replace('/api', '/base/api') }
// custom rewriting, returning Promise
pathRewrite: async function (path, req) {
const should_add_something = await httpRequestToDecideSomething(path);
if (should_add_something) path += "something";
return path;
}
createProxyEventHandler({
// ...
// the param `event` is H3Event
configureProxyRequest(event) {
// return your custom options of proxyRequest
return {}
}
})
SEE CHANGE LOG.
FAQs
A proxy event handler for h3, using proxyRequest.
The npm package h3-proxy receives a total of 1,580 weekly downloads. As such, h3-proxy popularity was classified as popular.
We found that h3-proxy 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.
Security News
Open source maintainers are urging GitHub to let them block Copilot from submitting AI-generated issues and pull requests to their repositories.
Research
Security News
Malicious Koishi plugin silently exfiltrates messages with hex strings to a hardcoded QQ account, exposing secrets in chatbots across platforms.
Research
Security News
Malicious PyPI checkers validate stolen emails against TikTok and Instagram APIs, enabling targeted account attacks and dark web credential sales.