Skip to content

Commit fae50ba

Browse files
author
Andrey
committed
Refactored code into modules.
1 parent 70b1024 commit fae50ba

File tree

2 files changed

+20
-20
lines changed

2 files changed

+20
-20
lines changed

index.js

Lines changed: 1 addition & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -2,28 +2,9 @@ const http = require('http');
22
const url = require('url');
33
const fs = require('fs');
44
const path = require('path');
5+
const mimeType = require('./modules/mimeType');
56
const port = 9000;
67

7-
// maps file extention to MIME types
8-
// full list can be found here: https://www.freeformatter.com/mime-types-list.html
9-
const mimeType = {
10-
'.ico': 'image/x-icon',
11-
'.html': 'text/html',
12-
'.js': 'text/javascript',
13-
'.json': 'application/json',
14-
'.css': 'text/css',
15-
'.png': 'image/png',
16-
'.jpg': 'image/jpeg',
17-
'.wav': 'audio/wav',
18-
'.mp3': 'audio/mpeg',
19-
'.svg': 'image/svg+xml',
20-
'.pdf': 'application/pdf',
21-
'.zip': 'application/zip',
22-
'.doc': 'application/msword',
23-
'.eot': 'application/vnd.ms-fontobject',
24-
'.ttf': 'application/x-font-ttf',
25-
};
26-
278
http
289
.createServer(function (req, res) {
2910
console.log(`${req.method} ${req.url}`);

modules/mimeType.js

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
// maps file extention to MIME types
2+
// full list can be found here: https://www.freeformatter.com/mime-types-list.html
3+
module.exports = mimeType = {
4+
'.ico': 'image/x-icon',
5+
'.html': 'text/html',
6+
'.js': 'text/javascript',
7+
'.json': 'application/json',
8+
'.css': 'text/css',
9+
'.png': 'image/png',
10+
'.jpg': 'image/jpeg',
11+
'.wav': 'audio/wav',
12+
'.mp3': 'audio/mpeg',
13+
'.svg': 'image/svg+xml',
14+
'.pdf': 'application/pdf',
15+
'.zip': 'application/zip',
16+
'.doc': 'application/msword',
17+
'.eot': 'application/vnd.ms-fontobject',
18+
'.ttf': 'application/x-font-ttf',
19+
};

0 commit comments

Comments
 (0)