简体   繁体   中英

Pub/sub after separating folder for client and server code

This is my current app structure:

/client/client.js
/server/server.js
collection.js

There are HTML and CSS files, but those aren't relevant to my problem. Before splitting my app into this current structure it worked great, but it was one big JavaScript file . My Meteor.publish and Meteor.subscribe are not working, along with my accounts-ui being misconfigured.

This user had a similar problem , but my collection is defined in collection.js

My client.js folder consists of all the code that was in Meteor.isClient and server.js consists of all the code that was in Meteor.isServer along with Meteor.methods.

Collection.js is just Tweets = new Mongo.Collection("tweets"); .

Why is my publish and subscribe not working? I don't know if it's related, but accounts ui is also misconfigured.

According to the meteor doc http://docs.meteor.com/#/full/structuringyourapp

In the File Load Order section

There are several load ordering rules. They are applied sequentially to all applicable files in the application, in the priority given below:

  1. HTML template files are always loaded before everything else
  2. Files beginning with main. are loaded last
  3. Files inside any lib/ directory are loaded next
  4. Files with deeper paths are loaded next
  5. Files are then loaded in alphabetical order of the entire path

Your client.js and server.js are loaded before collection.js they are one level deeper than collection.js

Try this:

Move collection.js into lib/collection.js so your file structure looks like this

/client/client.js
/server/server.js
/lib/collection.js

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM