gpt4 book ai didi

node.js - nodejs - 如何使用 Node 验证码模块?

转载 作者:搜寻专家 更新时间:2023-10-31 23:49:43 27 4
gpt4 key购买 nike

我已经从以下链接安装了 node-captcha nodejs 模块...

https://github.com/napa3um/node-captcha

网站给出的例子如下...

...
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'));
...

app 对象在 express 中使用,但我没有使用 express。

我一直在尝试通过在“http.createServer”函数中调用“captcha('/captcha.jpg')”来让验证码正常工作,但没有任何反应。

我真的很困惑如何使用这个模块。

最佳答案

设法编写了一个使用该模块的脚本。

另外 req.session.captcha = text 应该在模块的 captcha.js 文件中注释掉,否则会抛出错误。注释掉该代码确实意味着它应该被替换为将验证码文本存储到 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');
};

关于node.js - nodejs - 如何使用 Node 验证码模块?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9487844/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com