前端请求转发代理,解决跨域问题
- 若是静态界面,直接将http请求地址改为
little-Forwarding-agent
的启动地址 - 若是angular/react等框架
- 将如下代码中的IP地址改为
little-Forwarding-agent
启动地址,添加到package.json
proxy: "http://127.0.0.1:3001"
- 使用ajax等发送http时,不需要加入ip和端口部分,例如
fetch("/api/del", { method: 'POST', headers: { "Content-Type": "application/x-www-form-urlencoded; charset=UTF-8", }, credentials: 'include', ... }
- 将如下代码中的IP地址改为
- 在
little-Forwarding-agent
修改要转发的ip目的地地址,在router/index
中
目前只支持转发GET和POST方法。