const express = require('express'),
      router = express.Router(),
      fs = require('fs'),
      path = require('path'),
      grid = require('gridfs-stream');

const db = require('../lib/db'),
      mongoose = db.goose,
      conn = db.rope;

grid.mongo = mongoose.mongo;

router.get('/', function(req, res) {

  const name = path.basename(req.originalUrl),
        gfs = grid(conn.db);

  const query = {
    filename: name,
    root: 'media'
  }

  function sendFile() {
    const stream = gfs.createReadStream(query);

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

    stream.pipe(res);
  }

  gfs.exist(query, function(err, found) {
    if (err) {
      throw err;
    }
    found ? sendFile() : res.send('File doesn\'t exist!');
  });

});

module.exports = router;

@@ -467,24 +467,25 @@
 endFile() %7B%0A
+%0A
     const st
@@ -517,24 +517,117 @@
 am(query);%0A%0A
+    gfs.findOne(query, function(err, meta) %7B%0A%0A      if (err) %7B%0A        throw err;%0A      %7D%0A%0A  
     res.writ
@@ -647,16 +647,18 @@
         
+  
 'Content
@@ -669,20 +669,68 @@
 e': 
-'image/png'%0A
+meta.contentType,%0A          'Content-Length': meta.length%0A  
     
@@ -738,16 +738,18 @@
 );%0A%0A    
+ 
+ 
 stream.p
@@ -758,16 +758,25 @@
 e(res);%0A
+    %7D);%0A%0A
   %7D%0A%0A  g

Set correct headings for file responses