{"id":17515,"library":"bragg-router","title":"Bragg Router Middleware","description":"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.","status":"maintenance","version":"2.1.0","language":"javascript","source_language":"en","source_url":"https://github.com/samverschueren/bragg-router","tags":["javascript","bragg","framework","routing","router","aws","lambda"],"install":[{"cmd":"npm install bragg-router","lang":"bash","label":"npm"},{"cmd":"yarn add bragg-router","lang":"bash","label":"yarn"},{"cmd":"pnpm add bragg-router","lang":"bash","label":"pnpm"}],"dependencies":[{"reason":"bragg-router is a middleware designed exclusively for the bragg framework.","package":"bragg","optional":false}],"imports":[{"note":"This package is CommonJS only and exports a function that must be invoked to get the router instance.","wrong":"import router from 'bragg-router';","symbol":"router","correct":"const router = require('bragg-router')();"},{"note":"HTTP method handlers (e.g., `.get`, `.post`) are available directly on the router instance returned by `require('bragg-router')()`.","wrong":"get('/', handler);","symbol":"router.get","correct":"router.get('/', handler);"},{"note":"The `routes()` method must be called to return the actual middleware function compatible with `bragg`'s `app.use()`.","wrong":"app.use(router);","symbol":"router.routes","correct":"app.use(router.routes());"}],"quickstart":{"code":"const app = require('bragg')();\nconst router = require('bragg-router')();\n\n// Define a simple GET route for the root path\nrouter.get('/', ctx => {\n    ctx.body = 'Hello from Bragg Router!';\n});\n\n// Define a GET route with a URL parameter\nrouter.get('/user/{id}', ctx => {\n    ctx.body = `Retrieve user with ID: ${ctx.request.params.id}`;\n});\n\n// Define a route with multiple asynchronous handlers\nrouter.get('/chain', \n  () => Promise.resolve('First part'),\n  (ctx, result) => {\n    ctx.body = `${result} and Second part`;\n  }\n);\n\n// Attach the router middleware to the bragg application\napp.use(router.routes());\n\n// Export the handler for AWS Lambda\nexports.handler = app.listen();\n","lang":"javascript","description":"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."},"warnings":[{"fix":"For module import, use the CommonJS `require()` syntax: `const router = require('bragg-router')();`","message":"This package is written exclusively in CommonJS (CJS) and does not provide ES module (ESM) exports. Direct `import` statements using ESM syntax will fail.","severity":"gotcha","affected_versions":">=2.0.0"},{"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.","message":"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.","severity":"deprecated","affected_versions":">=2.0.0"}],"env_vars":null,"last_verified":"2026-04-23T00:00:00.000Z","next_check":"2026-07-22T00:00:00.000Z","problems":[{"fix":"Change the import statement to CommonJS `require()`: `const router = require('bragg-router')();`","cause":"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.","error":"TypeError: bragg_router_1 is not a function"},{"fix":"Ensure `router.routes()` is called to return the middleware function: `app.use(router.routes());`","cause":"The `router.routes` property was passed directly to `app.use()` without invoking it, meaning `app.use()` received `undefined` instead of a function.","error":"Error: app.use() requires a middleware function but got a [object Undefined]"}],"ecosystem":"npm","meta_description":null,"install_score":null,"install_tag":null,"quickstart_score":null,"quickstart_tag":null}