-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathutils.js
38 lines (37 loc) · 927 Bytes
/
utils.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
/* Helper function for getting a resource's (file) content-type */
exports.getContentType = function getContentType (resource) {
const resourceSplit = resource.split('.')
const extension = resource === '/' ? 'html' : resourceSplit[resourceSplit.length - 1]
let contentType
switch (extension) {
case 'html':
contentType = 'text/html'
break;
case 'js':
contentType = "text/javascript"
break;
case 'json':
contentType = "application/json"
break;
case 'css':
contentType = "text/css"
break;
case 'css':
contentType = "text/css"
break;
case 'jpg':
case 'jpeg':
contentType = "image/jpeg"
break;
case 'png':
contentType = "image/png"
break;
case 'svg':
contentType = "image/svg+xml"
break;
default:
contentType = "application/octet-stream"
break;
}
return contentType
}