pre: {
'/api/': {
// 要代理的地址
target: 'http://localhost:8000',
// 配置了这个可以从 http 代理到 https
// 依赖 origin 的功能可能需要这个,比如 cookie
changeOrigin: true,
},
'/admin/':{
// 我的API接口地址
target: 'http://localhost:3000',
// 配置了这个可以从 http 代理到 https
// 依赖 origin 的功能可能需要这个,比如 cookie
changeOrigin: true,
}
在config/proxy.ts下面配置自己的后台API接口后缀,Proxy会自动转发给我们的服务器,
比如我的前端服务在8000端口,我的API地址在3000端口同一IP下这样弄好以后umi build打包以后,我们的前端部署在nginx下面,还需要通过nginx转发给我们的node后端服务配置如下:
server {
.......
listen 8000;
server_name localhost;
#charset koi8-r;
#access_log logs/host.access.log main;
location / {
root html;
index index.html index.htm;
}
#转发 主要配置这个!!!
location /admin {
proxy_pass http://127.0.0.1:3000;
}
......