Refactoring servers configuration structure
This commit is contained in:
1 parent
624d2aeaf5
commit
b33ce54188
20 files changed
+173
-118
No files matched your search
@@ -46,12 +46,15 @@ Meteor.publish('reviewers', function() {
|
||||
return Reviewers.find();
|
||||
});
|
||||
|
||||
Meteor.publish('servers', function() {
|
||||
return Servers.find();
|
||||
});
|
||||
|
||||
// Temporary fix to drop all Collections on server restart
|
||||
// http://stackoverflow.com/questions/23891631/meteor-how-can-i-drop-all-mongo-collections-and-clear-all-data-on-startup
|
||||
Meteor.startup(function() {
|
||||
var globalObject = Meteor.isClient ? window : global;
|
||||
for (var property in globalObject) {
|
||||
var object = globalObject[property];
|
||||
for (var property in global) {
|
||||
var object = global[property];
|
||||
if (object instanceof Meteor.Collection) {
|
||||
object.remove({});
|
||||
}
|
||||
|
||||
@@ -0,0 +1,34 @@
|
||||
Meteor.startup(function() {
|
||||
|
||||
_.each(Meteor.settings.servers, function(endpoints, serverType) {
|
||||
_.each(endpoints, function(endpoint) {
|
||||
var server = _.clone(endpoint);
|
||||
server.origin = "json";
|
||||
server.type = serverType;
|
||||
Servers.insert(server);
|
||||
});
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
Meteor.methods({
|
||||
addServer: function(serverSettings) {
|
||||
console.log("CHECKING PERMISSIONS");
|
||||
if (!Meteor.userId()) {
|
||||
throw new Meteor.Error('not-authorized');
|
||||
}
|
||||
console.log("WRITTING ON COLLECTION");
|
||||
Servers.update(
|
||||
{ type: serverSettings.type, name: serverSettings.name },
|
||||
serverSettings,
|
||||
{ upsert: true },
|
||||
function(error, affected) {
|
||||
console.log("CHECKING FOR ERRORS");
|
||||
if(error) throw new Meteor.Error('data-write', error);
|
||||
console.log("NO ERRORS, " + affected + " DOCUMENTS AFFECTED");
|
||||
console.log(Servers.findOne());
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
});
|
||||
Reference in new issue
Block a user