{"id":13658000,"url":"https://github.com/kessler/node-dynamic-middleware","last_synced_at":"2025-03-17T02:31:11.588Z","repository":{"id":18112967,"uuid":"21184802","full_name":"kessler/node-dynamic-middleware","owner":"kessler","description":"turn a connect/express middleware into a runtime replaceable, deletable middleware","archived":false,"fork":false,"pushed_at":"2022-12-30T21:01:56.000Z","size":164,"stargazers_count":42,"open_issues_count":2,"forks_count":6,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-03-08T08:12:40.372Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":"SF-WDI-LABS/depth-first-search","license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/kessler.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2014-06-25T00:07:09.000Z","updated_at":"2025-01-02T01:01:18.000Z","dependencies_parsed_at":"2023-01-13T19:39:41.926Z","dependency_job_id":null,"html_url":"https://github.com/kessler/node-dynamic-middleware","commit_stats":null,"previous_names":[],"tags_count":10,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kessler%2Fnode-dynamic-middleware","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kessler%2Fnode-dynamic-middleware/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kessler%2Fnode-dynamic-middleware/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kessler%2Fnode-dynamic-middleware/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/kessler","download_url":"https://codeload.github.com/kessler/node-dynamic-middleware/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":243837011,"owners_count":20355813,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-08-02T05:00:54.993Z","updated_at":"2025-03-17T02:31:11.146Z","avatar_url":"https://github.com/kessler.png","language":"JavaScript","funding_links":[],"categories":["JavaScript"],"sub_categories":[],"readme":"# dynamic-middleware [![Build Status](https://secure.travis-ci.org/kessler/node-dynamic-middleware.png?branch=master)](http://travis-ci.org/kessler/node-dynamic-middleware)\n\nReplace or disable a connect/express middleware in runtime\n\ncompatible with express 3, express 4 and connect 3\n\n### Why?\n\nits quite inconvenient to replace a middleware after you start a connect / express server\n\n### Install\n```\n    npm install dynamic-middleware\n```\n\n### Usage\n```javascript\nconst DynamicMiddleware = require('dynamic-middleware')\nconst express = require('express')\n\nconst app = express()\n\n// a simple middleware\nfunction myMiddleware(req, res, next) {\n    res.end('1')\n}\n\n// create a dynamic one from it\nlet dm = DynamicMiddleware.create(myMiddleware)\n\napp.get('/', dm.handler()) \n\n// disable the middleware, will reply with 404 now\ndm.disable() \n\n// enable it back\ndm.enable()\n\n// or replace it with something else\ndm = dm.replace(function(req, res, next) {\n    res.end('2')\n})\n\n// create a dynamic error middlware\nlet errorDm = DynamicMiddleware.create((err, req, res, next) =\u003e { ... })\n\napp.use(errorDm.errorHandler())\n\n```\n\n## see also\n[loadbalance module](https://github.com/kessler/node-loadbalance)\n\n[loadbalance-middleware module](https://github.com/kessler/node-loadbalance-middleware)\n\n## changelog\n\n### 3.x.x\n\nPrevious versions operated by manipulating the internal state of express/connect , this approach worked well for real middlewares (.use()) but was terrible for routes (.get() etc..). The new version does not do that, but rather manages the state internally.\n\n### 4.x.x\n\nThe public interface of this module has changed\n\n## license\n\n[MIT](http://opensource.org/licenses/MIT) © [yaniv kessler](yanivkessler.com)","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkessler%2Fnode-dynamic-middleware","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fkessler%2Fnode-dynamic-middleware","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkessler%2Fnode-dynamic-middleware/lists"}