node js rest service express module is not invoking from sencha application

7 views
Skip to first unread message

itsaj...@gmail.com

unread,
Feb 14, 2016, 2:33:29 PM2/14/16
to nodejs
Hi ,


I am new to nodejs and sencha development. I am trying to develop an application using sencha. My application need to consume rest service, which is implemented in nodejs using express module.


My sench application looks as follows.


Model: HelloWorldModel.js
-----------START-----------------------------


Ext.define('Hello.model.HelloWorldModel', {
extend: 'Ext.data.Model',
config: {
fields: [ 'id', 'content' ]
}
});
------------END------------------------------


View : HelloWorldView.js
-----------START-----------------------------


Ext.define('Hello.view.HelloWorldView', {
extend: 'Ext.Panel',
config: {
fullscreen: true,
tpl: '<p>The ID is {id}</p><p>The content is {content}</p>'
}
});
------------END------------------------------




Store : HelloWorldStore.js
-----------START-----------------------------


xt.define('Hello.store.HelloWorldStore', {
extend: 'Ext.data.Store',
config: {
model: 'Hello.model.HelloWorldModel',
proxy: {
type: 'rest',
},
listeners: {
beforeload: function () {
var name = document.location.search.slice(1);
this.getProxy().setExtraParam('name', name);
}
}
}
});
------------END------------------------------


hello.js
-----------START-----------------------------
Ext.application({
name: 'Hello',
models: [ 'HelloWorldModel' ],
stores: [ 'HelloWorldStore' ],
views: [ 'HelloWorldView' ],
launch: function () {


var view = Ext.create('Hello.view.HelloWorldView', {});


Ext.create('Hello.store.HelloWorldStore', {
autoLoad: true,
listeners: {
load: function (self, records) {
view.setData(records[0].getData());
}
}
});


}
});


Ext.Loader.setConfig({ disableCaching: false });
------------END------------------------------


Application's index.html
-----------START-----------------------------
<!doctype html>
<html>
<head>
<title>Hello Sencha</title>
<script src="hello.js"></script>
</head>
<body>
</body>
</html>


------------END------------------------------






Rest Service is implemented using node js express module nodejsExpress.js
-----------START-----------------------------
var express = require('express');
var app = express();
app.get('/hello', function(req, res) {
console.log("Received request for /hello");
res.send('{"id":85,"content":"Hello, World!"}')
})
app.listen(8888);
console.log("Listening on 8888");
------------END------------------------------



If I am calling http://localhost:8888/hello from sencha's application, I could not see any console log message in the console where I ran nodejsExpress.js , and no response to the sencha application
I also implemented the rest service using http module as follows nodejsHttp.js`


-----------START-----------------------------
var http = require('http');
http.createServer(function (req, res) {
res.writeHead(200, {'Content-Type': 'text/plain'});
res.end('Hello World\n');
}).listen(8010, '127.0.0.1');
console.log('Server running at http://127.0.0.1:8010/');
------------END------------------------------
If i invoke http framework implemented nodeJS service(using http://localhost:8010 from the sencha application, I could see the response received to sencha application along with the console log.


Can some body please help me what is cauaing the issue with express framework nodejs implementation. 


Thanks for your help in advance.

Thanks, 
Ajay

Reply all
Reply to author
Forward
0 new messages