dylson-v
8/4/2015 - 1:52 PM

Loading a JSON inside a meteor app.

Loading a JSON inside a meteor app.

.
├── README.md
├── client
│   ├── home
│   │   ├── controllers
│   │   │   ├── home.controller.ng.js
│   │   │   └── products.controller.ng.js
│   │   └── views
│   │       ├── home.ng.html
│   │       └── products.ng.html
│   ├── lib
│   │   └── app.ng.js
│   ├── routes.ng.js
│   └── styles
│       └── main.styl
├── index.html
├── model
│   └── products.js
├── products.json
└── server
if (Meteor.isClient) {
  // Should execute only on the Client Side.
  HTTP.get(Meteor.absoluteUrl("/products.json"), function(err,result) {
      if (result) { console.log(result.data); }
  });
}

if (Meteor.isServer) {
  // Should execute only on the Server Side.
  Products = HTTP.get(Meteor.absoluteUrl("/products.json")).data;
  console.log(Products);
}
Looking for answers at
freenode's #meteor channel

00:05 You have joined the channel
00:05 |\|370 has joined (~|\|370@181.164.65.249)
00:05 Topic: Meteor: a better way to make apps http://www.meteor.com | https://github.com/meteor/meteor | Please use https://gist.github.com for code help. Please don’t paste in channel.
00:05 katielee set the topic at: Jul 29, 2014, 21:01
00:05 Mode: +cnt
00:05 Created at: Jan 28, 2010, 02:55
10:07 You have joined the channel
10:07 |\|370 has joined (~|\|370@201-212-137-187.cab.prima.net.ar)
10:07 Topic: Meteor: a better way to make apps http://www.meteor.com | https://github.com/meteor/meteor | Please use https://gist.github.com for code help. Please don’t paste in channel.
10:07 katielee set the topic at: Jul 29, 2014, 21:01
10:07 Mode: +cnt
10:07 Created at: Jan 28, 2010, 02:55
11:25 |\|370: Can anybody explain me why I'm getting this error? https://gist.github.com/n370/f244ed654714a8146502
11:25 |\|370: the server don't even fire
11:26 |\|370: your help is much appreciated
11:32 |\|370 has left ()
11:32 You have left the channel
11:32 You have joined the channel
11:32 |\|370 has joined (~|\|370@201-212-137-187.cab.prima.net.ar)
11:32 Topic: Meteor: a better way to make apps http://www.meteor.com | https://github.com/meteor/meteor | Please use https://gist.github.com for code help. Please don’t paste in channel.
11:32 katielee set the topic at: Jul 29, 2014, 21:01
11:32 Mode: +cnt
11:32 Created at: Jan 28, 2010, 02:55
11:39 |\|370: Can anybody explain me why I'm getting this error? https://gist.github.com/n370/f244ed654714a8146502
11:39 |\|370: the server hangs forever an the error throw is a joke
11:39 |\|370: thrown
11:45 pchoo: |\|370: have you read about: http://docs.meteor.com/#/full/meteor_absoluteurl ? it says not to include the leading / - also, have you tried navigating to the rsult of the absolute URL call?  It may be that you need to move your json file if it cannot find it.  That said it would be a misleading error.
11:47 |\|370: thanks pchoo let me triple check all this. get back here in a moment. 
11:48 |\|370: however it a concern for me to have my json file where it is placed now and be able to access it there from the server and have it available through a variable accecible both from the client and the server
11:50 |\|370: My ultimate goal is to have this json file available just like a regular mongo collection
11:57 pchoo: |\|370: http://docs.meteor.com/#/full/structuringyourappSee the public folder r.e. having it available as a URL based thing.  If you want to have this json file available in a similar manner to a collection, why not have it in a  collection?
12:11 |\|370: so pchoo removing the leading / doesn't change the output. I understand that any file outside the test, packages, server, client, public and private folder are available both on the client and the server so why my json isn't accessible ? 
12:12 pchoo: they are interpreted by the compiler as such, but that does not mean they are available via HTTP
12:13 pchoo: if you want it via HTTP you via HTTP move it to the public folder, and your code may work with that
12:13 pchoo: |\|370: you would likely find this post useful: http://stackoverflow.com/questions/15374066/importing-a-json-file-in-meteor
12:14 |\|370: yes I understand that. using http is not a requirement for me
12:14 pchoo: Caveat being I've not tried this, and only just skimmed it
12:15 |\|370: yeah pchoo I stumbled upon this SO question and have posted two comments on the accecepted answere since yesterday
12:15 |\|370: using http is not a requiremente for me
12:15 |\|370: I just want to keep the folder structore
12:15 |\|370: the way it is shown in the gist i posted
12:16 |\|370: pchoo, btw thank for engaging with me on that one. 
12:16 |\|370: I appreciate your time
12:16 pchoo: |\|370: np, it's an intriguing issue, gimme a minute to check something out
12:17 |\|370: thanks man
12:24 pchoo: |\|370: does it have to be in the root of the project, or can it be private/whatever.json?
12:29 |\|370: pchoo given the way things unfolded I have to answers for your question. my pragmatic ego answers whatever, load it into the private folder access it using the assets api and be happy, however my curious ego answers DAMN!!!! why the hell this isn't working with the .json in the root of the project. and why doing it like that makes meteor throw this nasty error that doesn't give a clue about what is happening there. I can't eve
12:29 |\|370: n debug it with node-inspector because the server never fires up.
12:30 |\|370: hahahah see how mad this thing is driving me now
12:30 |\|370: unbelievable
12:31 dbarrett: is the json valid?
12:31 dbarrett: if you remove the json file from the project does it start correctly?
12:31 pchoo: |\|370: haha Assets APi in the private folder is working for me.  As for the unhelpful error, take that up with MDG ;) AFAIK meteor does nothing with .json files natively, unless they are in a special directory.  If you want it available on the URL, then it needs to be in the public folder
12:35 |\|370: yes, I'm definitely taking it to the meteor forums after that. thank you very much for your assistance pchoo
12:35 pchoo: no worries, good luck finding the answer to your quest!
12:35 |\|370: yep, dbarret, I have a valid json there
12:35 pchoo: question*
12:35 pchoo: for a second there I thought we were within an RPG :|
12:36 pchoo: might not help that I'm listening to the dotHACK OSTs :D
12:36 |\|370: yep, yesterday night al kinds of darkness surrounded me with that error
12:39 |\|370: and removing the .json doesn't solve the issue dbarrett
W20150804-10:50:47.375(-3)? (STDERR)          
W20150804-10:50:47.376(-3)? (STDERR) /Users/n370/.meteor/packages/meteor-tool/.1.1.4.rpwbv7++os.osx.x86_64+web.browser+web.cordova/mt-os.osx.x86_64/dev_bundle/server-lib/node_modules/fibers/future.js:278
W20150804-10:50:47.376(-3)? (STDERR) 						throw(ex);
W20150804-10:50:47.376(-3)? (STDERR) 						      ^
W20150804-10:50:47.402(-3)? (STDERR) Error: socket hang up
W20150804-10:50:47.402(-3)? (STDERR)     at Object.Future.wait (/Users/n370/.meteor/packages/meteor-tool/.1.1.4.rpwbv7++os.osx.x86_64+web.browser+web.cordova/mt-os.osx.x86_64/dev_bundle/server-lib/node_modules/fibers/future.js:398:15)
W20150804-10:50:47.402(-3)? (STDERR)     at Object.call (packages/meteor/helpers.js:119:1)
W20150804-10:50:47.402(-3)? (STDERR)     at Object.HTTP.get (packages/http/httpcall_common.js:45:1)
W20150804-10:50:47.402(-3)? (STDERR)     at app/model/products.js:10:19
W20150804-10:50:47.402(-3)? (STDERR)     at app/model/products.js:14:3
W20150804-10:50:47.403(-3)? (STDERR)     at /Users/n370/Projects/Tevincocin/frescaentrega-angular-meteor/.meteor/local/build/programs/server/boot.js:222:10
W20150804-10:50:47.403(-3)? (STDERR)     at Array.forEach (native)
W20150804-10:50:47.403(-3)? (STDERR)     at Function._.each._.forEach (/Users/n370/.meteor/packages/meteor-tool/.1.1.4.rpwbv7++os.osx.x86_64+web.browser+web.cordova/mt-os.osx.x86_64/dev_bundle/server-lib/node_modules/underscore/underscore.js:79:11)
W20150804-10:50:47.403(-3)? (STDERR)     at /Users/n370/Projects/Tevincocin/frescaentrega-angular-meteor/.meteor/local/build/programs/server/boot.js:117:5
W20150804-10:50:47.403(-3)? (STDERR)     - - - - -
W20150804-10:50:47.403(-3)? (STDERR)     at createHangUpError (http.js:1477:15)
W20150804-10:50:47.403(-3)? (STDERR)     at Socket.socketOnEnd (http.js:1573:23)
W20150804-10:50:47.403(-3)? (STDERR)     at Socket.g (events.js:180:16)
W20150804-10:50:47.403(-3)? (STDERR)     at Socket.emit (events.js:117:20)
W20150804-10:50:47.403(-3)? (STDERR)     at _stream_readable.js:944:16
W20150804-10:50:47.404(-3)? (STDERR)     at process._tickCallback (node.js:442:13)
=> Exited with code: 8