I'm trying to check what the type of content is, but it doesn't appear to be working. Here is the output on the shell:
$ node app.js
# Request http://localhost:3000 via browser
CLIENT DOES NOT WANT XML, JSON, OR HTML
text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8
And here is the contents of the app.js script:
var express = require('express');
var app = express.createServer();
app.get('/', function(req, res) {
if (req.is('xml')) {
console.log("CLIENT WANTS XML");
} else if (req.is('json') || req.is('html')) {
console.log("CLIENT WANTS JSON OR HTML");
} else {
console.log("CLIENT DOES NOT WANT XML, JSON, OR HTML");
console.log(req.header('Accept'));
}
});
app.listen(3000);
I would expect the text/html
Accept header to trigger the req.is('html')
function or even the application/xhtml+xml
Accept header to trigger the req.is('xml')
, but the else
statement actually gets run. I'm using Express 3.0.0 rc1 and Node 0.8.1.
Turns out I should be using .accepts()
, instead of .is()
.