-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.js
More file actions
61 lines (54 loc) · 1.46 KB
/
index.js
File metadata and controls
61 lines (54 loc) · 1.46 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
58
59
60
61
/*
* @Author: Dodik Gaghan
* @Date: 2016-02-15 09:39:55
* @Last Modified by: Dodik Gaghan
* @Last Modified time: 2016-02-16 15:08:09
*/
'use strict';
var Resource = require('deployd/lib/resource');
var Script = require('deployd/lib/script');
var util = require('util');
function EventResource() {
Resource.apply(this, arguments);
}
util.inherits(EventResource, Resource);
EventResource.label = "Custom Event";
EventResource.defaultPath = '/event';
EventResource.events = ["get", "post", "put", "delete"];
EventResource.prototype.clientGeneration = true;
EventResource.prototype.handle = function(ctx, next) {
var result = {};
var parts = ctx.url.split('/').filter(function(p) {
return p;
});
var domain = {
url: ctx.url,
parts: parts,
query: ctx.query,
body: ctx.body,
'this': result
}
domain.setResponse = function(val) {
result = val;
}
if (ctx.method === "POST" && this.events.post) {
this.events.post.run(ctx, domain, function(err) {
ctx.done(err, result);
});
} else if (ctx.method === "GET" && this.events.get) {
this.events.get.run(ctx, domain, function(err) {
ctx.done(err, result);
});
} else if (ctx.method === "PUT" && this.events.put) {
this.events.put.run(ctx, domain, function(err) {
ctx.done(err, result);
});
} else if (ctx.method === "DELETE" && this.events.delete) {
this.events.delete.run(ctx, domain, function(err) {
ctx.done(err, result);
});
} else {
next();
}
}
module.exports = EventResource;