node.js を使用して内部に raphael.js スクリプトを含む HTML ページを提供しようとしています。
私の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
私は何を間違っていますか?