webpack-dev-server icon indicating copy to clipboard operation
webpack-dev-server copied to clipboard

HTTP HEAD request results in 404

Open reiner-dolp opened this issue 9 years ago • 7 comments

Do you want to request a feature or report a bug? Bug.

What is the current behavior? HTTP HEAD method requests result in a 404: Not Found even though the resource exists and is retrievable using HTTP GET.

If the current behavior is a bug, please provide the steps to reproduce. Compile using webpack and request any file:

$> curl -I http://localhost:8080/index.html 
HTTP/1.1 404 Not Found
X-Powered-By: Express
Content-Security-Policy: default-src 'self'
X-Content-Type-Options: nosniff
Content-Type: text/html; charset=utf-8
Content-Length: 158
Date: Sun, 28 May 2017 09:35:14 GMT
Connection: keep-alive
$> curl -G http://localhost:8080/index.html
<h1>works</h1>

Please mention your webpack and Operating System version. Tested on Windows 10 with dev server 2.4.5 and webpack 2.6.1

reiner-dolp avatar May 28 '17 09:05 reiner-dolp

you can go with this code of proxy:

'/my_url/**': {
  target: config.targetLocal,
  bypass: (req) => {
    req.method = 'GET'; 
  },
},

Opty1712 avatar Jul 07 '17 07:07 Opty1712

You can use the proxy method, or you'll have to extend the middleware to handle HEAD requests. At present it only supports GET. You can view some of the setup for that here. I think this would be a little too edge case to make it a permanent part of WDS.

shellscape avatar Aug 09 '17 15:08 shellscape

Why this is closed? It is a normal use case to check etag with HEAD request. This req.method = 'GET'; is just unneeded hacking.

alzuma avatar Dec 05 '18 08:12 alzuma

@shellscape It's also a common use-case to use a HEAD request to check whether the server is running. Can you please reopen?

Example: https://github.com/sindresorhus/wait-for-localhost/blob/master/index.js

sindresorhus avatar Jan 11 '19 09:01 sindresorhus

+1 Please add support for HEAD method requests as it is a common HTTP Method to use instead of GET when only the headers are needed.

Jaans avatar Mar 21 '19 02:03 Jaans

Also critical is using method HEAD for checking if the css file exists: https://github.com/addyosmani/critical/blob/master/src/file.js#L115

FYI @addyosmani @bezoerb

HenriqueLimas avatar Apr 12 '19 09:04 HenriqueLimas

Continued in https://github.com/webpack/webpack-dev-server/issues/1833.

sindresorhus avatar Apr 30 '19 14:04 sindresorhus