Autore Topic: Embedded HTTP server con la rev. 5209  (Letto 644 volte)

Offline vuott

  • Moderatore globale
  • Senatore Gambero
  • *****
  • Post: 11.719
  • Ne mors quidem nos iunget
    • Mostra profilo
Embedded HTTP server con la rev. 5209
« il: 28 Settembre 2012, 03:57:59 »
Minisini fa sapere che:

Hi,

In revision #5209, I have added an experimental new feature to the
interpreter, which is an... embedded HTTP server.

At the moment, you can only use it from the command line.

By running the interpreter with the '-H' option, the current project is
run as a CGI script from an embedded HTTP server.

In other words, provided that your application is a CGI script, running
it with the '-H' option transforms it into a running local web site.

For example:

$ cd /path/to/my/cgi/script/project
$ GB_HTTPD_PORT=8000 gbx3 -H
...
[Hit ^C to stop it]
$

Note the GB_HTTPD_PORT environmental variable that is needed, otherwise
the embedded HTTP server will try the port 80, which is reserved to root.

How does it work? "gbx3 -H" will just run the embedded HTTP server, and
when a request arrives, it will fork and run the Gambas interpreter
normally. As many initialization have already been done by the HTTP
server (all components have been loaded), the CGI script should run
faster than when it is run from a normal HTTP server like Apache.

Another variable is GB_HTTPD_TIMEOUT, which is how many seconds a CGI
script can run before being killed by the HTTP server.

I made that feature so that we will be able to debug web application
directly from the IDE. Actually I don't know if this is possible. I
mean: running a CGI script step by step like a normal program while the
HTTP server is running and serving other HTTP request from the same CGI
script!

Anyway, even if it is not possible at the moment, that feature will
allow to run a Gambas project as a full standalone http server serving a
complete website.

I hope some of you will find that interesting. :-)

Regards,

--
Benoît Minisini
« Chiunque, non ricorrendo lo stato di necessità, nel proprio progetto Gambas fa uso delle istruzioni Shell o Exec, è punito con la sanzione pecuniaria da euro 20,00 a euro 60,00. »

Offline vuott

  • Moderatore globale
  • Senatore Gambero
  • *****
  • Post: 11.719
  • Ne mors quidem nos iunget
    • Mostra profilo
Re: Embedded HTTP server con la rev. 5209
« Risposta #1 il: 28 Settembre 2012, 04:01:00 »
Rispondendo, poi, ad un membro della M.L.I. aggiunge:

At the moment, the HTTP server is run just after the ".project" file has
been loaded, analyzed, and the required components loaded. When it forks
to actually run the project, the _init() functions of all exported
classes from components written in Gambas are called, the main hooks are
run, and then the Main() function of the startup class is run.

As for translation files, they are always loaded the later as possible
(when the first translated string of the component or the project is
needed).
gb.httpd is intended to serve only what is inside the project. I think
it could be modified so that it serves static files located inside the
project without running the CGI script.

Regards,

--
Benoît Minisini
« Chiunque, non ricorrendo lo stato di necessità, nel proprio progetto Gambas fa uso delle istruzioni Shell o Exec, è punito con la sanzione pecuniaria da euro 20,00 a euro 60,00. »

Offline vuott

  • Moderatore globale
  • Senatore Gambero
  • *****
  • Post: 11.719
  • Ne mors quidem nos iunget
    • Mostra profilo
Re: Embedded HTTP server con la rev. 5209
« Risposta #2 il: 28 Settembre 2012, 12:19:45 »
How can i use it and take advantage of this feature if i do not know all the
details ?
e.g.
can i run a gmbas project using gb.httpd on PC1 (or raspberry) and access the
running project via http from another machine PC2 ?

wally
« Chiunque, non ricorrendo lo stato di necessità, nel proprio progetto Gambas fa uso delle istruzioni Shell o Exec, è punito con la sanzione pecuniaria da euro 20,00 a euro 60,00. »

Offline vuott

  • Moderatore globale
  • Senatore Gambero
  • *****
  • Post: 11.719
  • Ne mors quidem nos iunget
    • Mostra profilo
Re: Embedded HTTP server con la rev. 5209
« Risposta #3 il: 08 Ottobre 2012, 14:41:02 »
Altro messaggio di Minisini al riguardo:

Hi,

In revision #5226, the embedded HTTP server is now able to serve static
files. These static files must be located in a new project directory
named ".public" on the disk and "Public" on the IDE project tree.

The server first checks if the URL matches a file inside the ".public"
directory. In that case, the file is served.

Otherwise, the executable is run as a CGI script.

Regards,

--
Benoît Minisini
« Chiunque, non ricorrendo lo stato di necessità, nel proprio progetto Gambas fa uso delle istruzioni Shell o Exec, è punito con la sanzione pecuniaria da euro 20,00 a euro 60,00. »