Registry / aws / bragg-router

bragg-router

JSON →
library2.1.0jsnpmunverified

Bragg Router is a routing middleware specifically crafted for the `bragg` AWS Lambda web framework. It empowers developers to define HTTP routes for serverless functions using a familiar Koa-inspired interface. Routes can handle various HTTP methods (GET, POST, PUT, DELETE, PATCH, HEAD, UPDATE) and support URL parameter matching based on the `matcher` library. A key feature is the ability to chain multiple middleware functions for a single route, processing them sequentially and resolving promises between steps. The current stable version is 2.1.0, released in 2020. As a specialized router for the `bragg` framework, it differentiates itself by providing a concise and functional API tailored for AWS Lambda environments, in contrast to broader Node.js web frameworks. However, the `bragg` ecosystem and `bragg-router` itself appear to be in an unmaintained state, with no new feature development or consistent release cadence since 2021.

npm install bragg-router
INSTALL
IMPORT
SIG · BRAGG-ROUTER
B
bragg-router
awsjavascriptv2.1.0
Install
Import
Disk
Pass rate
0/ 6
Env Coverage0 / 6
glibc
1822
musl
1822
Install & Compatibility
Where this runs
tested against v? · npm install
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
node 18226 runs
build_error
glibc
node 18226 runs
build_error
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

router
const router = require('bragg-router')();
import router from 'bragg-router';
This package is CommonJS only and exports a function that must be invoked to get the router instance.
router.get
router.get('/', handler);
get('/', handler);
HTTP method handlers (e.g., `.get`, `.post`) are available directly on the router instance returned by `require('bragg-router')()`.
router.routes
app.use(router.routes());
app.use(router);
The `routes()` method must be called to return the actual middleware function compatible with `bragg`'s `app.use()`.

This quickstart demonstrates how to initialize `bragg-router`, define simple and parameterized GET routes, implement a route with multiple asynchronous handlers, and integrate the router's middleware into a `bragg` application for AWS Lambda.

const app = require('bragg')(); const router = require('bragg-router')(); // Define a simple GET route for the root path router.get('/', ctx => { ctx.body = 'Hello from Bragg Router!'; }); // Define a GET route with a URL parameter router.get('/user/{id}', ctx => { ctx.body = `Retrieve user with ID: ${ctx.request.params.id}`; }); // Define a route with multiple asynchronous handlers router.get('/chain', () => Promise.resolve('First part'), (ctx, result) => { ctx.body = `${result} and Second part`; } ); // Attach the router middleware to the bragg application app.use(router.routes()); // Export the handler for AWS Lambda exports.handler = app.listen();
Debug
Known issues
gotchaThis package is written exclusively in CommonJS (CJS) and does not provide ES module (ESM) exports. Direct `import` statements using ESM syntax will fail.
fix
For module import, use the CommonJS `require()` syntax: `const router = require('bragg-router')();`
affects: >=2.0.0
deprecatedThe `bragg` framework and its associated middleware, including `bragg-router`, appear to be unmaintained. The last significant activity on the `bragg` GitHub repository was in 2021, and `bragg-router` in 2020. This implies no active development, bug fixes, or updates for newer Node.js versions or security vulnerabilities.
fix
Evaluate long-term suitability for new projects. Consider actively maintained alternatives if continuous updates, modern features, or security patching are critical. For existing projects, pin exact versions and conduct thorough security audits.
affects: >=2.0.0
Errors
Common errors & fixes
TypeError: bragg_router_1 is not a function
Attempting to use an ES module `import` statement for `bragg-router` and then trying to invoke the imported module directly, which is not how the CommonJS export works.
fix
Change the import statement to CommonJS `require()`: `const router = require('bragg-router')();`
Error: app.use() requires a middleware function but got a [object Undefined]
The `router.routes` property was passed directly to `app.use()` without invoking it, meaning `app.use()` received `undefined` instead of a function.
fix
Ensure `router.routes()` is called to return the middleware function: `app.use(router.routes());`
Upgrade
Version history
2.1.0latest on npm
Audit
Dependencies
braggrequiredbragg-router is a middleware designed exclusively for the bragg framework.
Agent activity
22 hits · last 30 days
node
20
OpenAI (training)
1
Resources
bragg-router — npm install bragg-router · libregistry