
Security News
ECMAScript 2025 Finalized with Iterator Helpers, Set Methods, RegExp.escape, and More
ECMAScript 2025 introduces Iterator Helpers, Set methods, JSON modules, and more in its latest spec update approved by Ecma in June 2025.
cors-middleware
Advanced tools
Middleware to set your Cross Origin Resource Sharing headers in your http clients ✌🏽.
cors-middleware
functions as middleware that takes in req
, res
, ctx
,
done
and sets all applicable headers on the res
argument.
var corsMiddleware = require('cors-middleware')
var merry = require('merry')
var mw = merry.middleware
var cors = corsMiddleware({
methods: 'GET',
origin: 'http://localhost:8080'
})
var app = merry()
app.use(cors)
app.router('GET', '/', homeRoute)
function homeRoute (req, res, ctx) {
console.log(res.getHeader('access-control-allow-origin')) // 'http://localhost:8080'
ctx.send(200, { msg: 'woah cors headers are all set' })
}
You can pass on a few options to the cors wrapper to handle the specific headers you might need. If not tho, we gotchu with some defaults.
['Content-Type', 'Accept', 'X-Requested-With']
.['PUT', 'POST', 'DELETE', 'GET', 'OPTIONS']
'*'
FAQs
add cors headers to a route's res
We found that cors-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
ECMAScript 2025 introduces Iterator Helpers, Set methods, JSON modules, and more in its latest spec update approved by Ecma in June 2025.
Security News
A new Node.js homepage button linking to paid support for EOL versions has sparked a heated discussion among contributors and the wider community.
Research
North Korean threat actors linked to the Contagious Interview campaign return with 35 new malicious npm packages using a stealthy multi-stage malware loader.