問題は、リクエストにサービスを提供している、あなたのバックエンドのコードではなく、フロントエンドです。
var app = http.createServer(function(req, res) {
res.writeHead(200, {
'Content-type': 'text/html'
});
res.end(index);
});
このコードはjs
とcss
ファイルを含むすべての要求のために実行されます。したがって、js
リクエストにindex.html
という内容が表示されます。したがって、JavaScriptエンジンでは、html
<
タグを含むファイルの解析中にエラーが表示されます。
解決策は、特定のルートを定義することです。
var http = require('http'),
fs = require('fs'),
path = require('path'),
express= require('express'),
index = fs.readFileSync(__dirname + '/index.html');
var app = express();
var server = require('http').Server(app);
var io = require('socket.io')(server);
app.use('/bower_components', express.static('bower_components'));
app.get('/', function(req, res){
res.writeHead(200, {
'Content-type': 'text/html'
});
res.end(index);
});
server.listen(3000, function() {
console.log('Server listening on port 3000');
});