meteor - app not working unless there is something in server.js file -
i have texting app created while , broke. fixed copying of code on project , installing same packages. when did this, stopped working , have no idea why. narrowed down texts
returning empty array since no data being published. in new app created, have exact same code, 1 not working... happened me other app copied from(it did not work, randomly started working again) , worked after day of not touching it. , yes, autopublish installed @ version 1.0.7. please reoccuring problem , need answer!
client - main.js
import react "react"; import reactdom "react-dom"; import {meteor} "meteor/meteor"; import {tracker} "meteor/tracker"; import { browserrouter, route, switch, redirect, withrouter} 'react-router-dom' import {texts} "./../imports/api/text"; import app "./../imports/ui/app"; import notfound "./../imports/ui/notfound"; import signup "./../imports/ui/signup"; import login "./../imports/ui/login"; meteor.startup(() => { tracker.autorun(() => { let texts = texts.find().fetch(); let signedin = !!meteor.userid(); if(signedin){ console.log("signed in"); }else{ console.log("signed out") } console.log(texts) const routes = ( <browserrouter> <switch> <app path="/chat" texts={texts}/> <signup path="/signup" /> <login path="/login" /> <route component={notfound}/> </switch> </browserrouter> ); reactdom.render(routes, document.getelementbyid("app")); }); console.log("hi") });
server - main.js
import { meteor } 'meteor/meteor'; meteor.startup(() => { const texts = new mongo.collection("texts") //<--app works when put line of code in server file });
text.js
import {mongo} "meteor/mongo"; export const texts = new mongo.collection("texts");
you need have collection initialized on both client , server. code seems you're importing text.js
client code only, that's why works when you're creating collection on server well. can import same text.js
in server/main.js
, should work.
Comments
Post a Comment