diff options
author | Trygve Laugstøl <trygvis@inamo.no> | 2012-07-02 22:54:50 +0200 |
---|---|---|
committer | Trygve Laugstøl <trygvis@inamo.no> | 2012-07-02 22:54:50 +0200 |
commit | 350b7ac055ed6374bde8bf49278c085f583c5781 (patch) | |
tree | 1153e6dc043dff134dab3861f42fa19c76836cd1 /routes | |
parent | 178e900fb843f29c70771226109278451fc15087 (diff) | |
download | example-collection-json-db-350b7ac055ed6374bde8bf49278c085f583c5781.tar.gz example-collection-json-db-350b7ac055ed6374bde8bf49278c085f583c5781.tar.bz2 example-collection-json-db-350b7ac055ed6374bde8bf49278c085f583c5781.tar.xz example-collection-json-db-350b7ac055ed6374bde8bf49278c085f583c5781.zip |
o Better conneg, defaulting to c+j unless text/html is requested.
Diffstat (limited to 'routes')
-rw-r--r-- | routes/index.js | 9 |
1 files changed, 6 insertions, 3 deletions
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; } }; |