Closed giovanni-bertoncelli closed 1 year ago
Hello, and sorry you are having an issue. It should be there. I tried really quick to put together an example app using the code snippet you provided and I was unable to reproduce your issue. Can you either modify the below code and then detail how to call it where it does not return a content-type
header, or provide your code fully-runnable code and instructions on how to reproduce? We would be happy to diagnose and address the issue, but just are unable to reproduce with the given information.
var finalhandler = require('finalhandler')
var http = require('http')
var serveStatic = require('serve-static')
var serve = serveStatic('./public', { index: 'index.html' })
var server = http.createServer(function onRequest (req, res) {
serve(req, res, finalhandler(req, res))
})
server.listen(3000)
$ ls public/
index.html
$ curl -i http://localhost:3000/
HTTP/1.1 200 OK
Accept-Ranges: bytes
Cache-Control: public, max-age=0
Last-Modified: Wed, 15 Feb 2023 17:01:10 GMT
ETag: W/"0-1865605dec6"
Content-Type: text/html; charset=UTF-8
Content-Length: 0
Date: Wed, 15 Feb 2023 17:02:26 GMT
Connection: keep-alive
Keep-Alive: timeout=5
Thank you for the quick response @dougwilson , I think I've mistaken with some other static content served by my server.
Hi, I'm using this middleware in order to serve static files. My configuration is something like this:
But when navigating on the root, since I have the
X-Content-Type-Options: nosniff
header enabled, I've noticied that theindex.html
file is returned without theContent-type
header, so the HTML get not rendered by the browser:I think that header should be present, shouldn't it?