I created an ExtJS 5 application with Sencha Cmd. I will deploy this application in a tomcat server where there are some REST web services. I would need to use these web services but when I run the application with "sencha app watch" (on port 1841) it doesn't find the services because they are on a differente server (tomcat is on a different port). How can I use an "external" web service with Sencha CMD? Thanks stefano
1 Answers
Here are some of the available options:
Option 1 Proxy Web Service
You could create a service on the local machine where the sencha app is that create web requests that then goto the target remote services. This is called a proxy service.
Essentially the proxy service will take a request and resubmit it to the desired target remote machine.
There is a php example here
And a C# web request example here (Although this c# example isn't exactly what you are needing. The base of the web request that would need to be submitted is in this code. )
Option 2 JsonP
The other option off the top, is if the web services on the other machine support jsonp
they should be accessible. However, jsonp only supports get
so if you have a full rest implementation some services will probably not work.
And an extjs request example for JsonP
:
Ext.data.JsonP.request({
'url': 'url',
params: {
'param1': 'value'
},
success: function (result, request) {
//success
}
});
Option 3 Hosting multiple apps/paths on single port
However, since it seems like the tomcat server may actually be on the same machine. Is there not a way to host both the web services and the application path through tomcat?
It looks like, for instance, jetty has an option to host two apps on the same port
Option 4 Enable CORS
You can enable cross origin resource sharing on the rest application depending on the architecture/framework used.
The browser will basically send a request first to see if it can access the resource. And then the server would respond with the allowed origin domains. Once CORS is enabled then access could be granted between the two different ports/servers
Great site on CORS with instructions for enabling on most basic setups
Here is example documentation for spring
-
Thank you for your message. But would you suggest to do if I have to configure e REST proxy in a Model object? – stefano Sep 29 '14 at 13:40
-
@stefano i'd definitely see if cors could be enabled on the server with the webservice first. – weeksdev Oct 07 '14 at 00:54