Thursday, April 14, 2016

Webpack-dev-server not sending requests to external domain via proxy

Leave a Comment

I'm trying to use the webpack-dev-server proxy configuration to send api requests to an external domain and I can't seem to get it working.

Here's my config:

var path = require('path')  module.exports = {     entry: './client/index.js',     output: {         filename: 'bundle.js',         path: path.resolve(__dirname, 'public/assets'),         publicPath: 'assets'     },     devServer: {         contentBase: 'public',         proxy:{             '/api/v1*': {                 target: 'http://laravelandwebpack.demo/',                 secure: false             }         }     } } 

So, anytime my app makes a request with the uri /api/v1... it should send that request to http://laravelandwebpack.demo.

In my Vue app, I'm using the vue-resource to make the requests and I'm defaulting all requests with the needed uri prefix:

var Vue = require('vue') Vue.use(require('vue-resource'))  new Vue({     el: 'body',     http: {         root: '/api/v1', // prefix all requests with this         headers:{             test: 'testheader'         }     },     ready: function (){         this.$http({             url: 'tasks',             method: 'GET'         }).then(function (response){             console.log(response);         }, function (response){             console.error(response);         })     } }) 

The URL's are being constructed correctly, but they're still pointing to localhost:8080 which is the webpack-dev-server:

Errant http request

I read and re-read the docs for webpack-dev-server and I can't figure out where I have it set up wrong. Any ideas?

0 Answers

If You Enjoyed This, Take 5 Seconds To Share It

0 comments:

Post a Comment