- svn更新代码到本地 前端代码地址 http://svn.chinaedu.net/svn/zkzx/Develop/trunk/dev/web/
- 本地安装node
- 全局安装grunt npm install -g grunt-cli
- 切换到要更改的项目目录 本地安装node依赖包 npm install
- 启动grunt 命令行输入grunt
- 第一次启动时要运行grunt build
- 切换的web目录下进入生成的webcenter
- 复制一个server.js进去,并修改文件中的127.0.0.1 80 端口为8089
- 配置host 172.16.4.68 zkzx.chinaedu.net 127.0.0.1 static.zkzx.com
- 启动node server.js
- 前台访问 zkzx.chinaedu.net:8089
server.js内容
var http=require("http");
var url = require("url");
var fs = require("fs");
var libPath = require("path");
var virtualpath = 'web-public-static/'
function serverRole(req, res){
var req_path = url.parse(req.url).path.replace(virtualpath,'').replace(/\?.*$/,'');
var filepath = __dirname + req_path;
if (req_path.indexOf('/bbs/') == 0) {
filepath = 'F:/ChinaeduCloudStatic/branches/dev' + req_path;
}
var ext = libPath.extname(filepath);//返回文件的扩展名
var contentType = "";
switch(ext){
case ".html":
contentType= "text/html";
break;
case ".js":
contentType="text/javascript";
break;
case ".css":
contentType="text/css";
break;
case ".gif":
contentType="image/gif"
break;
case ".jpg":
contentType="image/jpeg";
break;
case ".png":
contentType="image/png";
break;
case ".ico":
contentType="image/icon";
break;
default:
contentType="application/octet-stream";
}
fs.exists(filepath, function(exists){
if(exists){
fs.stat(filepath, function(err, stats){//检查一个文件是否存在
if(err){
res.writeHead(500, {'Content-Type' : 'text/html;charset=utf8'});
res.end('<div styel="color:black;font-size:22px;">server error</div>');
}else{
if(stats.isFile()){
var file = fs.createReadStream(filepath);
res.writeHead(200, {'Content-Type' : contentType});
file.pipe(res);
}else{
fs.readdir(filepath, function(err, files){
var str = '';
for(var i in files){
str += files[i] + '<br/>';
}
res.writeHead(200, {'Content-Type' : 'text/html;charset=utf8'});
res.write(str);
});
}
}
});
}else{
res.writeHead(404, {'Content-Type' : 'text/html;charset=utf8'});
res.end('<div styel="color:black;font-size:22px;">404 not found</div>');
}
});
}
var server = http.createServer(serverRole);
var server2 = http.createServer(serverRole);
server.listen('8089', '127.0.0.1');//测试
server2.listen('1888','127.0.0.1');//开发 + bbs