2013-06-30 34 views
0

我想用raphael.js脚本在里面使用node.js服务HTML页面。服务Raphael.js脚本的Node.js

我的index.html文件是:

<!DOCTYPE html> 
<head> 
<title>Raphael testing html</title>  
<script src="raphael-min.js"></script> 
<script> 
    // Initialize container when document is loaded 
    window.onload = function() { 
     paper = Raphael(0, 0, 640, 720, "container"); 
     paper.circle(100,100,50).attr('fill','red'); 
    }; 
</script> 
</head> 
<body> 
<div id="container"></div> 
</body> 
</html> 

和我server.js文件是:

var httpServer = require('http'); 
var fs = require('fs'); 
var index = fs.readFileSync('index.html'); 

var httpServer = httpServer.createServer(function(request, response) { 
console.log((new Date()) + ' Received request for ' + request.url); 
response.writeHead(200, {'Content-Type': 'text/html'}); 
response.end(index); 
return; 
}); 

httpServer.listen(8080, function() {}); 

运行在浏览器中的index.html文件 - 工作正常(即平。一个圆圈)。然而,试图服务于这个使用节点时:

$ node server.js 

指着我的浏览器为localhost,当我没有圈:8080/ 相反,我在控制台中出现以下错误:

Resource interpreted as Script but transferred with MIME type text/html:   
"http://localhost:8080/raphael-min.js". localhost/:6 
Uncaught SyntaxError: Unexpected token < :8080/raphael-min.js:2 
Uncaught ReferenceError: Raphael is not defined localhost/:12 

什么时我做错了?

回答