WebService, HandleURL - Standalone vs CGI

  1. 3 days ago

    Jürg O

    Mar 20 Pre-Release Testers, Xojo Pro

    I've been playing a bit with creating a WebService. The Databases WebService Webinar and Luna have proven to be a good start.

    So I have a simple WebService running - as a Standalone App. The Event 'HandleURL' is being used to handle the requests.

    What I don't yet understand is:
    How is this supposed to work if the app is being deployed as .cgi?
    Let's assume: http://my-ip.address/cgi-bin/myapp.cgi
    Running it in Apache2 on Ubuntu works without any issue. I can use it as a regular Xojo WebApp (by opening http://my-ip.address/cgi-bin/myapp.cgi in the Browser).
    And I get the app to handle http://my-ip.address/cgi-bin/myapp.cgi/MyCustomRequest (from the "local" Ubuntu machine using Firefox).

    However, if I don't get the app to handle http://my-ip.address/cgi-bin/myapp.cgi/MyCustomRequest with 'HandleURL' from another machine (Windows, IE).

    Question 1:
    Somehow, it also doesn't make quite sense to me: How can Apache2 know that .../myapp.cgi/MyCustomRequest should be handled by the .cgi (and /MyCustomRequest shall be what's going to 'HandleURL'-event)? Why does it know that there's this .cgi, and is not looking for a folder 'myapp.cgi' and another folder 'MyCustomRequest'?

    Question 2:
    One other idea which I couldn't get to work:
    Can I use a Xojo WebApp as .cgi to handle a whole (virtual) "instance"? Configure Apache2 somehow so that all requests are being answered by the .cgi (but of course passing the Request to the same .cgi)?
    I only managed to allow a .cgi in the root, so that http://my-ip.address/ launches the Xojo-WebApp.
    But http://my-ip.address/MyRequest is then not being passed to the .cgi (along with /MyRequest) - Apache then tried to find an (obviously not existing) index-file in a folder "MyRequest").

    General question(s):
    How are others doing their WebServices in Xojo? Do you only built them as 'Standalone' or .cgi?
    How to design (and how to configure Apache2) it so that it can be used as .cgi, too - getting the .../myapp.cgi/MyRequest -> HandleURL '/MyRequest'?
    Or don't I need to bother at all, because a WebService as .cgi is not a good idea anyway - and if so: why?

    I know, quite some beginner questions :)
    Thanks if you find the time to answer some or all of my questions and/or explain how Xojo WebApp-Services running as .cgi are supposed to work.

  2. Michel B

    Mar 20 Pre-Release Testers, Xojo Pro
    Edited 3 days ago by Michel B

    You are making it way more complicated than it is.

    You don't need to configure anything. Just call your cgi with /myRequest, as you would in standalone.

    Standalone :

    http://127.0.0.1:8080/MyRequest

    Cgi

    http://mysite.com/cgi-bin/myprog.cgi/MyRequest

    In both case, HandleURL will be triggered, with path = MyRequest.

    BTW, since Standalone and cgi HandleURL work alike, you can test local within the IDE before deployment as cgi.

    I use that technique daily on my sites.

  3. Tomas J

    Mar 20 Pre-Release Testers, Xojo Pro Europe (Germany)

    to answer your 2nd Question: To prevent Apache2 searching a non-existent subfolder you could use mod_rewrite.

  4. Michel B

    Mar 20 Pre-Release Testers, Xojo Pro
    Edited 3 days ago by Michel B

    Sigh.

    He does not need any special configuration. Xojo handles the virtual path.

    Just build a cgi and try. You'll see.

  5. Jürg O

    Mar 20 Pre-Release Testers, Xojo Pro

    @Michel B He does not need any special configuration. Xojo handles the virtual path.

    I'm just curious why/how Apache recognizes this, and calls the .cgi with the 'virtual path'.

    It indeed works on the Ubuntu-machine where Apache is running without any special configuration.

    But so far I didn't manage to get a Xojo-Windows-App (running on another machine) connecting to http://ip-of-ubuntu-machine/cgi-bin/myapp.cgi/MyRequest using a HTTPSocket. I get Error 103 (Name resolution error). The same HTTPSocket has no issues connecting to a Standalone WebService to http://ip-of-ubuntu-machine:8080/MyRequest
    And a (non-xojo) Webbrowser on the 'other machine' can connect to the WebApp at http://ip-of-ubuntu-machine/cgi-bin/myapp.cgi, but doesn't get a 'HandleURL-response' from http://ip-of-ubuntu-machine/cgi-bin/myapp.cgi/MyRequest

    Something is not quite right yet - I just have to figure out what and why.
    So it would help to understand what Apache is doing (or maybe isn't in my case).

    But I agree that trying to use Apache->CGI the same way as a Standalone might not be the best idea (that would "make it complicated", in order to use Michel's words). I'm just curious if/how this could be done (or not) - to get Apache to answer all requests via a single .cgi and send all 'virtual Paths' in the same way a Standalone receives them.
    It's probably a lot of configuration for not much value (only to have shorter URL's to call; such as in the Standalone version).

  6. Tomas J

    Mar 20 Pre-Release Testers, Xojo Pro Europe (Germany)
    Edited 3 days ago by Tomas J

    Quite right Michel,

    https://apps.jakobssystems.de/wind3eck/demo leads to 401 because subfolder is not found
    https://apps.jakobssystems.de/wind3eck/ leads to CGI as described in Q2

    The only way to past HandleURL to the CGI is to rewrite http://my-ip/demo to http://my-ip/myapp.cgi/demo
    Of course in not making your cgi an index file would avoid this special treatment too but then it wouldn't be so readable.

  7. Michel B

    Mar 20 Pre-Release Testers, Xojo Pro
    Edited 3 days ago by Michel B

    Tomas, you are talking about a regular web app. A web service using HandleURL does not need anything special to work.

    Q2 is entirely, completely and utterly irrelevant.

or Sign Up to reply!