Creating Custom CLI Tools for the Meteor Application

I am working on a Meteor application (port from a PHP project), and I need to be able to run commands on my application from the server for various operations, such as clearing caches, aggregating data, etc. These commands must be run from shell and crontab scripts. I have seen other people ask this question, and apparently there is no official way to do this yet.

I read the suggestion about using Meteor methods and just called them from the JS client console with a password. This does not solve my problem of starting them from the CLI, but it gave me an idea:

Is it possible to use a mute browser (e.g. PhantomJS) to connect to my application and execute Meteor.call () to simulate a CLI tool with arguments passed to the method? If possible, does anyone know how I can do this?

Thanks!

+4
source share
3 answers

EDIT : Updated to use Iron Router, the successor to Meteor Router.

No need for a headless browser or anything complicated. Use Meteorite to install Iron Router and determine server-sided route:

Router.map(function () { this.route('clearCache', { where: 'server', action: function () { // Your cache-clearing code goes here. } }); }); 

Then try running a cronjob HTTP GET request for this URI:

 curl http://yoursite.com/clearCache 

When the Meteor server receives a GET request, the router will execute your code.

To increase security a bit, add a password check:

 Router.map(function () { this.route('clearCache', { path: '/clearCache/:password', where: 'server', action: function () { if (this.params.password == '2d1QZuK3R3a7fe46FX8huj517juvzciem73') { // Your cache-clearing code goes here. } } }); }); 

And let your cronjob add this password to the URI:

 curl http://yoursite.com/clearCache/2d1QZuK3R3a7fe46FX8huj517juvzciem73 

Original post :

No need for a headless browser or anything complicated. Use Meteorite to install the Meteor Router and determine the server-sided route:

 Meteor.Router.add('/clearCache', function() { // Your cache-clearing code goes here. }); 

Then try running a cronjob HTTP GET request for this URI:

 curl http://yoursite.com/clearCache 

When the Meteor server receives a GET request, the router will execute your code.

To increase security a bit, add a password check:

 Meteor.Router.add('/clearCache/:password', function(password) { if (password == '2d1QZuK3R3a7fe46FX8huj517juvzciem73') { // Your cache-clearing code goes here. } }); 

And let your cronjob add this password to the URI:

 curl http://yoursite.com/clearCache/2d1QZuK3R3a7fe46FX8huj517juvzciem73 
+5
source

Check out this Meteor app that does just that:

http://meteor-shell.meteor.com/

Why do you need a CLI tool when you can just save some scripts on the server and execute them from the admin interface in your Meteor application?

0
source
I had the same question yesterday. Found this package, but have not tried https://github.com/practicalmeteor/meteor-mcli yet

Overview

Meteor package and command line tools for creating and running the command line program / cli with meteor.

Stimulus

To be able to reuse the same code of your meteor application in your team instead of creating separate node / npm code base with a lot of code duplicated from your meteorite application.

0
source

Source: https://habr.com/ru/post/1489962/


All Articles