socket.io and differents folders — solution found

前端 未结 5 1489
轮回少年
轮回少年 2020-12-18 09:39

I\'m new to socket.io and i already have a problem, minor i think. I have installed node.js properly and socket.io too with npm. Then just for testing i cut and paste a sam

5条回答
  •  时光取名叫无心
    2020-12-18 10:16

    Only that solves:

    function handler (request, response) {
        var file = __dirname + (request.url == '/' ? '/index.html' : request.url);
        fs.readFile(file, function(error, data) {
            if (error) {
                response.writeHead(500);
                return response.end('Error loading index.html');
            }
            response.writeHead(200);
            response.end(data, 'utf-8');
        });
    }
    

提交回复
热议问题