As usual, when this topic comes to the mailing list, there is a lot of 
talking and very little facts. Let's come back to the OP's code (and fix it 
a bit so that it also works when the path is *not* a symlink.

Here is how I implement it with streamline.js and express-streamline:

  CDN.use(config.CDN.baseUrl, function(req, res, next, _) {
      var path = config.base + "/cdn" + req.url;
      if (fs.lstat(path, _).isSymbolicLink()) path = fs.readlink(path, _); 
      res.writeHead(200, { "Content-type" : "text/html" }); 
      res.end( fs.readFile(path, _));
  });

Here is the "rule" behind it (in plain English)

If the request is a CDN URL do
  if the path corresponds to a symbolic link resolve the symbolic link
  write a 200 status and a text.html content-type
  write the file to the response


How do you implement it with async? with promises? with event emitters? 
How close it your code to the plain English rule? 
Does it matter? for the person who writes the code? for the person who will 
read this code? for the person who will modify the code 6 months later? 
How does it perform? 
How robust is it? What response (if any) will you get if the file does not 
exist, if someone makes a change and introduces a bug like a null 
dereference? 
...

-- 
Job board: http://jobs.nodejs.org/
New group rules: 
https://gist.github.com/othiym23/9886289#file-moderation-policy-md
Old group rules: 
https://github.com/joyent/node/wiki/Mailing-List-Posting-Guidelines
--- 
You received this message because you are subscribed to the Google Groups 
"nodejs" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to nodejs+unsubscr...@googlegroups.com.
To post to this group, send email to nodejs@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/nodejs/bbf24c11-db1b-4b3e-88b8-3853702a3099%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to