WebService, HandleURL - Standalone vs CGI

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 :slight_smile:
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.

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.

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

Sigh.

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

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

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).

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.

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.

You’re right.

I wasn’t quite sure because in some situations it didn’t work as expected.

Meanwhile this has been tracked down to this:
<https://xojo.com/issue/47469> - Connecting from a WebApp using the old HTTPSecureocket (with .Secure=false) doesn’t work in CGI-mode (but works in Standalone mode).