1#![recursion_limit = "256"]
2#![cfg_attr(docsrs, feature(doc_cfg))]
8
9#[cfg(feature = "ssr")]
17pub mod server;
18
19#[cfg(feature = "ssr")]
20pub fn main(settings: flams_utils::settings::SettingsSpec) {
22 #[allow(unused_imports)]
23 use flams_ftml::FTML;
24 #[allow(unused_imports)]
25 #[cfg(feature = "tantivy")]
26 use flams_search::TANTIVY;
27 #[allow(unused_imports)]
28 use flams_stex::STEX;
29
30 use flams_system::settings::SettingsSpec;
31 fn exit() {
32 flams_system::building::queue_manager::QueueManager::clear();
33 flams_system::settings::Settings::get().close();
34 std::process::exit(0)
35 }
36
37 #[allow(clippy::future_not_send)]
38 async fn run(settings: SettingsSpec) {
39 let lsp = settings.lsp;
40 let _ce = color_eyre::install();
41 flams_system::initialize::<flams_system::TokioEngine>(settings, true);
42 if lsp {
43 let (sender, recv) = tokio::sync::watch::channel(None);
44 tokio::select! {
45 () = crate::server::run(Some(sender)) => {},
46 () = flams_lsp::start_lsp(recv) => {},
47 _ = tokio::signal::ctrl_c() => exit()
48 }
49 } else {
50 tokio::select! {
51 () = crate::server::run(None) => {},
52 _ = tokio::signal::ctrl_c() => exit()
53 }
54 }
55 }
56
57 let mut rt = tokio::runtime::Builder::new_multi_thread();
58 rt.enable_all();
59 if let Some(mb) = settings.stack_size
60 && mb > 2
61 {
62 rt.thread_stack_size((mb as usize) * 1024 * 1024);
63 } else {
64 if settings.lsp {
65 rt.thread_stack_size(4 * 1024 * 1024);
66 }
67 #[cfg(debug_assertions)]
68 {
69 rt.thread_stack_size(if settings.lsp { 6 } else { 4 } * 1024 * 1024);
70 }
71 }
72
73 rt.build()
74 .expect("Failed to initialize Tokio runtime")
75 .block_on(run(settings));
76}
77
78#[cfg(feature = "hydrate")]
79#[wasm_bindgen::prelude::wasm_bindgen]
80pub fn hydrate() {
81 use tracing_subscriber::prelude::*;
82 fn filter(lvl: tracing::Level) -> tracing_subscriber::filter::Targets {
83 tracing_subscriber::filter::Targets::new()
84 .with_target("ftml_dom", lvl)
85 .with_target("ftml_components", lvl)
86 .with_target("ftml_parser", lvl)
87 .with_target("ftml_backend", lvl)
88 .with_target("ftml_ontology", lvl)
89 .with_target("ssr_example", lvl)
90 .with_target("flams_router_base", lvl)
92 .with_target(
93 "leptos_posthoc",
94 tracing_subscriber::filter::LevelFilter::ERROR,
95 )
96 }
97 console_error_panic_hook::set_once();
98 tracing_subscriber::registry()
99 .with(tracing_wasm::WASMLayer::default())
100 .with(filter(tracing::Level::WARN))
101 .init();
102 ftml_components::set_backend::<flams_router_content::backend::FtmlBackend>();
103 ftml_components::set_continuation(&flams_router_content::Continuations);
104 #[cfg(debug_assertions)]
105 {
106 leptos::mount::hydrate_body(flams_router_dashboard::Main);
107 }
108 #[cfg(not(debug_assertions))]
109 {
110 leptos::mount::hydrate_lazy(flams_router_dashboard::Main);
111 }
112}