Security News
Node.js EOL Versions CVE Dubbed the "Worst CVE of the Year" by Security Experts
Critics call the Node.js EOL CVE a misuse of the system, sparking debate over CVE standards and the growing noise in vulnerability databases.
Wegweiser {m}, Wegweiser {pl}:
- signpost; direction sign; guide sign [Am.]
- (figurative) guide [e.g. a book]
- a router for Quinn, powered by routington and footnote.
npm install --save wegweiser
import { createRouter, GET, PUT } from 'wegweiser';
const simpleHandler = GET('/my/scope')(req => {
return respond().body('ok');
});
class PretendingItsJava {
@PUT('/user/:username/profile')
async updateProfile(req, { username }) {
const data = await readJson(req);
return respond.json({ ok: true, firstName: data.firstName });
}
}
const router = createRouter(simpleHandler, PretendingItsJava);
// router is a quinn handler: request => response
For decorators,
you'll need babel with --stage 1
.
createRouter(...routes)
This is also the default export.
Each argument to this function should either be an annotated function or a class with annotated methods. Routes have to be unambiguous. If the same method and path combination is configured twice, creating the router will fail.
The result is a router; a function of form request => result
.
The request
is expected to have two properties:
method: String
: An HTTP method, e.g. 'GET'
.url: String
: A url path, e.g. '/foo?a=b'
.If one of the routes matches, the router will call the route handler
with two arguments: the request
(just passed through) and params
.
params
is an object containing the params parameters.
GET('/users/:id')(f);
createRouter(f)({ method: 'GET', 'url': '/users/robin' });
// Calls `f` with `(request, { id: 'robin' })`.
The return value of the router is whatever the route handler returns,
no changes or assumptions are made by wegweiser
itself.
If no route matches, the router will return undefined
.
Route(method: String, path: String)
A footnote
annotation decorator that adds metadata to functions or methods
to turn them into valid arguments for createRouter
.
The return value is a decorator function that supports two different call styles:
Route('GET', '/')(f: Function)
: Annotates a function.Route('GET', '/')(prototype, propertyKey, propertyDescriptor)
: Annotates a method.When a method is annotated, the constructor of the class is tracked. Whenever the route is matched, a new instance of the class will be created and the method will be called on that instance. The arguments the router passes into functions and methods are the same (see `createRouter above).
GET(path: String)
/ POST(path)
/ ...Route
partially applied with an HTTP verb.
Unless you need to support some very exotic HTTP verbs,
you'll use these instead of Route
directly.
FAQs
A router for Quinn
The npm package wegweiser receives a total of 10 weekly downloads. As such, wegweiser popularity was classified as not popular.
We found that wegweiser demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 2 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.
Security News
Critics call the Node.js EOL CVE a misuse of the system, sparking debate over CVE standards and the growing noise in vulnerability databases.
Security News
cURL and Go security teams are publicly rejecting CVSS as flawed for assessing vulnerabilities and are calling for more accurate, context-aware approaches.
Security News
Bun 1.2 enhances its JavaScript runtime with 90% Node.js compatibility, built-in S3 and Postgres support, HTML Imports, and faster, cloud-first performance.