-
Notifications
You must be signed in to change notification settings - Fork 9
/
representor.js
42 lines (33 loc) · 1016 Bytes
/
representor.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
/*******************************************************
* todo-mvc implementation based on ALPS doc
* representation router (server)
* May 2015
* Mike Amundsen (@mamund)
* Soundtrack : Complete Collection : B.B. King (2008)
*******************************************************/
// handles internal representation routing (based on conneg)
// load representors
var json = require('./representors/json.js');
var cj = require('./representors/cj.js');
module.exports = processDoc;
function processDoc(object, mimeType, root) {
var doc;
// clueless? assume JSON
if (!mimeType) {
mimeType = "application/vnd.collection+json";
}
// dispatch to requested representor
switch (mimeType.toLowerCase()) {
case "application/json":
doc = json(object, root);
break;
case "application/vnd.collection+json":
doc = cj(object, root);
break;
default:
doc = json(object, root);
break;
}
return doc;
}
// EOF