Skip to content

Instantly share code, notes, and snippets.

@shanestillwell
Created April 25, 2014 17:39
Show Gist options
  • Save shanestillwell/11297429 to your computer and use it in GitHub Desktop.
Save shanestillwell/11297429 to your computer and use it in GitHub Desktop.
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