代码拉取完成,页面将自动刷新
var commander = require('commander');
var fs = require('fs');
var path = require('path');
commander.
option('-p, --port <port>', 'Port to run on', Number).
parse(process.argv);
require('http').createServer(function (request, response) {
request.addListener('end', function() {
console.log(request.url);
// Backwards-compatible support for wordpress, because wordpress allows
// URLs like `/2013/06/06/61/` to map to the blog post `61`
if (request.url.length > 1 &&
request.url.charAt(request.url.length - 1) === '/') {
request.url = request.url.substr(0, request.url.length - 1);
}
if (request.url.indexOf('?') !== -1) {
request.url = request.url.substr(0, request.url.indexOf('?'));
}
// Defend against directory traversals
var p = path.join('./bin', request.url.replace('../', ''));
fs.stat(p, function(err, stats) {
if (err || !stats) {
response.writeHead(404, {
'Cache-Control': 'max-age=7200',
'Content-Type': 'text/plain'
});
return response.end("Not found");
}
if (stats.isFile()) {
var type = path.extname(p);
if (type === '.xml') {
type = 'application/xml'
}
response.writeHead(200, {
'Cache-Control': 'max-age=7200',
'Content-Type': type || 'text/html'
});
fs.createReadStream(p).pipe(response);
} else {
var indexPath = path.join(p, 'index');
fs.stat(indexPath, function(err, stats) {
if (err || !stats || !stats.isFile()) {
response.writeHead(404, {
'Cache-Control': 'max-age=7200',
'Content-Type': 'text/plain'
});
return response.end("Not found");
}
response.writeHead(200, {
'Cache-Control': 'max-age=7200',
'Content-Type': type || 'text/html'
});
fs.createReadStream(indexPath).pipe(response);
});
}
});
}).resume();
}).listen(process.env.TCB_PORT || commander.port || 8080);
console.log('Server listening on port ' + (process.env.TCB_PORT || commander.port || 8080));
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。