代码拉取完成,页面将自动刷新
var http = require('http');
var url = require('url');
var fs = require('fs');
var server = http.createServer(function(request, response){
response.charset = 'utf-8';
var t = new Date();
var pathname = url.parse(request.url).pathname;
var realPath = '.'+pathname;
if(realPath.length<=2){
realPath = './index.html';
}
fs.exists(realPath, function (exists) {
if (!exists) {
response.writeHead(404, {
'Content-Type': 'text/plain'
});
response.write("This request URL " + pathname + " was not found on this server.");
response.end();
} else {
fs.readFile(realPath, "binary", function (err, file) {
if (err) {
response.writeHead(500, {
'Content-Type': 'text/plain'
});
response.end(err);
} else {
if(realPath.indexOf('.js')!=-1){
response.writeHead(200, {'Content-Type': 'text/javascript'});
}else if(realPath.indexOf('.css')!=-1){
response.writeHead(200, {'Content-Type': 'text/css'});
}else if (realPath.indexOf('.html')!=-1) {
response.writeHead(200, {'Content-Type': 'text/html'});
}else{
response.writeHead(200, {'Content-Type': 'text/plain'});
};
response.write(file, "binary");
response.end();
}
});
}
});
console.log('['+t.toLocaleString()+']'+pathname);
});
server.listen(8080);
console.log("server start up at http://localhost:8080\n");
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。