-
Notifications
You must be signed in to change notification settings - Fork 28
Expand file tree
/
Copy pathhapi.js
More file actions
57 lines (45 loc) · 1.16 KB
/
hapi.js
File metadata and controls
57 lines (45 loc) · 1.16 KB
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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
var hapi = {};
hapi.HAPI_VERB = {
get: "getting",
create: "creating",
update: "changing",
delete: "deleting"
};
hapi.makeHAPISuccess = function (HAPI_VERB, resourceType, data) {
var hapiResponse = {
"this": "succeeded",
"by": HAPI_VERB,
"the": resourceType,
"with": data
};
return hapiResponse;
}
hapi.makeHAPIFailure = function (why, apiErrorCode) {
var hapiResponse = {
"this": "failed",
"with": apiErrorCode,
"because": why
};
return hapiResponse;
}
function middleware()
{
function hapiMiddleware(req, res, next) {
res.sendHAPISuccess = function(HAPI_VERB, resourceType, data)
{
res.send(hapi.makeHAPISuccess(HAPI_VERB, resourceType, data));
}
res.sendHAPIFailure = function(why, apiErrorCode)
{
res.send(hapi.makeHAPIFailure(why, apiErrorCode));
}
res.sendHAPINotFoundFailure = function()
{
res.sendHAPIFailure("we couldn't find this", 404);
}
return (next());
}
return (hapiMiddleware);
}
hapi.middleware = middleware;
module.exports = hapi;