JavaScript Node.js connect not serving images correctly

I am currently trying to write a very simple webserver using Node.js and connect, that basically just serves a single directory staticly.

var server = connect.createServer();
server.use(connect.logger());
server.use(connect.static(DOCUMENT_ROOT));
server.listen(SERVER_PORT);

This is basically working, I can connect to the server and its serving the index.html to me.

The problem occurs when I try to serve images (either in an html or by opening their url directly). They are served, but it seems not completely, yielding a result such as this:

connect image result

I looked into the headers, but can't find any obvious flaws. The correct content-size is there, the only thing I find rather strange is that the content-type seems to be missing, but it seems the browser figured it out correctly. Interestingly, if I serve the image manually, it works. So using this code the image is served correctly:

var server = connect.createServer();
server.use(connect.logger());

server.use(function(req, res, next) {
  console.log(req.url);

  if (req.url != "/testimage.png") {
    next();
    return;
  }

  var data = fs.readFileSync(DOCUMENT_ROOT + req.url);

  res.writeHead(200, {'Content-Type': 'image/png'});
  res.write(data);
  res.end();
});

server.use(connect.static(DOCUMENT_ROOT));
server.listen(SERVER_PORT);

Any ideas why serving the images with connect does not work? Since this is a rather small example I find it strange its not working... . Did I understand something wrong about connect?

Update

I tracked it down a little further. It seems to be an issue with the streaming component of the send module - it never stops streaming the file but repeats it endlessly. I think this might be related to me running Nodelike so I opened an issue at the Nodelike repo. If someone has an idea I'd still be glad

Answer:1

I'm trying to retrieve the TR element's ID, whenever the user removes focus from that TR. Triggering the event is easy enough, but I can't work out how best to retrieve the ID $(".row-identifying-...

I'm trying to retrieve the TR element's ID, whenever the user removes focus from that TR. Triggering the event is easy enough, but I can't work out how best to retrieve the ID $(".row-identifying-...

Am trying to use fitBounds to make all my markers visible with a proper zoom level. getBounds(){ return [[12.49637,41.90278],[12.319398,45.441906],[13.055054,47.809532],[16.373724,48.208244]] } &...

Am trying to use fitBounds to make all my markers visible with a proper zoom level. getBounds(){ return [[12.49637,41.90278],[12.319398,45.441906],[13.055054,47.809532],[16.373724,48.208244]] } &...

This seems fairly simple but I can't get this to run. I basically want to check if 'div class = balances' contains the text 'EUR' and if it does, I want to do other checks. It works when I use an ...

This seems fairly simple but I can't get this to run. I basically want to check if 'div class = balances' contains the text 'EUR' and if it does, I want to do other checks. It works when I use an ...

  1. if statement protractor element

I'm trying to remove a specific object when a property matches my parameter (Here when the name of the wheel is "Michelin") but I can't make it work... How could I do it ? var car = { type: "...

I'm trying to remove a specific object when a property matches my parameter (Here when the name of the wheel is "Michelin") but I can't make it work... How could I do it ? var car = { type: "...

  1. remove nested object javascript
  2. lodash remove nested object
  3. mongodb remove nested object
  4. mongoose remove nested object
  5. remove nested json object
  6. remove nested property from object javascript
  7. nested object remove