Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
var express = require('express'),
http = require('http'),
longRes = require('./data'),
app = express();
app.disable('x-powered-by');
// this is the function utilized to stage a request
express.response.stage = function(body, cb) {
this.stagedResponse = {body: body}
cb(null, null)
}
// Monkey patch express
express.response.ship = function(body, status) {
var _this = this;
// Testing adding a header
this.set('Access-Control-Allow-Methods', 'GET, POST, PUT, DELETE, OPTIONS');
// Simulate waiting for async
process.nextTick(function() {
// Adding another header right before sending
_this.set('Fake', '123');
_this.json(status, body);
});
};
app.use(express.compress());
app.get('/', function(req, res, next) {
res.set('Access-Control-Allow-Origin', '*');
res.ship(longRes, 200);
});
http.createServer(app).listen(3000, function() {
console.log('up')
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.