
Research
Malicious npm Packages Impersonate Flashbots SDKs, Targeting Ethereum Wallet Credentials
Four npm packages disguised as cryptographic tools steal developer credentials and send them to attacker-controlled Telegram infrastructure.
@ineentho/composable-middleware
Advanced tools
Treat a sequence of middleware as middleware.
Install the module with: npm install composable-middleware
var composable_middleware = require( 'composable-middleware' );
Middleware is a function that follows specific conventions. Composable middleware allows a series of middleware functions to be used as if they were a single middleware function. With it, a middleware stack is middleware and becomes a first-class object. With composable middleware you can:
You may compose middleware by defining its steps in the argument to the composable-middleware function:
var mw =
composable_middleware(
connect.logger(),
connect.gzip(),
);
or by using its use
function:
var mw =
composable_middleware()
.use(connect.logger())
.use(connect.gzip());
and then include it in another middleware stack:
var okay =
composable_middleware()
.use(mw)
.use(
function(req,res,next) {
res.send('okay');
})
You might then use that middleware in Connect, Express or any other middleware-based framework:
var app = connect();
app.use(okay);
app.listen(3000);
One of the design goals of this package is to minimize overhead when sequencing through middleware steps. Notably, it does not support mounting paths or routing. It does not examine the URL at all. That is best left to middleware, perhaps middleware that routes requests into different middleware stacks depending upon route.
The composable_middleware software also does not deal with errors or unhandled requests other than routing errors to middleware that expects an error argument. Since a middleware stack may be treated as middleware within another middleware stack, it cannot be assumed that reaching the end of the stack has any significance. You will need to provide middleware (perhaps we should call it 'finalware') to send out 404 responses or to log errors and send 500 responses if the overall framework in which the middleware is running does not do so.
The Composable Middleware package supports Connect middleware and flatiron/union middleware as well as a hybrid of the two.
(req,res,next)
()
. The request and response are in this.req
and this.res
. this.res.emit('next')
passes the request to the next level of middleware.(next)
. The request and response are in this.req
and this.res
.(err,req,res,next)
(err,next)
. The request and response are in this.req
and this.res
.The middleware type is determined by checking its arity:
Error-handling middleware is skipped unless an error was passed to the next
function. Normal middleware is skipped if there is an error.
Although not a convention shared by other middleware containers, this package calls all middleware serving a given request in the same context. It should thus be possible to attach an attribute to this
in one middleware function and access it in a different middleware function serving the same request. This package will assure, however, that the global object is not used as the context, allocating a new object to serve as the context, if needed. To avoid the possibility of interference, if invoked as Connect middleware, composable-middleware
will similarly replace the Connect context with a new context. If a new context is created, this._middleware_common_object
will be defined. The constructor for the new context is exported as MiddlewareCommonObject and the function used by composable-middleware
to test whether a new context is needed is exported as is_protected_content
.
In lieu of a formal styleguide, take care to maintain the existing coding style. Add unit tests for any new or changed functionality. Lint and test your code using Grunt.
this
object for all middleware serving a given request.Copyright (c) 2013 Randy McLaughlin Licensed under the MIT license.
FAQs
Treat a sequence of middleware as middleware.
We found that @ineentho/composable-middleware demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Research
Four npm packages disguised as cryptographic tools steal developer credentials and send them to attacker-controlled Telegram infrastructure.
Security News
Ruby maintainers from Bundler and rbenv teams are building rv to bring Python uv's speed and unified tooling approach to Ruby development.
Security News
Following last week’s supply chain attack, Nx published findings on the GitHub Actions exploit and moved npm publishing to Trusted Publishers.