Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

While the meteor app is running, what are some ways of executing arbitrary code on the server side?

Sometimes I find myself wanting to execute some privileged code on the server while the app is running. For example, I may want to quickly delete a document in a collection (when the client-side is blocked from doing so). Or, I may want to quickly try out server-side functions like Email.send and Accounts.createUser.

So what are some of the ways of achieving this? I'm concerned with both cases of how an meteor app can be run:

  1. running using the meteor command
  2. running as the bundled node app

Ultimately, I'd also like to setup cron jobs that can execute some code in the Meteor context. Is this directly achievable or doable through workarounds?

Thanks for the help!

like image 914
Dave Avatar asked Jan 15 '23 17:01

Dave


1 Answers

Couldn't you just write server-side methods that only work for your user? Then expose those with Meteor.methods and run them in the client console. That's what I do when I want to test eg. Email.send. You could also go a step further and write a rudimentary admin UI.

For instance, on the server:

  Meteor.methods({
    test_sendEmail: function(options) {
      if (this.userId != adminUserId) return; // don't execute unless admin
      Email.send(options);
    }
  });

On the client:

  Meteor.call("test_sendEmail", {to: "[email protected]", subject: "Foo", text: "Bar"});
like image 197
Rahul Avatar answered Jan 20 '23 14:01

Rahul