Ai
8 Star 9 Fork 2

cloudfroster/lessAnimate

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
node.js 1.57 KB
一键复制 编辑 原始数据 按行查看 历史
cloudfroster 提交于 2015-04-05 14:36 +08:00 . update
var port = (process.env.VMC_APP_PORT || process.env.PORT 3000);
var host = (process.env.VCAP_APP_HOST || process.env.IP || 'localhost');
var http = require('http');
var url = require('url');
var path = require('path');
var fs = require('fs');
var mime = require("./server/mime").types;
var serverRoot = 'server/index.html';
var server = http.createServer(function (request, response) {
var pathname = url.parse(request.url).pathname;
var realPath = 'server' + pathname;
if(realPath == 'server/') realPath = serverRoot;
var ext = path.extname(realPath);
ext = ext ? ext.slice(1) : 'unknown';
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 {
var contentType = mime[ext] || "text/plain";
response.writeHead(200, {'Content-Type': contentType});
response.write(file, "binary");
response.end();
response.write(file, "binary");
response.end();
}
});
}
});
});
server.listen(port, host);
console.log('server run at:' + host + ':' + port);
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
CSS
1
https://gitee.com/marchen/lessAnimate.git
git@gitee.com:marchen/lessAnimate.git
marchen
lessAnimate
lessAnimate
master

搜索帮助