Wildhoney / Magento-on-Angular

Angular.js application using Magento as the backend API
360 stars 120 forks source link

nodeJS server #89

Open ricricucit opened 9 years ago

ricricucit commented 9 years ago

I wanted to test Moa and everything went smooth until i've run this:

...$ node node/server.js

which generated this:

SyntaxError: Unexpected token <
at Object.parse (native)
at Request._callback (/Applications/MAMP/htdocs/stood_shop/node/server.js:24:21)
at Request.self.callback (/Applications/MAMP/htdocs/stood_shop/node_modules/request/request.js:122:22)
at Request.emit (events.js:98:17)
at Request.<anonymous> (/Applications/MAMP/htdocs/stood_shop/node_modules/request/request.js:888:14)
at Request.emit (events.js:117:20)
at IncomingMessage.<anonymous> (/Applications/MAMP/htdocs/stood_shop/node_modules/request/request.js:839:12)
at IncomingMessage.emit (events.js:117:20)
at _stream_readable.js:943:16
at /Applications/MAMP/htdocs/stood_shop/node_modules/newrelic/node_modules/continuation-local-storage/node_modules/async-listener/glue.js:177:31

any idea why?

(note: running a Python simpleHTTPserver showed me the app, but gave me obvious "Access-Control-Allow-Origin" errors)

Wildhoney commented 9 years ago

Probably Magento isn't configured correctly — try accessing api/products directly and see what message is returned.

ricricucit commented 9 years ago

i get a 404...i think that me and the "Getting Started" are missing some steps...

ricricucit commented 9 years ago

actually no. It's all good. going to

http://my.store/api/public/products

i see me an empty Array printed (which i guess it's fine since i didn't yet add any product)

Now the problem is:

1) Open example.com/Magento-on-Angular/store/ in your browser; 2) You may need to update the base_url in Magento Admin > Configuration > Web if you did a fresh installation of Magento.

1) it just shows me "Welcome to socket.io." 2) I'm not familiar with Magento but there i'm setting "http://example.com/Magento-on-Angular/store/" (obviously making that match with the right URL) ...is that the right BASE_URL? (doing that: i still get "Welcome to socket.io.")

zontafil commented 9 years ago

same problem. In my magento install (maybe on all newer install?) rest api need "accept: application/json" header, or it will return a 500 status code. substituting line 24 with

 request({url:url,headers:{"Accept": "application/json"}}, function (error, response, body) {

solved the issue for me, but you should debug your node server and see what's in the body and response var. Of course a status code check should be implemented in the server along with a correct error handling

Wildhoney commented 9 years ago

@m3l7 Could you please open a pull request for this change?