Bragg Router Middleware
raw JSON →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.
Common errors
error TypeError: bragg_router_1 is not a function ↓
require(): const router = require('bragg-router')(); error Error: app.use() requires a middleware function but got a [object Undefined] ↓
router.routes() is called to return the middleware function: app.use(router.routes()); Warnings
gotcha This package is written exclusively in CommonJS (CJS) and does not provide ES module (ESM) exports. Direct `import` statements using ESM syntax will fail. ↓
deprecated The `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. ↓
Install
npm install bragg-router yarn add bragg-router pnpm add bragg-router Imports
- router wrong
import router from 'bragg-router';correctconst router = require('bragg-router')(); - router.get wrong
get('/', handler);correctrouter.get('/', handler); - router.routes wrong
app.use(router);correctapp.use(router.routes());
Quickstart
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();