返回功能不起作用? (打回来)

时间:2015-04-13 21:22:16

标签: javascript mysql node.js function callback

我正在使用Node.JS,但我正在尝试获取禁止日期,我的回复将无效。

代码:

exports.getVar = function(string,request) {
var mysql = require('mysql').createConnection({host: 'localhost', user: 'root', password: 'triogames3', database: 'UG'});

var ipadress = function(req) {
    var ip = (req.headers["X-Forwarded-For"] ||
            req.headers["x-forwarded-for"] ||
            '').split(',')[0] ||
           req.client.remoteAddress;

    return mysql.escape(ip);
};

if (string == "BanDate"){

    mysql.query('SELECT * FROM `ban-ips` WHERE `ip`="' + ipadress(request) + '"',function (err, data) {
        if (!err){
            if (data.length > 0){
                var banDate = data[0].unbanDate,
                dateNow = new Date(),
                diffMs = (banDate - dateNow);
                if (diffMs > 0){
                    return banDate;
                } else {
                    return '<meta http-equiv="refresh" content="0; url=http://universal-games.nl">';
                }
            } else {
                return '<meta http-equiv="refresh" content="0; url=http://universal-games.nl">';
            }
        } else {
            console.log(err.code);
            return 'Err';
        }
    });

} else if (string == "bannedTitle"){
    return "Banned";
} else if (string == "loginTitle"){
    return "Login";
} else if (string == "siteName"){
    return "UGFS Admin";
} else if (string == "style"){
    return "assets/css/style.css";
} else {
    return "Err";
}

};

正如你所看到的那样,我试图通过某种方式让绷带得到什么? 我称之为:

var htmlReplace = function(html){
    var matches = html.match(/\{(.*?)\}/g);

    if (matches) {
        matches.forEach(function(entry) {
            if (entry.substr(1, 1) == "$"){
                html = html.replace(entry, dataVar.getVar(entry.substring(2, entry.length - 1), req));
                console.log(dataVar.getVar(entry.substring(2, entry.length - 1), req));
            }
        });
    }

    return html;
};

在我的HTML中我正在使用{$ banDate} 所有其他人认为只有大班的工作不起作用?请帮帮我?

0 个答案:

没有答案