Last active
December 11, 2015 10:19
-
-
Save gvangool/4586292 to your computer and use it in GitHub Desktop.
Test program for a bug in mikeal/stoopid
This file contains 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
{ | |
"name": "bug-stoopid-test", | |
"description": "Test program for a bug in mikeal/stoopid", | |
"author": "Gert Van Gool <[email protected]>", | |
"version": "0.0.1", | |
"dependencies": { | |
"cradle": "0.6.4", | |
"stoopid": "~0.2.1" | |
}, | |
"engine": "node >= 0.8.0" | |
} |
This file contains 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
// Test project for a bug in stoopid | |
/* Configure options */ | |
var server = require('http').createServer(), | |
logger = require('stoopid').logger('bug-stoopid'), | |
cradle = require('cradle'), | |
conn = new(cradle.Connection)({ | |
host: '127.0.0.1', | |
port: 5984, | |
cache: false, | |
raw: false | |
}), | |
port = 8080, | |
bind_address = '127.0.0.1'; | |
server.on('request', function (req, res) { | |
logger.info('URL', req.url); | |
switch (req.url) { | |
case '/test': | |
logger.debug('/test'); | |
conn.database('_users').get('_design/_auth', function(err, doc) { | |
if (err) { | |
logger.error("Couldn't find document: " + JSON.stringify(err)); | |
res.writeHead(500, | |
{'Content-Type': 'text/plain'} | |
); | |
res.end('ERROR! ' + JSON.stringify(err)); | |
return; | |
} | |
logger.info('Found document'); | |
res.writeHead(500, | |
{'Content-Type': 'text/plain'} | |
); | |
res.end('Everything alright!'); | |
}); | |
break; | |
default: | |
logger.warn('Unknown request: ' + req.url); | |
res.writeHead(400, | |
{'Content-Type': 'text/plain'} | |
); | |
res.end("I'm sorry, Dave. I'm afraid I can't do that."); | |
} | |
}); | |
server.listen(port, bind_address, function() { | |
logger.warn('listening at http://' + bind_address + ':' + port); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment