+1
+1
A reverse HTTP proxy server, for serving your remote backend from your local dev environment, can be done in Sencha Cmd with the --j2ee flag and a suitable web.xml file in the appropriate locations.
In the workspace root directory, create a file WEB-INF/web.xml with content similar to this example:
This should work since bug SDKTOOLS-1349 was fixed, so with Sencha Cmd v6.1.0 and up, using sencha web start --j2ee, or sencha app watch --fashion --j2ee, etc.Code:<?xml version="1.0" encoding="UTF-8"?> <web-app xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" metadata-complete="true" version="2.5" > <!-- ==================================================================== --> <!-- Reverse HTTP Proxy for the Sencha Cmd web server, e.g. --> <!-- http://localhost:1841/backend/test.php will reflect --> <!-- http://example.com/backend/test.php --> <!-- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - --> <servlet> <servlet-name>transparentReverseProxy</servlet-name> <servlet-class>org.eclipse.jetty.servlets.ProxyServlet$Transparent</servlet-class> <init-param> <param-name>ProxyTo</param-name> <param-value>http://example.com/backend</param-value> </init-param> <init-param> <param-name>HostHeader</param-name> <param-value>example.com</param-value> </init-param> <init-param> <param-name>Prefix</param-name> <param-value>/backend</param-value> </init-param> <load-on-startup>1</load-on-startup> </servlet> <servlet-mapping> <servlet-name>transparentReverseProxy</servlet-name> <url-pattern>/backend/*</url-pattern> </servlet-mapping> </web-app>
Last edited by richardvd; 4 Jan 2017 at 4:52 AM. Reason: WEB-INF should only exist in workspace root dir
I have added a WEB-INF/web.xml file and changed the content to my needs.
Now running 'sencha web start --j2ee' is working with the desired proxy settings.
But 'sencha app watch --j2ee' does not!
Is there any difference?
It would be great to have 'sencha app watch' running with the proxy settings.
The WEB-INF directory needs to be in the workspace root only, that's where the embedded Jetty server looks for it when using app watch.
Israel Roldán | Senior Software Engineer (Framework tools)
Does this work for Ajax requests? I don't think mine is working correctly, is there any way to test if it is set up correctly?
By workspace root you don't mean the app root right?
So I have the following:
Workspace/
apps/
appone/
ext/
packages/
WEB-INF/
You can display the workspace root directory by running: sencha framework list
Ok, I ran this and the workspace is what I thought it was. It still doesn't seem to be running.
How do I test that the reverse proxy is being picked up and working? When I make an AJAX request it is still going through localhost:1841.
Running with and without the -j2ee gives the exact same output. How would I know if it's picking up the xml file? Is there verbose mode or anything that would indicate this.
Apologies if I'm misunderstanding something.
In post #12 above I gave an example configuration file. Put that in WEB-INF/web.xml.
Run from the workspace root directory: sencha web start --j2ee
Now, open in your browser: http://example.com/backend/test.php and http://localhost:1841/backend/test.php
If it's working then both will give the result of the screenshot below:
Screen Shot 2017-03-17 at 15.47.16.png
For verbose output, run sencha -debug web start --j2ee and look for this line:
Code:[DBG] 785148949 proxy /backend/test.php-->http://example.com/backend/test.php
Oh my god! I had WEB_INF and not WEB-INF. I've hurt my face by how hard I face palmed myself...
Thanks so much for the help, I am able to get it going now!
Does the proxy forward custom headers, too? Or is it possible to configure which http-headers are proxied?