Webpack-dev-server: Proxy is extermely slow

Created on 23 Apr 2015  路  4Comments  路  Source: webpack/webpack-dev-server

I am using the proxy option to proxy API requests while using webpack-dev-server. The proxy is extremely slow, to the point where it's useless. I'm trying to test a type-ahead component, and proxying the API request is resulting in 5+ second response times.

webpack-dev-server: 1.8.2
node: 0.12.2

Request through proxy: 5.08 seconds
screen shot 2015-04-23 at 14 55 14

Request direct to API endpoint: 0.03 - 0.06 seconds
screen shot 2015-04-23 at 14 54 58

My webpack.config.js is below:

const webpack = require('webpack');
const path = require('path');
const config = require('config');
const hostname = config.get('dev_server_hostname');
const port = config.get('dev_server_port');

var pragmas = new webpack.DefinePlugin({
  __DEV__: 'true',
  __CANVAS_API_TOKEN__: JSON.stringify(config.get('api_token'))
});

module.exports = {
  devtool: 'eval',

  entry: [
    'webpack-dev-server/client?http://' + hostname + ':' + port,
    'webpack/hot/only-dev-server',
    './src/js/index.js',
  ],

  output: {
    filename: 'canvas_spaces.js',
    path: './dist',
    publicPath: 'http://' + hostname + ':' + port + '/dist/'
  },

  module: {
    loaders: [
      {
        test: /\.js$/,
        loaders: ['react-hot', 'babel-loader'],
        include: path.join(__dirname, 'src')
      },
      {
        test: /\.scss$/,
        loader: "style!css!sass"
      }
    ]
  },

  plugins: [
    pragmas,
    new webpack.HotModuleReplacementPlugin(),
    new webpack.NoErrorsPlugin(),
    new webpack.ProvidePlugin({
      'es6-promise': 'es6-promise',
      'fetch': 'imports?this=>global!exports?global.fetch!whatwg-fetch'
    })
  ],

  resolve: {
    extensions: ['', '.js', '.jsx'],
    root: __dirname + '/src/js'
  },

  devServer: {
    hot: true,
    host: hostname,
    port: port,
    historyApiFallback: true,
    proxy: {
      '/api/v1/*': config.get('api_proxy'),
      '/font/*': config.get('api_proxy'),
    }
  }
}

Most helpful comment

Never mind, this looks like it's a DNS-related problem. I'm proxying to a vagrant box; when I change to using its IP address everything is snappy.

All 4 comments

Never mind, this looks like it's a DNS-related problem. I'm proxying to a vagrant box; when I change to using its IP address everything is snappy.

I have the same issue, thanks for your finding, it helped me too.

Same issue experienced using recommend instructions with create-react-app. Thanks for sharing solution :)

Never mind, this looks like it's a DNS-related problem. I'm proxying to a vagrant box; when I change to using its IP address everything is snappy.

Thanks for sharing solution. It works

Was this page helpful?
0 / 5 - 0 ratings