Adds Hooks API

Adds Parse.Hooks.js in src/cloud-code/Parse.Hooks.js
Moves Cloud code related functions in src/cloud-code
This commit is contained in:
Florent Vilmart
2016-02-05 14:38:09 -05:00
parent a7262dafd8
commit 9ac7a52e40
19 changed files with 1121 additions and 104 deletions

View File

@@ -31,7 +31,7 @@ export default class PromiseRouter {
}
};
route(method, path, handler) {
route(method, path, ...handlers) {
switch(method) {
case 'POST':
case 'GET':
@@ -42,6 +42,25 @@ export default class PromiseRouter {
throw 'cannot route method: ' + method;
}
let handler = handlers[0];
if (handlers.length > 1) {
const length = handlers.length;
handler = function(req) {
var next = function(i, req, res) {
if (i == length) {
return res;
}
let result = handlers[i](req);
if (!result || typeof result.then !== "function") {
result = Promise.resolve(result);
}
return result.then((res) => (next(i+1, req, res)));
}
return next(0, req);
}
}
this.routes.push({
path: path,
method: method,
@@ -58,7 +77,6 @@ export default class PromiseRouter {
if (route.method != method) {
continue;
}
// NOTE: we can only route the specific wildcards :className and
// :objectId, and in that order.
// This is pretty hacky but I don't want to rebuild the entire