TypeError:无法读取属性' writeHead'未定义的节点js

时间:2016-01-29 02:19:29

标签: node.js

您好我在节点中运行真正的vanilla服务器并且此错误不断弹出,我甚至无法跟踪它,因为在我看来,没有任何可能出错的地方?

function send404(request, response) {
        response.writeHead(404, {'Content-Type': 'text/plain'});
        response.write('Error 404: resource not found. ');
        response.end();
    };

Server.js

var server = http.createServer(function (request, response) {
        var filePath = false;

        if (request.url === '/') {
            filePath = 'public/index.html';
        } else {
            filePath = 'public' + request.url;
        }
        var absPath = './' + filePath;
        serveStatic(response, cache, absPath);
        var filePath = false;

        if (request.url === '/' ) {
            filePath = 'public/index.html';
        } else {
            filePath = 'public' + request.url;
        }

        var absPath = './' + filePath;
        serveStatic(response, cache, absPath);
    });


    server.listen(3000, function() {
        console.log('Server listening on port 3000.');
    });

0 个答案:

没有答案