试图实现对应用程序的一些即时域搜索,但是,快速服务器仅在一次查询后退出。从语义上讲,我觉得一些代码需要重新排列,但我不确定是哪个。
var ee = new eventEmitter;
var queries = new Array();
ee.on('next', next_search);
function next_search() {
search(queries[a]);
if (queries.length == a) process.exit(0);
++a;
}
function search(x) {
dns.resolve(x, function (err) {
if (!err) {
console.log('bad: ' + x)
ee.emit('next')
} else {
console.log('good: ' + x)
ee.emit('next')
}
});
}
app.get('/', function (req, res) {
res.sendfile(__dirname + '/index.html');
});
app.post('/search', function (req, res) {
domain = req.param('domain');
queries.push(domain);
search(queries[queries.length]);
});
var a = 0;
http.createServer(app).listen(app.get('port'), function () {
console.log("Express server listening on port " + app.get('port'));
});