0

私は構築しようとしている高速アプリケーションの一部である次のコードを持っています:

app.get('/stat/1.gif', function( req, res ) {
    var time = +new Date();
    var origin;
    res.writeHead(200, {'Content-Type': 'image/gif'});
    origin = /\/(.*)\.gif/.exec(req.url);
    console.log(origin);
    if (origin) {
        var ip = req.ip;
        if (ip === null || ip === "127.0.0.1") {
            ip = "82.246.239.187";
        }
        location = geoip.lookup(ip);
        console.log(location);
        var obj;
        console.log(location.city);
        console.log(location.ll[1]);
        console.log(location.ll[0]);
        obj = {
            city: location.city
            ,longitude: location.ll[1]
            ,latitude: location.ll[0]
            ,ip: ip
            ,timestamp: time
        };
        console.log(obj);
    everyone.now.receiveLocation(obj);
    } else {
        console.log( 'fixme no origin' );
    }
});

console.log() を見て、私はobjとして取得します

{ city: 'Nîmes',
  longitude: 4.3596,
  latitude: 43.8338,
  ip: '82.246.239.187',
  timestamp: 1359930392288 }

しかし、私はこのエラーを受け取り続けます:

TypeError: Property 'receiveLocation' of object #<Object> is not a function
    at /Users/khinester/Documents/Tutorials/Node/Blade/server.js:188:18
    at callbacks (/Users/khinester/Documents/Tutorials/Node/Blade/node_modules/express/lib/router/index.js:161:37)
    at param (/Users/khinester/Documents/Tutorials/Node/Blade/node_modules/express/lib/router/index.js:135:11)
    at pass (/Users/khinester/Documents/Tutorials/Node/Blade/node_modules/express/lib/router/index.js:142:5)
    at Router._dispatch (/Users/khinester/Documents/Tutorials/Node/Blade/node_modules/express/lib/router/index.js:170:5)
    at Object.router (/Users/khinester/Documents/Tutorials/Node/Blade/node_modules/express/lib/router/index.js:33:10)
    at next (/Users/khinester/Documents/Tutorials/Node/Blade/node_modules/express/node_modules/connect/lib/proto.js:199:15)
    at resume (/Users/khinester/Documents/Tutorials/Node/Blade/node_modules/express/node_modules/connect/lib/middleware/static.js:60:7)
    at SendStream.error (/Users/khinester/Documents/Tutorials/Node/Blade/node_modules/express/node_modules/connect/lib/middleware/static.js:73:37)
    at SendStream.EventEmitter.emit (events.js:115:20)

https://github.com/bluesmoon/node-geoipを使用しています

次のコードでhttps://github.com/kuno/GeoIPを使用していました。

app.get('/stat/1.gif', function( req, res, next ) {
    var time = +new Date();
    var origin;
    res.writeHead(200, {'Content-Type': 'image/gif'});
    origin = /\/(.*)\.gif/.exec(req.url);
    if (origin) {
        var ip = req.headers['x-real-ip'];
        if (ip === null || ip === "127.0.0.1") {
            ip = "82.246.239.187";
        }
        city.lookup(ip, function(err, location) {
            var obj;
            if ( !err && location ) {
                obj = {
                    city: location.city
                    ,longitude: location.longitude
                    ,latitude: location.latitude
                    ,ip: ip
                    ,timestamp: time
                };
            } else { 
                console.log( 'server fake location' );
                obj ={ 
                    city: 'Bexleyheath',
                    longitude: 0.15000000596046448,
                    latitude: 51.45000076293945,
                    ip: '86.173.61.119',
                    timestamp: 1343054092459 
                };
            }
            everyone.now.receiveLocation(obj);
            console.log(obj);
        });
    console.log(origin[1], req.connection.remoteAddress, req.headers['user-agent']);
    } else {
        console.log( 'fixme no origin' );
    }
});

これは正常に動作しますが、ホットしたいホストとして geoip-lite を使用する必要があり、これには geoip c ライブラリがありません。

アドバイスをいただければ幸いです。

4

0 に答える 0