代码拉取完成,页面将自动刷新
var PORT = 8888;
var url = require("url");
var http = require("http");
var path = require("path");
var fs = require('fs');
var config = require("./config.js");
var cache = require("./cache.js");
var mime = require("./mime").types;
var crypto = require('crypto');
var server = http.createServer(function (request, response) {
var pathname = url.parse(request.url).pathname;
var realPath = "assets" + pathname;
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 {
var ext = path.extname(realPath);
ext = ext ? ext.slice(1) : 'unknown';
var contentType = mime[ext] || "text/plain";
cache(request, response, next);
function next() {
fs.readFile(realPath, "binary", function (err, file) {
console.log(new Date(), ":----read file-----");
if (err) {
response.writeHead(500, { 'Content-Type': contentType });
response.end(err);
} else {
response.writeHead(200, {
'Content-Type': contentType,
});
response.write(file, "binary");
response.end();
}
});
}
}
});
});
server.listen(PORT);
console.log("Server runing at port: " + PORT + ".");
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。