caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
From: Martin Jambon <martin.jambon@ens-lyon.org>
To: Richard Jones <rich@annexia.org>
Cc: ben kuin <benkuin@gmail.com>, caml-list@inria.fr
Subject: Re: [Caml-list] web server interface for Ocaml ( like rack, wsgi, ...)?
Date: Tue, 21 Sep 2010 12:58:49 -0700	[thread overview]
Message-ID: <4C990E79.9050105@ens-lyon.org> (raw)
In-Reply-To: <20100921192048.GA25700@annexia.org>

Richard Jones wrote:
> On Tue, Sep 21, 2010 at 09:50:36AM +0200, ben kuin wrote:
>>> what's wrong with simply proxying the HTTP connections through your favorite webserver to the backend ocsigen/ocamlnet server?
>> Nothing per se. I've tried so set something up with ocsigen, but I had
>> to give up. There seems to be a certain philosophy behind it how you
>> should writing web apps.
>>
>> But I just wanted to do something:
>> -  small ( one page app )
>> -  quick and dirty ( no big setup upfront, no compilation)
>> -  deployment, by dropping a (ocaml script) into a webroot, not matter
>> what webserver is running
>> - permissive license ( mit, ...)
> 
>>  ~~~~ from wikipedia ~~~~
>> require 'rack'
>> app = Rack::Builder.app do
>>   lambda do |env|
>>     body = "Hello, World!"
>>     [200, {"Content-Type" => "text/plain", "Content-Length" =>
>> body.length.to_s}, [body]]
>>   end
>> end
> 
> This ought to work, and it's pretty simple ...
> 
> -----
> #!/usr/bin/ocamlrun ocaml
> print_string "\
> Content-Type: text/plain
> 
> Hello, World!"
> -----
> 
> 'course the problem is you'll be wanting to parse parameters, cookies
> and the rest of it, and there it does get a little bit more
> complicated.
> 
> I'm fairly sure ocamlnet can write standalone scripts like that?  Gerd??

I am pretty sure this is possible to do with Ocamlnet (netcgi2) although I
haven't done it in a while.

My recommendation would be to use ocamlscript, which relies on ocamlfind to
load libraries and compiles the executables only when needed, based on timestamps.

http://martin.jambon.free.fr/ocamlscript.html

You can try this:

#! /usr/bin/env ocamlscript
Ocaml.packs := [ "netcgi2" ]
--

let handle_request (cgi : Netcgi.cgi) =
  cgi # set_header ~content_type:"text/plain" ();
  cgi # output # output_string "Hello!\n";
  cgi # output # commit_work ()

let () =
  if Netcgi_cgi.is_cgi () then
    Netcgi_cgi.run handle_request
  else
    Netcgi_test.run handle_request


I don't know if it works when called from apache.  There might be permission
issues.  In general I think it's a bad idea to let the webserver do the
precious program analysis (compilation) in a live installation, but it's free
to try.  Ocamlscript also has an option to just compile the script and takes
care of cleaning up the compilation by-products.


Martin

-- 
http://mjambon.com/


      parent reply	other threads:[~2010-09-21 19:58 UTC|newest]

Thread overview: 16+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2010-09-16 11:05 ben kuin
2010-09-16 16:04 ` [Caml-list] " Michael Ekstrand
2010-09-16 17:29 ` Jake Donham
2010-09-16 19:00   ` Paolo Donadeo
2010-09-16 22:04     ` Dario Teixeira
2010-09-16 22:27       ` Michael Ekstrand
2010-09-16 23:55         ` Vincent Balat
2010-09-17  8:08           ` Paolo Donadeo
2010-09-17  8:03         ` Paolo Donadeo
2010-09-17  7:59       ` Paolo Donadeo
2010-09-17  8:57         ` Stéphane Glondu
2010-09-19 10:32   ` Richard Jones
2010-09-21  7:50     ` ben kuin
2010-09-21 19:20       ` Richard Jones
2010-09-21 19:46         ` Gerd Stolpmann
2010-09-21 19:58         ` Martin Jambon [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=4C990E79.9050105@ens-lyon.org \
    --to=martin.jambon@ens-lyon.org \
    --cc=benkuin@gmail.com \
    --cc=caml-list@inria.fr \
    --cc=rich@annexia.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).