Skip to content

Commit c26880d

Browse files
committed
Hotfix: Fix content-type header casing
Also some minor cleanup
1 parent 0eb4c29 commit c26880d

File tree

1 file changed

+12
-11
lines changed

1 file changed

+12
-11
lines changed

src/server.js

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -26,17 +26,18 @@ class StaticServer {
2626
const ext = path.extname(req.url)
2727
const filepath = ext === HTML_EXT ? path.join(basePath, req.url) : path.join(basePath, publishDir, req.url)
2828

29-
res.writeHead(200, { 'Content-type': MIME_TYPES[ext] || 'text/plain' })
30-
const stream = fs.createReadStream(filepath, { encoding: 'utf-8' })
31-
32-
stream.on('open', function () {
33-
stream.pipe(res)
34-
})
35-
36-
stream.on('error', function (err) {
37-
res.statusCode = 500
38-
res.end(`Error getting the file: ${err}.`)
39-
})
29+
res.writeHead(200, { 'Content-Type': MIME_TYPES[ext] || 'text/plain' })
30+
31+
const stream = fs.createReadStream(filepath)
32+
33+
stream
34+
.on('open', function () {
35+
stream.pipe(res)
36+
})
37+
.on('error', function (err) {
38+
res.statusCode = 500
39+
res.end(`Error getting the file: ${err}.`)
40+
})
4041

4142
res.on('close', function () {
4243
stream.destroy()

0 commit comments

Comments
 (0)