• 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内容

  1. var http=require("http");
  2. var url = require("url");
  3. var fs = require("fs");
  4. var libPath = require("path");
  5. var virtualpath = 'web-public-static/'
  6. function serverRole(req, res){
  7. var req_path = url.parse(req.url).path.replace(virtualpath,'').replace(/\?.*$/,'');
  8. var filepath = __dirname + req_path;
  9. if (req_path.indexOf('/bbs/') == 0) {
  10. filepath = 'F:/ChinaeduCloudStatic/branches/dev' + req_path;
  11. }
  12. var ext = libPath.extname(filepath);//返回文件的扩展名
  13. var contentType = "";
  14. switch(ext){
  15. case ".html":
  16. contentType= "text/html";
  17. break;
  18. case ".js":
  19. contentType="text/javascript";
  20. break;
  21. case ".css":
  22. contentType="text/css";
  23. break;
  24. case ".gif":
  25. contentType="image/gif"
  26. break;
  27. case ".jpg":
  28. contentType="image/jpeg";
  29. break;
  30. case ".png":
  31. contentType="image/png";
  32. break;
  33. case ".ico":
  34. contentType="image/icon";
  35. break;
  36. default:
  37. contentType="application/octet-stream";
  38. }
  39. fs.exists(filepath, function(exists){
  40. if(exists){
  41. fs.stat(filepath, function(err, stats){//检查一个文件是否存在
  42. if(err){
  43. res.writeHead(500, {'Content-Type' : 'text/html;charset=utf8'});
  44. res.end('<div styel="color:black;font-size:22px;">server error</div>');
  45. }else{
  46. if(stats.isFile()){
  47. var file = fs.createReadStream(filepath);
  48. res.writeHead(200, {'Content-Type' : contentType});
  49. file.pipe(res);
  50. }else{
  51. fs.readdir(filepath, function(err, files){
  52. var str = '';
  53. for(var i in files){
  54. str += files[i] + '<br/>';
  55. }
  56. res.writeHead(200, {'Content-Type' : 'text/html;charset=utf8'});
  57. res.write(str);
  58. });
  59. }
  60. }
  61. });
  62. }else{
  63. res.writeHead(404, {'Content-Type' : 'text/html;charset=utf8'});
  64. res.end('<div styel="color:black;font-size:22px;">404 not found</div>');
  65. }
  66. });
  67. }
  68. var server = http.createServer(serverRole);
  69. var server2 = http.createServer(serverRole);
  70. server.listen('8089', '127.0.0.1');//测试
  71. server2.listen('1888','127.0.0.1');//开发 + bbs