Skip to content

Localhost no longer works for devServer proxy. #4828

@Spedwards

Description

@Spedwards

Bug report

Dev Server proxy targets no longer accept localhost as a valid option. After upgrading to v4, I have had to switch from localhost to 127.0.0.1 which is the same thing so it makes no sense.

There was nothing about this included in the v4 migration post which leads me to believe this is a bug.

Actual Behaviour

When making HTTP requests (through axios) to my server backend, I get proxy errors. These are the exact same errors I get when the server isn't even running. Upon switching the target to 127.0.0.1, it works.

Proxy error: Could not proxy request /api/v1/settings from localhost:8080 to http://localhost:3333.
See https://nodejs.org/api/errors.html#errors_common_system_errors for more information (ECONNREFUSED).

Expected Behaviour

I honestly don't know how to explain the expected behaviour as I'm not entirely sure why it's not working to begin with. HTTP requests should connect to the server and only throw this error if the server cannot be found. localhost and 127.0.0.1 are synonymous so working on one and not the other makes zero sense.

How Do We Reproduce?

I am using webpack-dev-server through vue-cli, but upon asking for help from them, I was informed that they pass these settings along to webpack and it's not handled by Vue. That said, here are my settings:

module.exports = {
	devServer: {
		proxy: {
			'/api': {
				target: 'http://127.0.0.1:3333',
			},
			'/uploads': {
				target: 'http://127.0.0.1:3333',
			},
		},
	},
}

I then have an Axios instance:

axios.create({ baseURL: '/api/v1', timeout: 3000 })

All HTTP requests go through that.

Please paste the results of npx webpack-cli info here, and mention other relevant information

$ npx webpack-cli info

  System:                                                     
    OS: Windows 10 10.0.19045                                 
    CPU: (8) x64 Intel(R) Core(TM) i7-9700K CPU @ 3.60GHz     
    Memory: 14.90 GB / 31.92 GB                               
  Binaries:                                                   
    Node: 18.16.0 - ~\.nvm\versions\node\v18.16.0\bin\node.EXE
    Yarn: 1.22.4 - C:\Program Files (x86)\Yarn\bin\yarn.CMD   
    npm: 9.5.1 - ~\.nvm\versions\node\v18.16.0\bin\npm.CMD    
  Browsers:                                                   
    Chrome: 112.0.5615.138                                    
    Edge: Spartan (44.19041.1266.0), Chromium (112.0.1722.48) 
    Internet Explorer: 11.0.19041.1566                        
  Packages:                                                   
    sass-loader: ^8.0.2 => 8.0.2 

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions