我一直在用头撞墙试图找出这段代码出了什么问题。我直接从node-static github存储库示例中复制了它,但它似乎不起作用。我所做的唯一修改是公共文件的路径(以前是“./public”)。在我的公共文件夹中,我有一个index.html,但是当我点击http://localhost:8080/index.html
我什么也没得到。
var static = require('node-static');
//
// Create a node-static server instance to serve the './public' folder
//
var file = new(static.Server)('C:\Projects\node\public');
require('http').createServer(function (request, response) {
request.addListener('end', function () {
//
// Serve files!
//
file.serve(request, response);
});
}).listen(8080);
如果重要的话,我在 Windows 7 64 位上运行 Node.js。
Edit:
我扔了一些console.log
语句并将其放入服务器处理程序中,但不放入侦听器处理程序中。这是否与“结束”事件有关?
我删除了request.addListener('end', ...)
功能:
require('http').createServer(function (request, response) {
//
// Serve files!
//
file.serve(request, response);
}).listen(8080);
现在效果很好。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)