diff --git a/tutos/dev/manual/basics-server.wiki b/tutos/dev/manual/basics-server.wiki index 4b5cab0c..4ed0864f 100644 --- a/tutos/dev/manual/basics-server.wiki +++ b/tutos/dev/manual/basics-server.wiki @@ -62,6 +62,71 @@ To learn Lwt, read this [[lwt|short tutorial]], or its [[wiki("lwt"):|user manua >> +<
> +Ocsigen Server can be used either as a library for you OCaml programs, or as +an executable, taking its configuration from a file (and with dynamic linking). + +Extensions add features to the server. For example, Staticmod makes it possible +to serve static files, Deflatemod to compress the output, Redirectmod to +configure redirections etc. + +Install Ocsigen Server with: +{{{ +opam install ocsigenserver +}}} + +===Use as a library=== + +To include a Web server in your OCaml program, just add +package {{{ocsigenserver}}} to your Dune file, together with all the extensions +you need. For example: + +{{{ +(executable + (public_name ooo) + (name main) + (libraries + ocsigenserver + ocsigenserver.ext.staticmod)) +}}} + +Do +{{{dune init project ooo}}} +Then copy the dune file in directory {{{bin/}}}. + +The following command will launch a server, serving static files from +directory {{{static}}}: +<> +Put this in file {{{main.ml}}}, and run {{{dune exec ooo}}}. + +By default, the server runs on port 8080. + +===Use as an executable=== +Alternatively, you can run command {{{ocsigenserver}}} with a configuration +file: +{{{ +ocsigenserver -c ooo.conf +}}} + +The following configuration file corresponds to the program above: +{{{ + + + 8080 + + + + + + +}}} + +>> + <
> The following code shows how to create a service that answers @@ -106,17 +171,64 @@ HTML as strings. But we recommend to used typed-HTML instead (see below). <
> -Eliom provides an helper program called {{{eliom-distillery}}} to create your projects easily, with the right dune configuration and all default directories you usually need for a Web application (static files, server logs, database, etc.). We will show how to use eliom-distillery in another section below. - In this section, we will show how to compile and run a //server-side only// Web site by creating your project manually. +First, create the directories will we use for data (logs, etc.): +{{{ +mkdir -p local/var/log/mysite +mkdir -p local/var/data/mysite +mkdir -p local/var/run +}}} + +===Build an executable=== +This section shows how to create a static executable for you program +(without configuration file). + +Run the following commands: +{{{ +opam install ocsipersist-sqlite eliom +dune init project mysite +cd mysite +}}} + +Add packages {{{ocsigenserver.ext.staticmod}}}, +{{{ocsipersist.sqlite}}} and {{{eliom.server}}} to your file +{{{bin/dune}}}, +in the "libraries" section. + +Copy the definition and registration of service {{{myservice}}} above +into file {{{bin/main.ml}}}, +and add the following lines to configure and run the server: + +<> + +Build and execute the program with: +{{{ +dune exec mysite +}}} + +Open URL {{{http://localhost:8080/aaa/bbb}}} with your browser. + +===Use with ocsigenserver=== +Alternatively, you can decide to build your Eliom app as a library and +load it dynamically into ocsigenserver. + {{{ opam install ocsipersist-sqlite eliom dune init proj --kind=lib mysite cd mysite }}} -Add {{{(libraries eliom.server)}}} into file {{{lib/dune}}}, in the library section. +Add {{{(libraries eliom.server)}}} into file {{{lib/dune}}}. Create your {{{.ml}}} files in directory {{{lib}}}. For example, copy the definition and registration of service {{{myservice}}} above. @@ -126,7 +238,8 @@ Compile: dune build }}} -Create a configuration file {{{mysite.conf}}} with this content on your project root directory: +Create a configuration file {{{mysite.conf}}} +with this content on your project root directory: {{{ @@ -138,25 +251,16 @@ Create a configuration file {{{mysite.conf}}} with this content on your project local/var/run/mysite-cmd - - - - + + - - + }}} -Create the missing directories: -{{{ -mkdir -p local/var/log/mysite -mkdir -p local/var/data/mysite -mkdir -p local/var/run -}}} Launch the application: {{{ ocsigenserver -c mysite.conf diff --git a/tutos/dev/manual/basics.wiki b/tutos/dev/manual/basics.wiki index d0764a7c..48b7b2d8 100644 --- a/tutos/dev/manual/basics.wiki +++ b/tutos/dev/manual/basics.wiki @@ -62,7 +62,8 @@ Ocsigen Server can be used either as a library for you OCaml programs, or as an executable, taking its configuration from a file (and with dynamic linking). Extensions add features to the server. For example, Staticmod makes it possible -to serve static files, Deflatemod to compress the output, etc. +to serve static files, Deflatemod to compress the output, Redirectmod to +configure redirections etc. Install Ocsigen Server with: {{{