Reputation: 2065
Let's say I have a normal Meteor website/app hosted on Galaxy, and then an admin site hosted on a different server, but both are connected to the same database.
I want a user on my regular site to be able to trigger a method call (or any procedure) on the admin server remotely.
I'm thinking this can be done because, if I had a dummy user logged into the right page on the admin server, then it would listen for changes in whatever collection "he" is subscribed to. If the real user on the different server changes something in that collection, the dummy user would see it, and that could in turn trigger a method call.
Now, there has to be a way to skip the step of the dummy user and listen in on changes directly from the admin server.
Can anyone lead me in the right direction here?
Upvotes: 2
Views: 170
Reputation: 302
From the comments, it looks like this is a matter of wanting to have administration operations running from a separate server, with administration code only on that server.
If this is indeed what's needed, the simplest way I can think to do it would be to run another instance of the meteor app on the other server, but the 'enhanced' version, and have your admin users connect to that server (perhaps called admin.yourdomain.com). You can still point the server at the original mongodb (by setting MONGO_URL as appropriate).
Upvotes: 0
Reputation: 3288
To expand on my comment to OP with some code.
First, add this package to the server you have created where you'd like to access some meteor methods, etc. Then:
// server1.js
Meteor.methods({
foo: function(bar) {
check(bar, Whatever)
... do some stuff ...
return fooBar
}
})
HTTP.methods({
'/foo/:bar': function() {
return JSON.stringify(Meteor.call("foo", this.params.bar), null, '\t')
}
});
Finally, on the other server, where you'd like to access the first server:
// server2.js
// somewhere on your server (startup, a method, etc.)
try {
var bar = ...
var result = HTTP.call(
"GET", "http://yourFirstServer.com/foo/" + bar
)
} catch (e) {
// Got a network error, time-out or HTTP error in the 400 or 500 range.
console.log(e)
}
Upvotes: 2