[跨域代理]
1后台之间没有跨域限制
a[服务器一般有做白名单]
2客户端和服务器才有跨域限制
a[浏览器的安全策略]
3原理:间接访问,客户端访问代理服务器(客户端和代理服务器同源),代理服务器和存储数据的服务器没有跨域限制,就可以访问
4node里dev-server
本地开发:直接基于 dev-server proxy实现跨域代理
部署上线:服务器没有 但是可以基于nginx反向代理来做
nginx反向代理和dev-server配套
4
server
listen
80;
192.168,161.189;
servername
#charsetkoi8-r
logs/hostaccess.log
#access_log
main;
Location
proxy_passhttp://192.168.161.189:8070;
html;
root
index.htmlindex.htm;
indeX
自己写dev-server
const path = require('path');const HtmlWebpackPlugin = require('html-webpack-plugin');module.exports = {mode: 'production',entry: './src/main.js',output: {filename: 'main.[hash].min.js',path: path.resolve(__dirname, 'build')},devServer: {port: '3000',compress: true,open: true,hot: true,proxy: {'/': {target: 'http://127.0.0.1:3001',changeOrigin: true}}},// 配置WEBPACK的插件plugins: [new HtmlWebpackPlugin({template: `./public/index.html`,filename: `index.html`})]};
