0

My meteor app interacts with a mongodb-backed node.js microservice. I want to use autoform on the meteor app without having to maintain two copies of the schemas.

The microservice schemas are mongoose but it was straighforward to write a translator for autoform's simple-schema.

Getting the translations into meteor has been the tough part.

First, I was going to use npm. That proved to be a problem because meteor/hacks can't use local (npm link'd) packages.

Then, I considered browserify. That was no good because mongoose isn't client-side compatible.

Finally, I decided to just serve up the translations with express.

The remaining issue is that I need to attach the schema with collection2 BEFORE autoform tries to render.

I put the HTTP request in a Meteor.method. How/Where do I call attachSchema() such that it occurs before rendering is attempted?

This is what I tried:

onBeforeAction: function () {
  var self = this;
  Meteor.call('fetchSchema', 'ModelName', function (err, schema) {
    ModelName.attachSchema(new SimpleSchema(schema));
    self.next();
  });
}

I get this error:

Exception in delivering result of invoking 'fetchSchema': TypeError: object is not a function

How should I be going about this?

Jason
  • 681
  • 1
  • 9
  • 19
  • You can use npm libraries in *meteor packages* that run on the server. There are [docs on meteor packaging](http://docs.meteor.com/#/full/writingpackages) and various blog tutorials. – Paul Feb 23 '15 at 15:40
  • see also: http://stackoverflow.com/questions/26660907/load-npm-package-in-meteor-1-0 – Paul Feb 23 '15 at 15:49
  • Thanks but I have the server-side down. It's client-side that is giving me trouble. (The way collection2/autoform works, the schema needs to be attached on both server and client... that's the impression I'm under anyway) – Jason Feb 23 '15 at 16:03
  • The browser is always limited by the fact that it is a browser. Probably you need to write an API and use `Meteor.methods()` on the server and `Meteor.call()` on the client. – Paul Feb 23 '15 at 16:35

0 Answers0