Reputation: 1003
I've installed the node-captcha nodejs module from the following link...
https://github.com/napa3um/node-captcha
The example given on the website is as follows...
...
var captcha = require('captcha');
...
app.configure(function(){
...
app.use(app.router);
app.use(captcha('/captcha.jpg')); // url for captcha jpeg
app.use(express.static(__dirname + '/public'));
...
The app object is used in express but I'm not using express.
I've been trying to get captcha to work by calling "captcha('/captcha.jpg')" within the "http.createServer" function but nothing is happening.
I'm really puzzled as to how I make use of this module.
Upvotes: 4
Views: 6186
Reputation: 1003
Managed to write up a script that uses the module.
Also req.session.captcha = text should be commented out in the module's captcha.js file otherwise an error will be thrown. Commenting out that code does mean it should be replaced with a line that will store the captcha text to the session.
var http = require('http'), url = require('url'), captcha = require('captcha');
http.createServer(function (req, res) {
res.writeHead(200, {'Content-Type': 'text/html'});
var path = url.parse(req.url).pathname;
switch (path) {
case '/':
res.writeHead(200, {'Content-Type': 'text/html'});
res.write('<img src="/captcha.jpg" />');
res.end();
break;
case '/captcha.jpg':
captcha('/captcha.jpg')(req, res, 'noCaptcha');
break;
}
}).listen(8124, "127.0.0.1");
console.log('Server running at http://127.0.0.1:8124/');
noCaptcha = function() {
console.log('No captcha available');
};
Upvotes: 4