Security News
The Unpaid Backbone of Open Source: Solo Maintainers Face Increasing Security Demands
Solo open source maintainers face burnout and security challenges, with 60% unpaid and 60% considering quitting.
briskly-router
Advanced tools
Route handling for Node with types!
See: Routing
Types annotations are allowed in route parameters to define more granular routes.
For example: Given the routes /users/{id: number}
and /users/{id: string}
A request to /users/123
will only match the {id: number}
route.
A request to /users/seikho
will only match the {id: string}
route.
Since we have no route that matches an array
or object
, /users/[1,2,3]
will not match either route.
See CONTRIBUTING guide
npm install briskly-router --save
import BR = require('briskly-router');
var router = new BR.Router({
port: 2189,
host: 'localhost'
});
router.route({
method: 'GET',
path: '/',
handler: {
file: 'front/index.html'
}
});
router.route({
method: 'GET',
path: '/users/{id: number}',
handler: (request, reply) => getUserById(request.params.id).then(reply)
});
router.start();
// some time later
router.stop();
See connection(...)
A route is defined by its parts
which are separated by a forward slash (/
).
Routes do not need to be defined in order and will always use the most specific route
An example route table:
/
/{...}
-- A catch all route that will match where everything else does not/scripts/{...}
-- Will match /scripts/[anything here]/[and here...]/so on..
/users/{id: number}
-- Will match /users/42
/users/{name: string}
-- Will match /users/seikho
/users
-- Will only /users
Allowed parts:
/my-home
/prefix{param}suffix
/prefix{param: string}suffix
/prefix{param: number}suffix
{myparam}
: E.g. /{myparams}
string
: /{someWord: string}
number
: /{anumber: number}
array
: /{myArray: array}
object
: /{myObj: object}
any
: {someParam: any}
/{...}
/scripts/{...}
Adds a route to the route table See: Routing RouteOptions
function route(options: RouteOptions)
Examples
route({ method: 'get', path: '/scripts/{...}', handler: directory: { 'front/scripts' } });
route({ method: 'get', path: '/api/users', handler: (req, reply) => getUsers.then(reply) });
route({ method: 'get', path: '/api/user/{id: number}', handler: (req, reply) => getUser(req.params.id).then(reply) });
route({ method: 'get', path: '/api/user/{name: string}', handler: (req, reply) => getUserByName(req.params.name).then(reply) });
route({ method: 'get', path: '/', handler: { file: 'front/index.html' } });
See: ServerOptions
class Router {
constructor(options: ServerOptions);
start(callback: (error?: any) => void): Promise<void>;
stop(callback: () => void): Promise<void>;
connection(options: ServerOptions): void;
route(options: RouteOptions): void;
}
See: ServerOptions
Set the listening port and/or host
function connection(options: ServerOptions): void;
Starts the web server listener.
This will parse briskly.json
and use the port
key
function start(callback: () => void): Promise<void>;
Stops the web server listener.
function stop(callback: () => void): Promise<void>;
interface ServerOptions {
port?: number;
host?: string;
}
See: RouteHandler DirectoryHandler FileHandler
interface RouteOptions {
method: string; // GET, POST, PUT, DELETE, etc...
path: string;
handler: RouteHandler|DirectoryHandler|FileHandler
}
function(response: Response, reply: Reply)
interface DirectoryHandler {
// The base directory to append the request file path to
directory: string;
}
interface FileHandler {
// The relative path of the file
file: string;
}
The object provided to the RouteHandler
function
interface Response {
query?: any;
body?: any;
params?: any;
path: string;
wildcard?: string;
}
The function use to send a response to the client
interface Reply {
(data: any, statusCode?: number)
file: (filePath: string) => void;
}
v0.7.0
catch
/error
handlersv0.6.0
v0.6.0
/scripts/{name: string}.js
/prefix-{param}-suffix
/{...myparam}
MIT
FAQs
briskly route handler
The npm package briskly-router receives a total of 2 weekly downloads. As such, briskly-router popularity was classified as not popular.
We found that briskly-router 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
Solo open source maintainers face burnout and security challenges, with 60% unpaid and 60% considering quitting.
Security News
License exceptions modify the terms of open source licenses, impacting how software can be used, modified, and distributed. Developers should be aware of the legal implications of these exceptions.
Security News
A developer is accusing Tencent of violating the GPL by modifying a Python utility and changing its license to BSD, highlighting the importance of copyleft compliance.