[2.演示]
1.和前端联调
- 登陆功能依赖cookie,必须用浏览器来联调
- cookie 跨域不共享,前端和server端必须同域
- 需要用到 nginx 做代理,让前后端同域
前端文件目录:
1.开启http服务
安装 http服务,开启8001端口
npm install http-server -g
http-server -p 8001
由于服务器端口是800端口,而我们的端口是8001,所以会404,况且cookie跨域也不共享。解决方案是用nginx进行联调。
2.使用nginx联调
我的nginx目录:
C:\nginx-1.19.0\conf
nginx.conf 配置
server {
listen 8080;
location / {
proxy_pass http://localhost:8001;
}
location /api/ {
proxy_pass http://localhost:8000;
proxy_set_header Host $host;
}
}
开启nginx代理
C:\Users\way liu>cd C:\nginx-1.19.0
C:\nginx-1.19.0>nginx -v
nginx version: nginx/1.19.0
C:\nginx-1.19.0>nginx -t
nginx: the configuration file C:\nginx-1.19.0/conf/nginx.conf syntax is ok
nginx: configuration file C:\nginx-1.19.0/conf/nginx.conf test is successful
C:\nginx-1.19.0>start nginx
- nginx -v 查看nginx版本
- nginx -t 检查nginx配置语法
- start nginx 开启nginx
- 参考 https://www.cnblogs.com/yang-2018/p/11418506.html
2.演示
1.http://127.0.0.1:8080/index.html
2. 登陆与管理
http://127.0.0.1:8080/login.html
3.点击编辑