解决跨域之服务器代理http-proxy-middleware模块

时间:2018-06-02 12:20:27   收藏:0   阅读:1631

安装模块

yarn add http-proxy-middleware

引入模块

app.js

var proxy = require("http-proxy-middleware");

使用模块

app.js

var app = express();
// 请求的路由地址(接口文件) 进行跨域请求的协议域名
app.use(‘/ajax_www_68ecshop_com.php‘, proxy({target: ‘https://www.jkslw.cn‘, changeOrigin: true}))

前端访问接口

index.html

$.ajax({
  type:"get",
  //直接传入路由地址,无需加上域名   url:
"/ajax_www_68ecshop_com.php?act=tipword&word=xiaomi&152790640006565",   dataType:"json",   success:function(data){     console.log(data);   }
})

 

评论(0)
© 2014 mamicode.com 版权所有 京ICP备13008772号-2  联系我们:gaon5@hotmail.com
迷上了代码!