
Research
/Security News
Critical Vulnerability in NestJS Devtools: Localhost RCE via Sandbox Escape
A flawed sandbox in @nestjs/devtools-integration lets attackers run code on your machine via CSRF, leading to full Remote Code Execution (RCE).
@dbushell/velocirouter
Advanced tools
A minimal async Request → Response router powered by URL Pattern API magic ✨
A minimal async Request
→ Response
router powered by URL Pattern API magic ✨
Route handles are attached using an HTTP method name:
const router = new Router();
router.get('*', () => {
return new Response('Hello, World!');
});
Router
method names like get
and post
are lower case.
Requests are passed through all matching handles in the order they were attached.
The first parameter is a URL Pattern API input. String inputs are matched against the URL pathname. Object inputs are used to match parts of the URL. The second parameter is a handle function.
router.get({pathname: '/hello/:name'}, ({match}) => {
const {name} = match.pathname.groups;
return new Response(`Hello ${name}!`);
});
For fastest performance provide a full URLPattern
instance:
router.get(new URLPattern({pathname: '/:slug([\w-]+)'}), () => {
// Pattern matches [a-zA-Z0-9_-]
});
The Router
class accepts the following configuration:
const router = new Router({
onError: (error, request) => {
console.error(error);
return new Response(null {status: 500});
},
onNoMatch: (request) => {
return new Response(null, {status: 404});
},
autoHead: false
});
onError
- a fallback handle when an error is thrown. Default is a 500 response.
onNoMatch
- a fallback handle when no response is returned from any matching routes. Default is a 404 response.
autoHead
- automatically generate corresponding HEAD
handles for any GET
handles attached. Default is true
.
The handle function receives a props
object as the only argument.
The props
object includes:
request
- the Request
object matching the route patternresponse
- the Response
object returned by a previous handle (or undefined
)match
- the URLPatternResult
platform
- any platform specific datastopPropagation
- a function to stop any further handles being calledIf the handle returns void
or undefined
it has no effect on the route. Any previous handle's Response
is used.
If the handle returns null
any previous handles are ignored. The route will be handled by onNoMatch
unless any following handles exist.
If the handles returns a Response
that becomes the route's response unless any following handles have an effect.
Handles can return an object: {request, response}
. The request
property changes the routes Request
passed to any following handles. The optional response
property follows the same rules above.
If an uncaught error is thrown inside a handle the onError
option is used.
Middleware is added with the use
method:
router.use(({request}) => {
console.log(`[${request.method}] ${request.url}`);
});
Handles attached with use
match all requests. They are executed in order before all other route handles.
A special all
handle will match all HTTP methods with a pattern:
router.all({pathname: '*'}, ({response}) => {
if (response) {
response.headers.set('x-powered-by', 'velocirouter');
}
});
Handles attached with all
are executed in order alongside route handles after any middleware.
Only Deno and Chromium based browsers have URL Pattern API support right now. Other runtimes like Bun and Node require a polyfill.
MIT License | Copyright © 2024 David Bushell
FAQs
A minimal async Request → Response router powered by URL Pattern API magic ✨
The npm package @dbushell/velocirouter receives a total of 0 weekly downloads. As such, @dbushell/velocirouter popularity was classified as not popular.
We found that @dbushell/velocirouter demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 0 open source maintainers 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
A flawed sandbox in @nestjs/devtools-integration lets attackers run code on your machine via CSRF, leading to full Remote Code Execution (RCE).
Product
Customize license detection with Socket’s new license overlays: gain control, reduce noise, and handle edge cases with precision.
Product
Socket now supports Rust and Cargo, offering package search for all users and experimental SBOM generation for enterprise projects.