1 | 'use strict'
|
2 |
|
3 | let mime
|
4 |
|
5 | try {
|
6 | mime = require('mime')
|
7 | } catch (e) {}
|
8 |
|
9 | const app = 'application'
|
10 | const html = 'text/html'
|
11 | const jpeg = 'image/jpeg'
|
12 | const text = 'text/plain'
|
13 |
|
14 | const types = {
|
15 | bin: `${app}/octet-stream`,
|
16 | css: 'text/css',
|
17 | gif: 'image/gif',
|
18 | html,
|
19 | htm: html,
|
20 | jpeg,
|
21 | jpg: jpeg,
|
22 | js: `${app}/javascript`,
|
23 | pdf: `${app}/pdf`,
|
24 | png: 'image/png',
|
25 | svg: 'image/svg+xml',
|
26 | text,
|
27 | txt: text,
|
28 | xml: `${app}/xml`
|
29 | }
|
30 |
|
31 | module.exports = mime || {
|
32 | getType: extension => {
|
33 | if (extension.charAt(0) === '.') {
|
34 | extension = extension.substring(1)
|
35 | }
|
36 | return types[extension] || types.bin
|
37 | }
|
38 | }
|