Skip to content

Commit

Permalink
Static linking: Make it possible to set the global current site in wh…
Browse files Browse the repository at this point in the history
…ich to register services
  • Loading branch information
balat committed May 9, 2024
1 parent e7fe205 commit 6209715
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 0 deletions.
2 changes: 2 additions & 0 deletions src/lib/eliom.server.ml
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
let change_site = Eliommod.change_site

let run ?site ?xhr_links ?data_timeout ?service_timeout ?persistent_timeout
?max_service_sessions_per_group ?max_volatile_data_sessions_per_group
?max_persistent_data_sessions_per_group ?max_service_tab_sessions_per_group
Expand Down
3 changes: 3 additions & 0 deletions src/lib/eliom.server.mli
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
val change_site : Ocsigen_server.Site.t -> unit
(** Change the default site in which Eliom services will be registered *)

val run :
?site:Ocsigen_server.Site.t
-> ?xhr_links:bool
Expand Down
27 changes: 27 additions & 0 deletions src/lib/server/eliommod.ml
Original file line number Diff line number Diff line change
Expand Up @@ -692,6 +692,33 @@ let site_init_ref = ref []
(** Register function for evaluation at site initialisation *)
let register_site_init e = site_init_ref := e :: !site_init_ref

let current_site = ref Ocsigen_server.Site.default_host

let get_sitedata =
let module M = Map.Make (struct
type t = Ocsigen_server.Site.t

let compare = compare
end)
in
let r = ref M.empty in
fun site ->
try M.find site !r
with Not_found ->
let sitedata =
let open Ocsigen_server.Site in
let path, hosts = path_and_hosts site in
create_sitedata hosts path (config_info site)
in
r := M.add site sitedata !r;
sitedata

let _ = Eliom_common.absolute_change_sitedata (get_sitedata !current_site)

let change_site s =
current_site := s;
Eliom_common.absolute_change_sitedata (get_sitedata !current_site)

let config = ref []
let config_in_tag = ref "" (* the parent tag of the currently handled tag *)

Expand Down
1 change: 1 addition & 0 deletions src/lib/server/eliommod.mli
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,7 @@ val register_site_init : (unit -> unit) -> unit
val config : Xml_light_types.xml list ref
val config_in_tag : string ref
val site_init : bool ref -> unit
val change_site : Ocsigen_server.Site.t -> unit

val load_eliom_module :
'a
Expand Down

0 comments on commit 6209715

Please sign in to comment.