Page 2 of 3 FirstFirst 123 LastLast
Results 11 to 20 of 27

Thread: "sencha app watch" proxy configuration

  1. #11
    Sencha Premium Member
    Join Date
    Dec 2012
    Posts
    12

    Default

    +1

  2. #12
    Sencha Premium Member richardvd's Avatar
    Join Date
    Jun 2011
    Location
    NL
    Posts
    255

    Default

    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:

    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>
    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.
    Last edited by richardvd; 4 Jan 2017 at 4:52 AM. Reason: WEB-INF should only exist in workspace root dir

  3. #13
    Sencha User
    Join Date
    May 2012
    Posts
    53

    Default

    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.

  4. #14
    Sencha - Engineering israelroldan's Avatar
    Join Date
    Nov 2011
    Location
    The Netherlands
    Posts
    395

    Default

    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)

  5. #15
    Sencha Premium Member
    Join Date
    May 2012
    Posts
    114

    Default

    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/

  6. #16
    Sencha Premium Member richardvd's Avatar
    Join Date
    Jun 2011
    Location
    NL
    Posts
    255

    Default

    You can display the workspace root directory by running: sencha framework list

  7. #17
    Sencha Premium Member
    Join Date
    May 2012
    Posts
    114

    Default

    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.

  8. #18
    Sencha Premium Member richardvd's Avatar
    Join Date
    Jun 2011
    Location
    NL
    Posts
    255

    Default

    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

  9. #19
    Sencha Premium Member
    Join Date
    May 2012
    Posts
    114

    Default

    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!

  10. #20
    Sencha Premium Member
    Join Date
    Sep 2011
    Posts
    123

    Default

    Does the proxy forward custom headers, too? Or is it possible to configure which http-headers are proxied?

Page 2 of 3 FirstFirst 123 LastLast

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •