Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/jameslnewell/removable-middleware
A middleware wrapper allowing you to remove and replace the wrapped middleware while the server is running.
https://github.com/jameslnewell/removable-middleware
connectjs expressjs middleware removable replacable
Last synced: about 1 month ago
JSON representation
A middleware wrapper allowing you to remove and replace the wrapped middleware while the server is running.
- Host: GitHub
- URL: https://github.com/jameslnewell/removable-middleware
- Owner: jameslnewell
- Created: 2017-03-05T20:46:05.000Z (almost 8 years ago)
- Default Branch: master
- Last Pushed: 2017-03-06T04:32:58.000Z (almost 8 years ago)
- Last Synced: 2024-10-12T03:18:25.487Z (2 months ago)
- Topics: connectjs, expressjs, middleware, removable, replacable
- Language: JavaScript
- Size: 1000 Bytes
- Stars: 0
- Watchers: 3
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# removable-middleware
A middleware wrapper allowing you to remove and replace the wrapped middleware while the server is running.
> WARNING: It is not recommended to remove or replace middleware in a production
app [#2418](https://github.com/expressjs/express/issues/2418). However, removing middleware during development can be useful e.g. for
code-splitting.## Installation
npm install --save removable-middleware
## Usage
> Example: Hot-reloading a server app bundled with Webpack:
```js
import express from 'express';
import removableMiddleware from 'removable-middleware';
import myAppMiddleware from './myAppMiddleware';const app = express();
const middleware = removableMiddleware(myAppMiddleware);app
.use(middleware)
.listen(3000)
;if(module.hot) {
module.hot.accept('./myAppMiddleware', () => {
import('./myAppMiddleware').then(module => middleware.replace(module.default));
});
}```
## API
### `removableMiddleware(initialMiddleware)`
Creates a new middleware that wraps the another middleware.
### `.replace(nextMiddleware)`
Replaces the wrapped middleware with another middleware.
### `.remove()`
Removes the wrapped middleware.