
Security News
Crates.io Implements Trusted Publishing Support
Crates.io adds Trusted Publishing support, enabling secure GitHub Actions-based crate releases without long-lived API tokens.
run-middleware
Advanced tools
NodeJS module to execute your Express endpoints (middlewares) from your code. This module will let you laucnch manually all your middleware. It is simulate a client calling to your rest API's. It is not using a network connections
NodeJS module to execute your Express endpoints (middlewares) from your code. This module will let you manually launch all your middleware. It is simulating a client calling your rest APIs, without using a network connection (your server does not even need to listen on a port).
#NodeJS run-middleware
Many times, your server and your client, need to execute the same functions. For example here is an endpoint to get user details:
app.get('/get-user/:id',function(req,res){
mysql.query('select * from users where id=?',[req.params.id],function(err,rows){
res.send({user:rows[0]})
})
})
Now you want to get the user details from your code. What should you do?
app.runMiddleware('/get-user/20',function(code,body,headers){
console.log('User Details:',body)
})
npm i -S run-middleware
var express=require('express')
var app=express();
require('run-middleware')(app)
run-middleware
tag.As options you can pass the query
, body
, method
, cookies
parameters.
app.runMiddleware('/handler',{
method:'post',
query:{token:'tk-12345'},
body:{"action":"list","path":"/"}
},function(code,data){
console.log(code,data)
process.exit()
})
When you can runMiddleware from another middleware, you can autopass all the parameters of the current middleware, by using the express request
object.
app.get('/middleware1',function(req,res){
// We use res.runMiddleware instead of app.runMiddleware. All the cookies & other data (like socket.io session) will be pass to the second middleware
res.runMidleware(...)
})
If the middleware you execute will redirect, you will be notified about it, by reading the code
and the headers.location
app.runMiddleware('/this-middleware-will-response-as-redirect',function(code,body,headers){
if(code==301 || code=302) {// Redirect HTTP codes
console.log('Redirect to:',headers.location)
}
})
See the tests
ISC License Copyright (c) 2016, Aminadav Glickshtein
Permission to use, copy, modify, and/or distribute this software for any purpose with or without fee is hereby granted, provided that the above copyright notice and this permission notice appear in all copies.
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
FAQs
NodeJS module to execute your Express endpoints (middlewares) from your code. This module will let you laucnch manually all your middleware. It is simulate a client calling to your rest API's. It is not using a network connections
The npm package run-middleware receives a total of 1,230 weekly downloads. As such, run-middleware popularity was classified as popular.
We found that run-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.
Security News
Crates.io adds Trusted Publishing support, enabling secure GitHub Actions-based crate releases without long-lived API tokens.
Research
/Security News
Undocumented protestware found in 28 npm packages disrupts UI for Russian-language users visiting Russian and Belarusian domains.
Research
/Security News
North Korean threat actors deploy 67 malicious npm packages using the newly discovered XORIndex malware loader.