|
@@ -1,10 +1,12 @@
|
|
'use strict';
|
|
'use strict';
|
|
|
|
|
|
import Cities from '../../models/v1/cities';
|
|
import Cities from '../../models/v1/cities';
|
|
|
|
+import http from 'http'
|
|
|
|
+
|
|
|
|
|
|
class CityHandle {
|
|
class CityHandle {
|
|
constructor(){
|
|
constructor(){
|
|
-
|
|
|
|
|
|
+ this.cityGuess = this.cityGuess.bind(this);
|
|
}
|
|
}
|
|
async cityGuess(req, res, next){
|
|
async cityGuess(req, res, next){
|
|
const type = req.query.type;
|
|
const type = req.query.type;
|
|
@@ -18,6 +20,8 @@ class CityHandle {
|
|
let cityInfo;
|
|
let cityInfo;
|
|
switch (type){
|
|
switch (type){
|
|
case 'guess':
|
|
case 'guess':
|
|
|
|
+ const city = this.getCityName(req);
|
|
|
|
+ // console.log(ip)
|
|
cityInfo = await Cities.cityGuess('shanghai');
|
|
cityInfo = await Cities.cityGuess('shanghai');
|
|
break;
|
|
break;
|
|
case 'hot':
|
|
case 'hot':
|
|
@@ -29,6 +33,21 @@ class CityHandle {
|
|
}
|
|
}
|
|
res.send(cityInfo)
|
|
res.send(cityInfo)
|
|
}
|
|
}
|
|
|
|
+ getCityName(req){
|
|
|
|
+ const ip = req.headers['x-forwarded-for'] ||
|
|
|
|
+ req.connection.remoteAddress ||
|
|
|
|
+ req.socket.remoteAddress ||
|
|
|
|
+ req.connection.socket.remoteAddress;
|
|
|
|
+ //调用阿里云接口
|
|
|
|
+ http.get('http://saip.market.alicloudapi.com/ip?ip=' + ip,function(req,res){
|
|
|
|
+ var html='';
|
|
|
|
+ req.on('data',function(data){
|
|
|
|
+ html+=data;
|
|
|
|
+ });
|
|
|
|
+ req.on('end',function(){
|
|
|
|
+ console.info(html);
|
|
|
|
+ });
|
|
|
|
+ });
|
|
|
|
+ }
|
|
}
|
|
}
|
|
-
|
|
|
|
export default new CityHandle()
|
|
export default new CityHandle()
|