Skip to content

Proxy localhost:port -> subdomain.localhost:another_port doesn't work #256

@PetrShypila

Description

@PetrShypila

Expected behavior

I have two running dev servers on localhost. I need to proxy a request from localhost:4000 to subdomain.localhost:3000

Actual behavior

On server launch I receive:
[HPM] Proxy created: / -> http://agent.localhost:3000
On request I see following message in console:
[HPM] Error occurred while trying to proxy request /config from localhost:4000 to http://agent.localhost:3000 (ENOTFOUND) (https://nodejs.org/api/errors.html#errors_common_system_errors)
And in a browser I receive following 504 response:
Error occurred while trying to proxy to: localhost:4000/config

At the same time requesting that endpoint in Chrome works fine.

Setup

  • http-proxy-middleware: 0.18.0
  • server: express@4.16.2
  • webpack-dev-middleware@3.1.0

proxy middleware configuration

  app.use(require('webpack-dev-middleware')(compiler, {
    noInfo: true,
    publicPath: config.output.publicPath
  }));
  app.use(require('webpack-hot-middleware')(compiler));

  config.devServer.proxyConf.endpoints.forEach((endpoint) => {
    app.use(endpoint, proxy(config.devServer.proxyConf.config));
  });
  proxyConf: {
    endpoints: [
      "/config",
    ],
    config: {
      target: "http://agent.localhost:3000",
      secure: false,
      changeOrigin: true
    },
  }

server mounting

  app.listen(port, function (err) {
    if(err) {
      console.log(`Error during app launch: ${err.message}`.red);
    } else {
      console.log(`Server is listening on ${port}...`.green);
    }
  });

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions