oblador / esbuild-server

Fast, lightweight and powerful development server for esbuild
MIT License
37 stars 5 forks source link

Error for requests with extensions not covered by mime.ts #2

Closed daradermody closed 1 year ago

daradermody commented 2 years ago

When I manually send a request in my browser or using curl to /favicon.ico, I get the following error:

node:internal/errors:477
    ErrorCaptureStackTrace(err);
    ^

TypeError [ERR_HTTP_INVALID_HEADER_VALUE]: Invalid value "undefined" for header "Content-Type"
    at storeHeader (node:_http_outgoing:532:5)
    at processHeader (node:_http_outgoing:527:3)
    at ServerResponse._storeHeader (node:_http_outgoing:421:11)
    at ServerResponse.writeHead (node:_http_server:370:8)
    at sendFile (/home/dara/git/OverDB/packages/frontend/node_modules/esbuild-server/dist/index.js:126:17)
    at async Server.<anonymous> (/home/dara/git/OverDB/packages/frontend/node_modules/esbuild-server/dist/index.js:178:28) {
  code: 'ERR_HTTP_INVALID_HEADER_VALUE'
}

This is due to the file extension (.ico) not being specified in mime.ts, and an undefined value being passed into res.writeHead.

If you're accepting PRs, I can make a fix that doesn't set Content-Type if it can't be determined. Another change I'd like to make is using the robust mime library for determining mime type for a much larger number of file extensions (including .ico).