From 5aa8432d9619b7f8d06ed8d3da003b07796064ef Mon Sep 17 00:00:00 2001 From: Matheus Fernandes Date: Wed, 19 Oct 2016 03:42:56 -0200 Subject: [PATCH] `mime` => `mime-types` --- bin/list | 12 ++++-------- package.json | 2 +- 2 files changed, 5 insertions(+), 9 deletions(-) diff --git a/bin/list b/bin/list index c62f803e..ef42ad21 100644 --- a/bin/list +++ b/bin/list @@ -12,7 +12,7 @@ import args from 'args' import {compile} from 'handlebars' import {isBinarySync as isBinary} from 'istextorbinary' import filesize from 'filesize' -import mime from 'mime' +import mime from 'mime-types' import compress from 'micro-compress' import fs from 'fs-promise' @@ -184,7 +184,7 @@ const handler = async (req, res) => { return send(res, 404, 'Not found') } - res.setHeader('Content-Type', mime.lookup(indexPath) + '; charset=utf-8') + res.setHeader('Content-Type', mime.contentType(path.extname(indexPath))) if (!fs.existsSync(indexPath)) { // Try to render the current directory's content @@ -259,13 +259,9 @@ const handler = async (req, res) => { res.end(body, 'binary') } else { const decoder = new StringDecoder('utf8') - let contentType = mime.lookup(related) + const contentType = mime.contentType(path.extname(related)) || mime.contentType('text') - if (!path.parse(related).ext) { - contentType = 'text/plain' - } - - res.setHeader('Content-Type', contentType + '; charset=utf-8') + res.setHeader('Content-Type', contentType) send(res, statusCode, decoder.write(body)) } } diff --git a/package.json b/package.json index 77d95ceb..9c17a8b8 100644 --- a/package.json +++ b/package.json @@ -63,6 +63,6 @@ "istextorbinary": "2.1.0", "micro": "6.1.0", "micro-compress": "1.0.0", - "mime": "1.3.4" + "mime-types": "^2.1.12" } }