0%

前置依赖,安装这个的目的是可以使用sudo yum-config-manager --enable nginx-mainline命令

1
sudo yum install yum-utils

创建yum仓库配置文件

/etc/yum.repo.d/nginx.repo

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
[nginx-stable]
name=nginx stable repo
baseurl=http://nginx.org/packages/centos/$releasever/$basearch/
gpgcheck=1
enabled=1
gpgkey=https://nginx.org/keys/nginx_signing.key
module_hotfixes=true

[nginx-mainlne]
name=nginx mainline repo
baseurl=http://nginx.org/packages/mainline/centos/$releasever/$basearch/
gpgcheck=1
enabled=0
gpgkey=https://nginx.org/keys/nginx_signing.key
module_hotfixes=true

安装nginx

1
sudo yum install nginx

Promise最大的好处是在异步执行过程中,把执行代码逻辑和处理请求后的结果分离了,解偶合了。

执行代码逻辑,比如请求api后,返回http code 200怎么做,返回400又怎么做。

可以把如下代码复制到Chrome的Console里面执行。

1
2
3
4
5
6
7
8
9
10
11
new Promise(function(resolve, reject) {
var return_code = 400 // 任意设置
if (return_code == 200) {
resolve('OK')
} else {
reject({code: 400})
}
}).then((res) => {
console.log(res)
}).catch((res) => {
console.log(res)});

高德开放平台下的天气查询接口文档

https://lbs.amap.com/api/webservice/guide/api/weatherinfo

注册开发者账号,获取Key

1
https://restapi.amap.com/v3/weather/weatherInfo?parameters

parameters代表的参数包括必填参数和可选参数。

https://restapi.amap.com/v3/weather/weatherInfo?key=[key]&city=310115

返回结果:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
{
"status": "1",
"count": "1",
"info": "OK",
"infocode": "10000",
"lives": [
{
"province": "上海",
"city": "浦东新区",
"adcode": "310115",
"weather": "多云",
"temperature": "6",
"winddirection": "北",
"windpower": "≤3",
"humidity": "56",
"reporttime": "2020-01-12 17:57:21"
}
]
}

百度api是jsonp的方式获取数据,而高德地图的api是允许跨域的。