-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathforest.js
49 lines (45 loc) · 1.88 KB
/
forest.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
43
44
45
46
47
48
49
Meteor.startup(() => {
if (Meteor.settings && Meteor.settings.private && Meteor.settings.private.forest
&& Meteor.settings.private.forest.secretKey) {
ForestAdmin.apiMapsGetter();
} else {
console.error('Forest cannot find your project secret key. ' +
'Please, ensure you have properly set the secret key in your ' +
'settings.json file.');
return;
}
let ForestRouter = new Iron.Router;
ForestRouter.onBeforeAction(Iron.Router.bodyParser.json());
ForestRouter.onBeforeAction(Iron.Router.bodyParser.urlencoded({extended: false}));
_.each(ForestAdmin.collections, (collection) => {
ForestRouter.route('/forest/' + collection.name, { where: 'server' })
.get(function() {
var json = ForestAdmin.resourcesGetter(collection.name, this.params.query);
this.response.end(JSON.stringify(json));
})
.post(function() {
const data = this.request.body.data;
ForestAdmin.resourceCreator(collection.name, data.attributes,
(error) => {
this.response.writeHead(error ? 400 : 200);
this.response.end(); // TODO: Display an error message if Forest enables it
});
});
ForestRouter.route('/forest/' + collection.name + '/:recordId', { where: 'server' })
.put(function() {
const data = this.request.body.data;
ForestAdmin.resourceUpdater(collection.name, data.id, data.attributes,
(error) => {
this.response.writeHead(error ? 400 : 204);
this.response.end(); // TODO: Display an error message if Forest enables it
});
})
.delete(function() {
ForestAdmin.resourceRemover(collection.name, this.params.recordId,
(error) => {
this.response.writeHead(error ? 400 : 204);
this.response.end(); // TODO: Display an error message if Forest enables it
});
});
});
});