| 432 | } |
| 433 | |
| 434 | getFileContentType(filepath, res) { |
| 435 | let contentType = res.getHeader("Content-Type"); |
| 436 | |
| 437 | // Content-Type might be already set via middleware |
| 438 | if (contentType) { |
| 439 | return contentType; |
| 440 | } |
| 441 | |
| 442 | let mimeType = mime.getType(filepath); |
| 443 | if (!mimeType) { |
| 444 | return; |
| 445 | } |
| 446 | |
| 447 | contentType = mimeType; |
| 448 | |
| 449 | // We only want to append charset if the header is not already set |
| 450 | if (contentType === "text/html") { |
| 451 | contentType = `text/html; charset=${this.options.encoding}`; |
| 452 | } |
| 453 | |
| 454 | return contentType; |
| 455 | } |
| 456 | |
| 457 | renderFile(filepath, res) { |
| 458 | let contents = fs.readFileSync(filepath); |