Node.js server “404 not found” message to 404.html page

前端 未结 5 1647
南旧
南旧 2021-01-04 16:50

Im working with node.js and I would like to know how to display a 404.html instead of a \"404 Not Found\" message.

This is my server.js:

var http = r         


        
5条回答
  •  醉梦人生
    2021-01-04 17:19

    This might be more of what you're looking for.

        fs.readFile('404.html', function(error, data) {
            res.writeHead(404, {'content-type': 'text/html'});
            res.end(data);
        });
    

提交回复
热议问题