question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

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

See original GitHub issue

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);
    }
  });

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:6 (1 by maintainers)

github_iconTop GitHub Comments

3reactions
a-typecommented, Jul 31, 2019

I’ve hit this as well. My path is correct for the target server. I can hit the same endpoint in Chrome (admin.localhost:8080), but the proxy middleware will not route it.

Update: I needed to add admin.localhost to my hosts file pointed to 127.0.0.1.

0reactions
prem-prakashcommented, Mar 1, 2020

putting my local subdomains on hosts file solved the issue to me, not the best solution but ok

Read more comments on GitHub >

github_iconTop Results From Across the Web

How can I reroute a sub-domain to localhost + port number?
I'm running IIS alongside Python development server. There are several server processes of different kinds. – urig. Jun 24, 2011 at 16:31.
Read more >
Resolving subdomain.localhost doesn't work with docker swarm
What is the problem: can't get to container via subdomain. It works if I use port though; curl gives different results for subdomain...
Read more >
Automatically forward subdomain to port on localhost - Help
I'm working with a microservices architecture and often have to spin up multiple front-ends running on different ports, the above config is ...
Read more >
Usage - code-server v4.8.0 docs - Coder
If you're working on web services and want to access them locally, code-server can proxy to any port using either a subdomain or...
Read more >
Proxy - Lando Docs
You can also tell Lando to scan additional ports with the moreHttpPorts key ... to health scan a localhost https address that doesn't...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found