如果我启动服务器并转到 localhost:4000,服务器会给出 index.html。但是 index.html 没有加载它的 style.css 并且没有连接到服务器。但是,如果我双击本地 index.html 文档,它会连接到服务器。我的回复有什么问题?
var app = require('http').createServer(handler)
, io = require('socket.io').listen(app)
, fs = require('fs')
app.listen(4000);
function handler (req, res) {
fs.readFile(__dirname + '/public/index.html',
function (err, data) {
if (err) {
res.writeHead(500);
return res.end('Error loading index.html');
}
res.writeHead(200);
res.end(data);
});
}
io.sockets.on('connection', function (socket) {...}
索引.html
<!DOCTYPE HTML>
<html>
<head>
<link rel="stylesheet",type="text/css" href="styles.css"/>
<script type="text/javascript" src="node_modules/socket.io/node_modules/socket.io-client/dist/socket.io.js">></script>
<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.8.2/jquery.min.js"></script>
</head>
<body>
<script>
var socket = io.connect('http://localhost:4000');
socket.on('connect', function(){...}