1:- module(dotcloud, [server/1, server/2]).    2:- reexport(library(http/http_dispatch)).    3
    4:- use_module(library(http/thread_httpd)).    5:- use_module(library(http/http_dispatch)).
 server(+Service:atom, :Goal) is det
Start HTTP service named Service. Service should match the name of a service configured in your dotloud.yml file. During deployment, dotCloud assigns a port on which the service must listen.

For convenience during development, if the environment variable 'PORT_$Service' is not set, listen on port 3000.

   16:- meta_predicate server(+,1).   17server(ServiceAtom, Goal) :-
   18    % on which port should we listen?
   19    upcase_atom(ServiceAtom, ServiceName),
   20    format(atom(Env), 'PORT_~w', [ServiceName]),
   21    getenv_default(Env, '3000', PortAtom),
   22    atom_number(PortAtom, Port),
   23
   24    % start an HTTP server there
   25    http_server(Goal, [port(Port), keep_alive_timeout(1)]),
   26    format('Listening on port ~d~n', [Port]),
   27    format(atom(Thread), 'http@~d', [Port]),
   28
   29    % wait for the server to exit
   30    thread_join(Thread, _).
 server(+ServiceAtom:atom) is det
Like server/2 but uses http_dispatch/1 as the Goal.
   36server(ServiceAtom) :-
   37    server(ServiceAtom, http_dispatch).
   38
   39
   40% retrieve an environment variable with a fallback default value
   41getenv_default(Name, Default, Value) :-
   42    ( getenv(Name, Value0) ->
   43        Value = Value0
   44    ; true ->
   45        debug(dotcloud, 'No ~w environment. Defaulting to ~w', [Name, Default]),
   46        Value = Default
   47    )