Last active
August 29, 2015 14:21
-
-
Save grabbou/8d414150e99e208d820a to your computer and use it in GitHub Desktop.
X-Powered-By: Este
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// middleware.js | |
import onHeaders from 'on-headers'; | |
export default function setupMiddleware(headers = [], options = {}) { | |
return function onRequest(req, res, next) { | |
// Do the action when headers are emitted for given res | |
onHeaders(res, _ => { | |
headers.forEach((value, header) => { | |
// If header does not exist or keepExisting is true | |
if (!res.getHeader(header) || !options.keepExisting) { | |
res.setHeader(header, value); | |
} | |
}); | |
}); | |
next(); | |
} | |
} | |
// main.js | |
import express from 'express'; | |
import setupHeaders from './middleware'; | |
const app = express(); | |
app.use(setupHeaders({ | |
'X-Powered-By': 'Este.js', | |
'X-Este-Version': '0.0.1' | |
})); | |
app.get('*', (req, res) => { | |
res.end('Hello!'); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment