Skip to content

Instantly share code, notes, and snippets.

@ryanbillingsley
Created April 22, 2011 16:31
Show Gist options
  • Save ryanbillingsley/936994 to your computer and use it in GitHub Desktop.
Save ryanbillingsley/936994 to your computer and use it in GitHub Desktop.
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
Copy link

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

@ryanbillingsley
Copy link
Author

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
Copy link

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
Copy link
Author

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