Skip to content

Commit 3cf01cf

Browse files
committed
WF-519 Review web server pipeline
1 parent 637b43b commit 3cf01cf

File tree

1 file changed

+24
-30
lines changed

1 file changed

+24
-30
lines changed

lib.mjs

+24-30
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,29 @@ const {
1919
HTTP_STATUS_OK,
2020
} = H2;
2121

22+
const MIME = {
23+
'bin': 'application/octet-stream',
24+
'css': 'text/css',
25+
'gif': 'image/gif',
26+
'htm': 'text/html',
27+
'html': 'text/html',
28+
'ico': 'image/vnd.microsoft.icon',
29+
'jpeg': 'image/jpeg',
30+
'jpg': 'image/jpeg',
31+
'js': 'text/javascript',
32+
'json': 'application/json',
33+
'mjs': 'text/javascript',
34+
'mp3': 'audio/mpeg',
35+
'mp4': 'video/mp4',
36+
'pdf': 'application/pdf',
37+
'png': 'image/png',
38+
'svg': 'image/svg+xml',
39+
'txt': 'text/plain',
40+
'woff': 'font/woff',
41+
'woff2': 'font/woff2',
42+
'xml': 'text/xml',
43+
};
44+
2245
const FILE_ICON = 'favicon.ico';
2346
const FILE_INDEX = 'index.html';
2447
const HEAD_FILENAME = 'upload-filename'; // HTTP header to get uploading filename
@@ -38,36 +61,7 @@ const WEB_ROOT = getWebRoot(); // path to './pub/' folder
3861
function getMimeType(filename) {
3962
const ext = filename.substring(filename.lastIndexOf(".") + 1);
4063
const norm = (typeof ext === 'string') ? ext.toLowerCase() : null;
41-
switch (norm) {
42-
case 'css':
43-
return 'text/css';
44-
case 'htm':
45-
case 'html':
46-
return 'text/html';
47-
case 'ico':
48-
return 'image/vnd.microsoft.icon';
49-
case 'jpeg':
50-
case 'jpg':
51-
return 'image/jpeg';
52-
case 'js':
53-
case 'mjs':
54-
return 'text/javascript';
55-
case 'json':
56-
return 'application/json';
57-
case 'mp3':
58-
return 'audio/mpeg';
59-
case 'mp4':
60-
return 'video/mp4';
61-
case 'pdf':
62-
return 'application/pdf';
63-
case 'png':
64-
return 'image/png';
65-
case 'txt':
66-
return 'text/plain';
67-
case 'xml':
68-
return 'text/xml';
69-
}
70-
return 'application/octet-stream';
64+
return MIME[norm] ?? MIME['bin'];
7165
}
7266

7367
/**

0 commit comments

Comments
 (0)