first commit

This commit is contained in:
编码猿
2024-09-27 02:06:13 +08:00
commit 852d94fbb9
36760 changed files with 3274413 additions and 0 deletions

View File

@@ -0,0 +1,41 @@
const express = require('express');
const request = require('request')
const app = express()
const cheerio = require('cheerio')
var IPURL = "http://200019.ip138.com/";
var BaseUrl = {
url: 'http://v.juhe.cn/weather/index',
appkey: '434c32f4a4f0d235196d7797752f6b61'
}
app.all("*",function(req,res,next){
res.header('Access-Control-Allow-Origin', '*');
next();
})
app.get('/getWeather', function(req, res) {
var cityName = req.query.cityname;
var url = `${BaseUrl.url}?key=${BaseUrl.appkey}&cityname=${encodeURI(cityName)}&format=2`;
request(url,function(error, response, body) {
res.json(JSON.parse(body))
})
})
app.get('/ip', function(req, res) {
request(IPURL,function(error, response, body) {
const $ = cheerio.load(body)
var ipaddress = $('body>p').text();
res.json({
resultcode: "200",
result: {
city: ipaddress.substring(ipaddress.indexOf("市")-3,(ipaddress.indexOf("市")-3)+3)
}
})
})
})
app.listen(9090, function() {
console.log('Example app listening on port 3000!')
})