-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
34 lines (28 loc) · 897 Bytes
/
index.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
const http = require('http');
const url = require('url');
const fs = require('fs');
const path = require('path');
const getMime = require('./mime').getMime;
http.createServer((req, res)=> {
let pathname = url.parse(req.url).pathname;
if(!pathname || pathname === '/'){
pathname = '/index.html';
}
console.log(pathname);
if(pathname != '/favicon.ico'){
fs.readFile('static'+ pathname, (err, data)=>{
if(err){
res.writeHead(404);
}else {
let extname = path.extname(pathname);
let mime = getMime(extname);
res.writeHead(200, {"Content-Type":mime+";charset='utf-8'"});
res.write(data);
}
res.end();
});
}else{
res.end();
}
}).listen(8585);
console.log('Server is running at http://localhost:8585');