Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Connect Async Basic Auth
cluster = require('cluster')
http = require('http')
connect = require('connect')
request = require('request')
sys = require('sys')
done = (success) ->
console.log("FN!" + success)
true
module.exports = server = connect.createServer(
connect.basicAuth( (user, pass, done) ->
console.log("Reached callback for BasicAuth")
authenticate({ user: user, pass: pass }, done)
)
connect.router( require('./convore') )
)
authenticate = (user,done) ->
console.log "Reached Authenticate"
console.log("User: "+user.user+" Pass: "+user.pass)
request({uri: "https://"+user.user+":"+user.pass+"@convore.com/api/account/verify.json"},(error, response, body) ->
if !error && response.statusCode == 200
console.log("Response from request: "+body)
done(true)
)
cluster(server)
.set('workers', 4)
.use(cluster.debug())
.listen(3000)
@leighton

This comment has been minimized.

Copy link

leighton commented Apr 23, 2011

Shouldn't you be calling "fn" as the callback in authenticate?

@ryanbillingsley

This comment has been minimized.

Copy link
Owner Author

ryanbillingsley commented Apr 23, 2011

Yes, I forgot to update the gist. The callback fires but the request just hangs. It is never getting a true or false answer

@leighton

This comment has been minimized.

Copy link

leighton commented Apr 24, 2011

Your globally defined "done" function will not be called, it is overridden by local arguments, and you haven't called "done" in the event of the request failing (this would result in hanging).

@ryanbillingsley

This comment has been minimized.

Copy link
Owner Author

ryanbillingsley commented Apr 25, 2011

ahh that makes a little more sense. thanks for the help.

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.