From 350b7ac055ed6374bde8bf49278c085f583c5781 Mon Sep 17 00:00:00 2001 From: Trygve Laugstøl Date: Mon, 2 Jul 2012 22:54:50 +0200 Subject: o Better conneg, defaulting to c+j unless text/html is requested. --- routes/index.js | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) (limited to 'routes') diff --git a/routes/index.js b/routes/index.js index 44feab4..ec57575 100644 --- a/routes/index.js +++ b/routes/index.js @@ -53,13 +53,15 @@ function after(res, callback) { } exports.index = function(req, res) { - if(req.accepts('html')) { + switch(req.accept.types.getBestMatch(["text/html", "application/vnd.collection+json"])) { + case "text/html": res.render('index', { title: 'Employee DB', urlgenerator: res.urlgenerator }); - } - else { + break; + case "application/vnd.collection+json": + default: var c = {collection: { links: [ { rel: 'departments', @@ -73,6 +75,7 @@ exports.index = function(req, res) { }}; res.contentType('application/vnd.collection+json'); res.send(JSON.stringify(collection_json.fromObject(c)), 200); + break; } }; -- cgit v1.2.3