I've been banging my head against the wall trying to figure out what's wrong with this code. I copied it directly from the node-static github repository example, but it doesn't seem to work. The only modification that I made was to the path of the public files (previously was './public'). In my public folder I have an index.html, but when I hit http://localhost:8080/index.html
I get nothing.
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);
If it matters, I'm running Node.js on Windows 7 64 bit.
Edit:
I threw in some console.log
statements and it makes it into the server handler, but not into the listener handler. Could this have something to do with the 'end' event?
I removed the request.addListener('end', ...)
function:
require('http').createServer(function (request, response) {
//
// Serve files!
//
file.serve(request, response);
}).listen(8080);
Now it works fine.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With