Skip to content

Commit

Permalink
basics and basics-server: improve "use as a library" doc
Browse files Browse the repository at this point in the history
  • Loading branch information
balat committed Aug 23, 2024
1 parent 101f090 commit 403b2e0
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 30 deletions.
29 changes: 14 additions & 15 deletions tutos/dev/manual/basics-server.wiki
Original file line number Diff line number Diff line change
Expand Up @@ -84,15 +84,15 @@ you need. For example:

{{{
(executable
(public_name ooo)
(public_name mysite)
(name main)
(libraries
ocsigenserver
ocsigenserver.ext.staticmod))
}}}

Do
{{{dune init project ooo}}}
{{{dune init project mysite}}}
Then copy the dune file in directory {{{bin/}}}.

The following command will launch a server, serving static files from
Expand All @@ -101,15 +101,15 @@ directory {{{static}}}:
let () =
Ocsigen_server.start [ Ocsigen_server.host [Staticmod.run ~dir:"static" ()]]
>>
Put this in file {{{main.ml}}}, and run {{{dune exec ooo}}}.
Put this in file {{{main.ml}}}, and run {{{dune exec mysite}}}.

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
ocsigenserver -c mysite.conf
}}}

The following configuration file corresponds to the program above:
Expand Down Expand Up @@ -184,26 +184,24 @@ mkdir -p local/var/run
This section shows how to create a static executable for you program
(without configuration file).

Run the following commands:
Run the following command:
{{{
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.
Add packages {{{ocsipersist.sqlite}}} and {{{eliom.server}}} to 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:
Copy the definition and registration of service {{{myservice}}} at the beginning
of file {{{bin/main.ml}}},
and replace the call to {{{Ocsigen_server.start}}} by the following lines:

<<code language="ocaml"|
let () =
Ocsigen_server.start
~command_pipe:"local/var/run/mysite-cmd"
~logdir:"local/var/log/mysite"
~datadir:"local/var/data/mysite"
[
Ocsigen_server.host
[ Staticmod.run ~dir:"local/var/www/mysite" ()
Expand All @@ -220,7 +218,7 @@ 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.
load it dynamically into ocsigenserver using a configuration file.

{{{
opam install ocsipersist-sqlite eliom
Expand Down Expand Up @@ -268,6 +266,7 @@ ocsigenserver -c mysite.conf
Open URL {{{http://localhost:8080/aaa/bbb}}} with your browser.
>>


<<section class="docblock" |
<<header |==TyXML: typing HTML==>>

Expand Down
28 changes: 13 additions & 15 deletions tutos/dev/manual/basics.wiki
Original file line number Diff line number Diff line change
Expand Up @@ -78,15 +78,15 @@ you need. For example:

{{{
(executable
(public_name ooo)
(public_name mysite)
(name main)
(libraries
ocsigenserver
ocsigenserver.ext.staticmod))
}}}

Do
{{{dune init project ooo}}}
{{{dune init project mysite}}}
Then copy the dune file in directory {{{bin/}}}.

The following command will launch a server, serving static files from
Expand All @@ -95,15 +95,15 @@ directory {{{static}}}:
let () =
Ocsigen_server.start [ Ocsigen_server.host [Staticmod.run ~dir:"static" ()]]
>>
Put this in file {{{main.ml}}}, and run {{{dune exec ooo}}}.
Put this in file {{{main.ml}}}, and run {{{dune exec mysite}}}.

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
ocsigenserver -c mysite.conf
}}}

The following configuration file corresponds to the program above:
Expand Down Expand Up @@ -345,26 +345,24 @@ mkdir -p local/var/run
This section shows how to create a static executable for you program
(without configuration file).

Run the following commands:
Run the following command:
{{{
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.
Add packages {{{ocsipersist.sqlite}}} and {{{eliom.server}}} to 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:
Copy the definition and registration of service {{{myservice}}} at the beginning
of file {{{bin/main.ml}}},
and replace the call to {{{Ocsigen_server.start}}} by the following lines:

<<code language="ocaml"|
let () =
Ocsigen_server.start
~command_pipe:"local/var/run/mysite-cmd"
~logdir:"local/var/log/mysite"
~datadir:"local/var/data/mysite"
[
Ocsigen_server.host
[ Staticmod.run ~dir:"local/var/www/mysite" ()
Expand All @@ -381,7 +379,7 @@ Open URL {{{http://localhost:8080/foo?myparam=Hello&i=27}}} with your browser.

===Use with ocsigenserver===
Alternatively, you can decide to build your Eliom app as a library and
load it dynamically into ocsigenserver.
load it dynamically into ocsigenserver using a configuration file.

{{{
opam install ocsipersist-sqlite eliom
Expand Down

0 comments on commit 403b2e0

Please sign in to comment.