Windows环境下
问题的提出
- Mac环境
- 方便快捷地搭建小程序的测试服务器
- 小程序对于网络请求的URL的特殊要求
- 不能出现端口号
- 不能用localhost
- 必须用https
主要步骤
- 用json-server搭建简单地服务器,搭建出来的服务器地址为localhonst:3000
- 安装nginx进行反向代理,以便隐藏端口号和替换localhost
- 搭建https服务
- 微信小程序设置
用到的工具
- json-server
- nginx
- openssl
- 微信小程序官方开发工具
json-server的使用
- 安装
sudo npm install -g json-server
- 选一个文件目录新建json文件,比如cars.json
{
"cars": [
{
"id": 1,
"desc": "哈弗H6",
"completed": false
},
{
"id": 2,
"desc": "吉利博越",
"completed": false
},
{
"id": 3,
"desc": "宝骏560",
"completed": false
}
]
}
- 启动json-server服务:在新建的json文件目录,运行命令:json-server + 文件名
json-server cars.json
输出: