运维服务中台
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 

27 lines
695 B

const request = require('superagent');
let _weatherUrl = '';
module.exports.entry = function (app, router, opts) {
const { weatherUrl } = opts;
_weatherUrl = weatherUrl;
router.get('/query/weather', weather);
};
async function weather(ctx) {
try {
const { cityName } = ctx.query;
const weatherRes = await request.post(_weatherUrl).send({ cityName });
const { body } = weatherRes;
if (body && body.data) {
ctx.status = 200;
ctx.body = { ...body.data, cityName };
} else {
ctx.status = 400;
ctx.body = { msg: '获取天气错误' };
}
} catch (error) {
console.log('[*err]', error);
ctx.status = 400;
ctx.body = error;
}
}