Last active
December 10, 2015 18:58
-
-
Save jfromaniello/4478401 to your computer and use it in GitHub Desktop.
error_domains.js
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
//npm install express request mongodb connect-domain connect-mongodb | |
var request = require('request'), | |
express = require('express'), | |
connectDomain = require('connect-domain'), | |
http = require('http'); | |
var MongoStore = require('connect-mongodb'), | |
Db = require('mongodb').Db, | |
Server = require('mongodb').Server, | |
server_config = new Server('localhost', 27017, {auto_reconnect: true, native_parser: true}), | |
db = new Db('test', server_config, {}), | |
mongoStore = new MongoStore({db: db}); | |
var app = express(); | |
app.configure(function(){ | |
//if i move this line after express.session | |
//everything works as expected. | |
this.use(connectDomain()); | |
this.use(express.cookieParser()); | |
this.use(express.session({secret: 'foobar', store: mongoStore })); | |
this.use(app.router); | |
this.use(function(err, req, res, next){ | |
res.end(err.message); | |
}); | |
}); | |
app.get('/', function(req, res, next){ | |
var r = request.get('http://localhost:9999'); | |
//at this point r.domain is null. | |
//If i explicitly add this stream to the domain it works | |
//Slightly changing connect-domain to store the domain in req, if i do | |
//req.__domain.add(r); it works | |
r.pipe(res); | |
}); | |
http.createServer(app).listen(3000, function(){ | |
console.log('listening on http://localhost:3000'); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment