{"_id":"@cababunga/router","_rev":"6-47e57d19b356a6fcd470a729efcae46b","name":"@cababunga/router","dist-tags":{"latest":"0.7.2"},"versions":{"0.5.2":{"name":"@cababunga/router","version":"0.5.2","license":"ISC","_id":"@cababunga/router@0.5.2","maintainers":[{"name":"cababunga","email":"alexmv@gmail.com"}],"homepage":"https://github.com/cababunga/base-router#readme","bugs":{"url":"https://github.com/cababunga/base-router/issues"},"dist":{"shasum":"e4701e360bf6e614efb88988ed6929139c0746b8","tarball":"https://registry.npmjs.org/@cababunga/router/-/router-0.5.2.tgz","fileCount":6,"integrity":"sha512-/Gkdxqh5mvaUV+AuRERs/TJk5apjkiz/h7+bKfjAr5VThj6Fk4lzHht5OQ3/Da+Hy8ZecCJAoxs5DgijbuDOpQ==","signatures":[{"sig":"MEUCIAE6oLPr90T+fQxUpT1T8eVx7EYH+y95Y93t/cBnI7gvAiEAqKskVpH/SvRGK9YBUvjA9tiUVd1FRo2JsYgjPsTNlXE=","keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA"}],"unpackedSize":15789},"main":"router","gitHead":"8d9a6739de11b4fbe2b1588a6bcd83eb0e2de539","scripts":{"bump":"npm version ${BUMP:=patch} && git push && git push --tags","test":"mocha *.test.js"},"_npmUser":{"name":"cababunga","email":"alexmv@gmail.com"},"repository":{"url":"git+https://github.com/cababunga/base-router.git","type":"git"},"_npmVersion":"9.8.0","description":"Request router and middleware stacker with async/await API and zero dependencies","directories":{},"_nodeVersion":"20.5.1","_hasShrinkwrap":false,"_npmOperationalInternal":{"tmp":"tmp/router_0.5.2_1711268628106_0.7195142413926741","host":"s3://npm-registry-packages"}},"0.6.0":{"name":"@cababunga/router","version":"0.6.0","license":"ISC","_id":"@cababunga/router@0.6.0","maintainers":[{"name":"cababunga","email":"alexmv@gmail.com"}],"homepage":"https://github.com/cababunga/base-router#readme","bugs":{"url":"https://github.com/cababunga/base-router/issues"},"dist":{"shasum":"65ed2de8e51a085b694836991e354430a47c4a67","tarball":"https://registry.npmjs.org/@cababunga/router/-/router-0.6.0.tgz","fileCount":11,"integrity":"sha512-rPFhiJKOpv2L5uMioeXXmIcbaudhEtu3iCqBBC4Jox7ZTIZkw0u6CP8s6zBMZ64cSi9cqbFbl457hfDP36z0rQ==","signatures":[{"sig":"MEYCIQCs/lMn7vQUjPVBU75XN06lkvYMRvFF94v1u3NWCbS3rwIhAKM+nTonW46omvrvD5Hy6K8lOkIzxW4aVSJAkZjaGDDo","keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA"}],"unpackedSize":38471},"main":"dist/router","types":"./dist/router.d.ts","exports":{".":"./dist/router.js","./cors":"./dist/cors.js"},"gitHead":"56b40f7dbe43cd9fd5125c74de27aede0db9c035","scripts":{"bump":"npm version ${BUMP:=patch} && git push && git push --tags","test":"mocha *.test.js","prepack":"tsc"},"_npmUser":{"name":"cababunga","email":"alexmv@gmail.com"},"repository":{"url":"git+https://github.com/cababunga/base-router.git","type":"git"},"_npmVersion":"10.8.2","description":"Node.js request router and middleware stacker with async/await API and zero dependencies","directories":{},"_nodeVersion":"22.8.0","_hasShrinkwrap":false,"devDependencies":{"typescript":"^5.5.4","@types/node":"^22.5.3"},"_npmOperationalInternal":{"tmp":"tmp/router_0.6.0_1725666444174_0.9714874419068242","host":"s3://npm-registry-packages"}},"0.6.1":{"name":"@cababunga/router","version":"0.6.1","license":"ISC","_id":"@cababunga/router@0.6.1","maintainers":[{"name":"cababunga","email":"alexmv@gmail.com"}],"homepage":"https://github.com/cababunga/base-router#readme","bugs":{"url":"https://github.com/cababunga/base-router/issues"},"dist":{"shasum":"f669eab040696bc1dfe120f66bf7aeffa1a533ca","tarball":"https://registry.npmjs.org/@cababunga/router/-/router-0.6.1.tgz","fileCount":7,"integrity":"sha512-8d/j/vrIqvKzoXATROogv/lGVf9WQBdpOzbwd3CqASd6pGnpOm3YLpPtXMVLWEjq4DOqAoe5jYswjybZ/2103g==","signatures":[{"sig":"MEYCIQDAF+Xr/ps/i80YdpRt5gfXAZyNC31gBaxsTGjAcxDxqAIhAOOW7MOS4209dYoG3zEXdat7mwyI03K1DxJxssDPl5P6","keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA"}],"unpackedSize":14712},"main":"dist/router","exports":{".":"./dist/router.js","./cors":"./dist/cors.js"},"gitHead":"73ce377f3db35020f5bb4d178148d42735823351","scripts":{"bump":"npm version ${BUMP:=patch} && git push && git push --tags","test":"mocha --import=tsx src/*.test.ts","prepack":"tsc"},"_npmUser":{"name":"cababunga","email":"alexmv@gmail.com"},"repository":{"url":"git+https://github.com/cababunga/base-router.git","type":"git"},"_npmVersion":"10.8.2","description":"Node.js request router and middleware stacker with async/await API and zero dependencies","directories":{},"_nodeVersion":"22.8.0","_hasShrinkwrap":false,"devDependencies":{"tsx":"^4.19.1","typescript":"^5.5.4","@types/node":"^22.5.3","@types/mocha":"^10.0.8"},"_npmOperationalInternal":{"tmp":"tmp/router_0.6.1_1726205019546_0.5935824437363937","host":"s3://npm-registry-packages"}},"0.6.2":{"name":"@cababunga/router","version":"0.6.2","license":"ISC","_id":"@cababunga/router@0.6.2","maintainers":[{"name":"cababunga","email":"alexmv@gmail.com"}],"homepage":"https://github.com/cababunga/base-router#readme","bugs":{"url":"https://github.com/cababunga/base-router/issues"},"dist":{"shasum":"e613ed177ed38aa055f1c375c75a2114873146fe","tarball":"https://registry.npmjs.org/@cababunga/router/-/router-0.6.2.tgz","fileCount":7,"integrity":"sha512-w7CxeW/JZNTMcNVmFGI+QSHZAJnGO0Ti7SwUzRmqpRsLStnqg7e0EDIMd8NwzVGj76MRqHaahc7zTmE4m8iVpw==","signatures":[{"sig":"MEQCIAzrOS87yT4K6L2bquQybSDAzMNFeLzdWRPoWAXY29yvAiAMFQF4JCcYIbyVgb25P25QnIUofmVn8vK8baTQlsQljA==","keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA"}],"unpackedSize":14727},"main":"dist/src/router.js","types":"./dist/src/router.d.ts","exports":{".":"./dist/src/router.js","./cors":"./dist/src/cors.js"},"gitHead":"152471daf5ddb28f04d8ab4d59091de677515ad0","scripts":{"bump":"npm version ${BUMP:=patch} && git push && git push --tags","test":"mocha --import=tsx src/*.test.ts","prepack":"tsc"},"_npmUser":{"name":"cababunga","email":"alexmv@gmail.com"},"repository":{"url":"git+https://github.com/cababunga/base-router.git","type":"git"},"_npmVersion":"10.8.2","description":"Node.js request router and middleware stacker with async/await API and zero dependencies","directories":{},"_nodeVersion":"22.8.0","_hasShrinkwrap":false,"devDependencies":{"tsx":"^4.19.1","typescript":"^5.5.4","@types/node":"^22.5.3","@types/mocha":"^10.0.8"},"_npmOperationalInternal":{"tmp":"tmp/router_0.6.2_1726215118310_0.9609738330398936","host":"s3://npm-registry-packages"}},"0.7.1":{"name":"@cababunga/router","version":"0.7.1","license":"ISC","_id":"@cababunga/router@0.7.1","maintainers":[{"name":"cababunga","email":"alexmv@gmail.com"}],"homepage":"https://github.com/cababunga/base-router#readme","bugs":{"url":"https://github.com/cababunga/base-router/issues"},"dist":{"shasum":"348a91068141a620bccb0b2e6f889d3b78213418","tarball":"https://registry.npmjs.org/@cababunga/router/-/router-0.7.1.tgz","fileCount":7,"integrity":"sha512-L5nMKpSEUxLC/O5e3amAsoDbgfAJakFfu0h/vZEoU0pCjnYjcIW0ElERgFgtUaDPYYS1D3umhbptfWh7b6QvjA==","signatures":[{"sig":"MEQCIATm2Evtg98C0lrbshbtiU2IeINOqoTTR9KfZ2H4ea4hAiAQmHg3JHCaQcR6qc/bOzCotP4fU1I51jFSPHLxX8v6Gg==","keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U"}],"unpackedSize":12722},"main":"dist/src/router.js","type":"module","types":"./dist/src/router.d.ts","exports":{".":"./dist/src/router.js","./cors":"./dist/src/cors.js"},"gitHead":"fe47adabe1391a47c14f65da117ad4ef737f417d","scripts":{"bump":"npm version ${BUMP:=patch} && git push && git push --tags","test":"mocha --import=tsx test/*.test.ts","prepack":"tsc"},"_npmUser":{"name":"cababunga","email":"alexmv@gmail.com"},"repository":{"url":"git+https://github.com/cababunga/base-router.git","type":"git"},"_npmVersion":"10.9.4","description":"Node.js request router and middleware stacker with async/await API and zero dependencies","directories":{},"_nodeVersion":"22.22.0","_hasShrinkwrap":false,"devDependencies":{"tsx":"^4.19.1","typescript":"^5.5.4","@types/node":"^22.5.3","@types/mocha":"^10.0.8"},"_npmOperationalInternal":{"tmp":"tmp/router_0.7.1_1771491437234_0.4072282584533109","host":"s3://npm-registry-packages-npm-production"}},"0.7.2":{"name":"@cababunga/router","version":"0.7.2","description":"Node.js request router and middleware stacker with async/await API and zero dependencies","main":"dist/src/router.js","type":"module","exports":{".":"./dist/src/router.js","./cors":"./dist/src/cors.js"},"scripts":{"test":"mocha --import=tsx test/*.test.ts","bump":"npm version ${BUMP:=patch} && git push && git push --tags","prepack":"tsc"},"repository":{"type":"git","url":"git+https://github.com/cababunga/base-router.git"},"license":"ISC","devDependencies":{"@types/mocha":"^10.0.8","@types/node":"^22.5.3","tsx":"^4.19.1","typescript":"^5.5.4"},"_id":"@cababunga/router@0.7.2","gitHead":"5ae40c5459b721e9de8a25f1c36a9e5b5a143881","types":"./dist/src/router.d.ts","bugs":{"url":"https://github.com/cababunga/base-router/issues"},"homepage":"https://github.com/cababunga/base-router#readme","_nodeVersion":"22.22.0","_npmVersion":"10.9.4","dist":{"integrity":"sha512-x0RMy7+QkEGfcZ9aOvCfG2ngUvrm2wDCtnKADg63On2rjACLWOXmOn3EBS4MnAXo2c9sABhKWYTr0o5c7l8Mwg==","shasum":"67c7dbb3035527570c9fc5ae9b2c0dee95c3ee24","tarball":"https://registry.npmjs.org/@cababunga/router/-/router-0.7.2.tgz","fileCount":7,"unpackedSize":12780,"signatures":[{"keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U","sig":"MEQCIE81fzudkTG3JEIwEU4vXB3tGYxtiNB8HRz67HOCdrqVAiAUPXAHH9Jaqj2PlCshs0Y6t3tP8OZ7Bqle0EMMTskAkg=="}]},"_npmUser":{"name":"cababunga","email":"alexmv@gmail.com"},"directories":{},"maintainers":[{"name":"cababunga","email":"alexmv@gmail.com"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages-npm-production","tmp":"tmp/router_0.7.2_1771538233712_0.5268709606470254"},"_hasShrinkwrap":false}},"time":{"created":"2024-03-24T08:23:48.039Z","modified":"2026-02-19T21:57:13.973Z","0.5.2":"2024-03-24T08:23:48.259Z","0.6.0":"2024-09-06T23:47:24.327Z","0.6.1":"2024-09-13T05:23:39.681Z","0.6.2":"2024-09-13T08:11:58.527Z","0.7.1":"2026-02-19T08:57:17.385Z","0.7.2":"2026-02-19T21:57:13.863Z"},"bugs":{"url":"https://github.com/cababunga/base-router/issues"},"license":"ISC","homepage":"https://github.com/cababunga/base-router#readme","repository":{"type":"git","url":"git+https://github.com/cababunga/base-router.git"},"description":"Node.js request router and middleware stacker with async/await API and zero dependencies","maintainers":[{"name":"cababunga","email":"alexmv@gmail.com"}],"readme":"# BASE -- Boilerplate API Server Environment\n\n## Router\n\n### Install\n\n```shell\nnpm i @cababunga/router\n```\n\n### Use\n\nHTTP request router and middleware stacker.\n\nCreating router is easy.\n\n```javascript\nimport router from \"@cababunga/router\";\nconst app = router();\n```\n\nRouter has the following methods:\n\n```javascript\nadd(methods, route, ...handlers)\n```\n\n**methods**\n\nThis can be the name os a single HTTP method, like \"GET\" or an array of method names [\"GET\", \"POST\"]. Special string \"*\" means that any method is allowed. If \"GET\" is allowed, then \"HEAD\" will be allowed automatically.\n\n\n**route**\n\nRoute is a path prefix that needs to be matched with the `url` from request. If segment of route is in form `:<word>`, this segment won't be matched with the part of the `url`, instead this part of the `url` will be available in the handler as `request.param[<word>]`.\n\n**handlers**\n\nThe rest of the parameters are middleware and a handler. The difference between middleware and handler is that middleware doesn't call `response.end()`. If route only has associated middleware and no final handler, this middleware will be executed for each path for which this route is a prefix.\n\n### CORS middleware\n\nMiddleware for adding CORS headers.\n\n```javascript\nimport cors from \"@cababunga/router/cors\";\ncors(options)\n```\n\nThe following options are recognized:\n\n**methods**\n\n Will be added as the value for the `Access-Control-Allow-Methods` header.\n\n **origin**\n\n Will be added as the value for the `Access-Control-Allow-Origin` header. If omitted, `req.headers[\"origin\"]` will be used.\n\n **headers**\n \n Will be added as the value for the `Access-Control-Allow-Headers` header.\n\n **credentials**\n\n Will be added as the value for the `Access-Control-Allow-Credentials` header.\n\n```javascript\nconst cors = require(\"@cababunga/router/cors\");\ncors({methods: \"GET, POST\", headers: \"content-type\"});\n```\n\n\n### Examples\n\n```javascript\nimport http from \"http\";\nimport router from \"@cababunga/router\";\nimport cors from \"@cababunga/router/cors\";\nconst accesslog = require(\"@cababunga/accesslog\");\n\nconst response = (res, data, code) => {\n    if (data === undefined)\n        res.writeHead(code || 204).end();\n    else\n        res.writeHead(code || 200, {\"Content-Type\": \"application/json\"}).end(JSON.stringify(data));\n};\n\nconst errorResponse = (res, code, message) =>\n    res.writeHead(code, {\"Content-Type\": \"application/json\"})\n        .end(JSON.stringify({err: true, msg: message}));\n\n// Middleware for authentication\nconst authenticate = async (req, res) => {\n    const sessionId = req.headers[\"x-session-id\"];\n    const session = await getSession(sessionId);\n    if (!session)\n        return errorResponse(res, 401, \"Please login\");\n    req.session = session;\n};\n\nconst getSession = async sessionId => { /* await getSession(sessionId) */ return Promise.resolve(1); };\nconst listAdd = async (req, res) => { /* await addToList(await req.json()); */ response(res, {ok: true}); };\nconst listRemove = async (req, res) => { /* await removeFromList(); */ response(res); };\n\nconst app = router();\napp.all(\"/\", cors({methods: \"GET, POST, PATCH, DELETE\", headers: \"x-session-id, content-type\"}));\napp.all(\"/\", accesslog(console.log, {skip: \"/health-check\"}));\n\napp.add(\"POST\", \"/api/1/list\", authenticate, listAdd);\napp.add(\"DELETE\", \"/api/1/list/:id\", authenticate, listRemove);\napp.error((err, req, res) => (res, err) => errorResponse(res, 500, err.message));\n\napp.listen(1234);\n```\n","readmeFilename":"README.md"}