Security News
GitHub Removes Malicious Pull Requests Targeting Open Source Repositories
GitHub removed 27 malicious pull requests attempting to inject harmful code across multiple open source repositories, in another round of low-effort attacks.
middie is the module that add middlewares support on steroids to Fastify.
The syntax style is the same as express/connect.
Does not support the full syntax middleware(err, req, res, next)
, because error handling is done inside Fastify.
If you want to see how use this module with Fastify, check here.
npm install middie --save
const Middie = require('middie')
const http = require('http')
const helmet = require('helmet')
const cors = require('cors')
const middie = Middie(_runMiddlewares)
middie.use(helmet())
middie.use(cors())
http
.createServer(function handler (req, res) {
middie.run(req, res)
})
.listen(3000)
function _runMiddlewares (err, req, res) {
if (err) {
console.log(err)
res.end(err)
return
}
// => routing function
}
If you need it you can also keep the context of the calling function by calling run
with run(req, res, this)
, in this way you can avoid closures allocation.
http
.createServer(function handler (req, res) {
middie.run(req, res, { context: 'object' })
})
.listen(3000)
function _runMiddlewares (err, req, res, ctx) {
if (err) {
console.log(err)
res.end(err)
return
}
console.log(ctx)
}
If you need to run a middleware only under certains path(s), just pass the path as first parameter to use
and you are done!
Note that this does support routes with parameters, e.g. /user/:id/comments
, but all the matched parameters will be discarded
// Single path
middie.use('/public', staticFiles('/assets'))
// Multiple paths
middie.use(['/public', '/dist'], staticFiles('/assets'))
To guarantee compatibility with Express, adding a prefix uses path-to-regexp
to compute
a RegExp
, which is then used to math every request: it is signficantly slower.
This project is kindly sponsored by:
Licensed under MIT.
FAQs
`middie@7.1.0` has been deprecated. Please use `@fastify/middie@8.0.0` instead.
The npm package middie receives a total of 23,394 weekly downloads. As such, middie popularity was classified as popular.
We found that middie demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 13 open source maintainers 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
GitHub removed 27 malicious pull requests attempting to inject harmful code across multiple open source repositories, in another round of low-effort attacks.
Security News
RubyGems.org has added a new "maintainer" role that allows for publishing new versions of gems. This new permission type is aimed at improving security for gem owners and the service overall.
Security News
Node.js will be enforcing stricter semver-major PR policies a month before major releases to enhance stability and ensure reliable release candidates.