egoist / vuepack

:package: A modern starter which uses Vue 2, Vuex, Vue-router and Webpack 2 (and even Electron)
http://vuepack.surge.sh
MIT License
2.43k stars 202 forks source link

Is it possible to proxy requests to backend with dev server? #141

Closed korjavin closed 7 years ago

korjavin commented 7 years ago

I read about that ability:

// config/index.js
module.exports = {
  // ...
  dev: {
    proxyTable: {
      // proxy all requests starting with /api to jsonplaceholder
      '/api': {
        target: 'http://jsonplaceholder.typicode.com',
        changeOrigin: true,
        pathRewrite: {
          '^/api': ''
        }
      }
    }
  }
}

It's what I needed, but I can't find a way to where I must put in in your template. Could you please help me?

egoist commented 7 years ago

where did you read this? there's no such option.

You could update https://github.com/egoist/vuepack/blob/master/template/build/server.js to use https://github.com/chimurai/http-proxy-middleware in order to use proxy

I will replace it with webpack-dev-server to make it support proxy out of the box.

egoist commented 7 years ago

Try the latest version, you can configure it at: https://github.com/egoist/vuepack/blob/master/template/build/config.js#L8

korjavin commented 7 years ago

Thank you a lot ! It solved my problem