Serve .flow files as text/plain

This commit is contained in:
MICHAEL JACKSON 2017-08-12 20:37:29 -07:00
parent e4f5bfe4c0
commit db53a296aa
2 changed files with 13 additions and 6 deletions

View File

@ -8,17 +8,19 @@ mime.define({
'changes',
'authors',
'makefile',
'ts'
'ts',
'flow'
]
})
const TextFiles = /\/?(\.[a-z]*rc|\.git[a-z]*|\.[a-z]*ignore)$/i
const getContentType = (file) =>
TextFiles.test(file) ? 'text/plain' : mime.lookup(file)
function getContentType(file) {
return TextFiles.test(file) ? 'text/plain' : mime.lookup(file)
}
const getStats = (file) =>
new Promise((resolve, reject) => {
function getStats(file) {
return new Promise((resolve, reject) => {
fs.lstat(file, (error, stats) => {
if (error) {
reject(error)
@ -27,8 +29,9 @@ const getStats = (file) =>
}
})
})
}
const getFileType = (stats) => {
function getFileType(stats) {
if (stats.isFile()) return 'file'
if (stats.isDirectory()) return 'directory'
if (stats.isBlockDevice()) return 'blockDevice'

View File

@ -28,3 +28,7 @@ it('gets a content type of text/plain for .ts files', () => {
expect(getContentType('app.ts')).toBe('text/plain')
expect(getContentType('app.d.ts')).toBe('text/plain')
})
it('gets a content type of text/plain for .flow files', () => {
expect(getContentType('app.js.flow')).toBe('text/plain')
})