title: Conditional serving of web pages based on "Accept" header with express?
body: <p>I understand that you can serve static content over express with: </p>
  
  <pre><code>app.use(express.static(__dirname + "../../../public_html"));
  </code></pre>
  
  <p>However, I'm trying to have express change the presentation of the content it delivers based upon the "Accept" header the the response sends over.  Normally, the content that I have is requested in a JSON format through a REST API so the url is: <code>http://blah.com/this/that/item</code> and that works well.</p>
  
  <p>However, I would also like for users to be able to access that same page from a browser which would send over something like: <code>Accept:text/html</code> and because of that header, see a page with correct formatting (CSS/JS/HTML/etc) to present the same information.</p>
  
  <p>Right now, I'm trying to serve the content through:</p>
  
  <pre><code>if (req.accepts("text/html")) {
     res.sendfile("/", {
        root: "../../../public_html"
     });
     res.status(200);
     return;
  }
  </code></pre>
  
  <p>Where <code>public_html</code> holds <code>index.html</code> and the relative directories with the CSS and JS.  I won't send that file whenever this is finished, but I figured it would be a good start and then add the JSON content after I figured out how to serve static content based on the Accept header.</p>
  
  <p>Is there a better way to do this?</p>