SimulatedGREG / electron-vue

An Electron & Vue.js quick start boilerplate with vue-cli scaffolding, common Vue plugins, electron-packager/electron-builder, unit/e2e testing, vue-devtools, and webpack.
https://simulatedgreg.gitbooks.io/electron-vue/content/
MIT License
15.48k stars 1.55k forks source link

反向代理怎么配置 #939

Open snail-boy opened 5 years ago

snail-boy commented 5 years ago

将electron-vue集成到现有项目中,vue-cli3.0搭建的项目 ,,现有项目请求后端地址需要在vue.config.js配置反向代理

 [process.env.VUE_APP_BASE_API]: {
        target: `http://192.168.1.11:8092/test-web/`,
        changeOrigin: true,
        pathRewrite: {
          ['^' + process.env.VUE_APP_BASE_API]: ''
        }
      }

electron-vue在哪里配置

umbrella22 commented 5 years ago

您应当在electron的主进程中设置webSecurity:false,来允许跨域请求,而不是在脚手架中配置代理达到跨域

snail-boy commented 5 years ago

您应当在electron的主进程中设置webSecurity:false,来允许跨域请求,而不是在脚手架中配置代理达到跨域

const service = axios.create({ // baseURL: process.env.VUE_APP_BASE_API, // url = base url + request url baseURL: 'http://192.168.1.11:8092/test-web', withCredentials: true, // send cookies when cross-domain requests timeout: 15000, // request timeout headers: { 'content-type': 'application/json; charset=utf-8' } })

在这配 baseURL: 'http://192.168.1.11:8092/test-web'

const server = new WebpackDevServer( compiler, { contentBase: path.join(__dirname, '../'), quiet: true, before (app, ctx) { app.use(hotMiddleware) ctx.middleware.waitUntilValid(() => { resolve() }) }, proxy: { '*:': { target: http://172.16.123.71:19906/test-web, changeOrigin: true, secure: false, } } }

即可

lamking commented 4 years ago

@websmallrabbit 大佬 请教一下 你这做法相当于是起一个node进程作为转发 让前端页面请求到这个node 然后转发请求接口吗