2024-06-23 20:15:33 +02:00
|
|
|
use crate::{Mode, GLOBAL_MODE};
|
|
|
|
|
use lazy_static::lazy_static;
|
2024-05-18 20:45:35 +02:00
|
|
|
use ssr_rs::Ssr;
|
|
|
|
|
use std::cell::RefCell;
|
|
|
|
|
use std::fs::read_to_string;
|
2024-06-23 20:15:33 +02:00
|
|
|
use std::path::PathBuf;
|
|
|
|
|
|
|
|
|
|
lazy_static! {
|
|
|
|
|
static ref BUNDLE_PATH: &'static str = {
|
|
|
|
|
if GLOBAL_MODE.get().unwrap() == &Mode::Dev {
|
|
|
|
|
return "./.tuono/server/dev-server.js";
|
|
|
|
|
}
|
|
|
|
|
"./out/server/prod-server.js"
|
|
|
|
|
};
|
|
|
|
|
}
|
2024-05-18 20:45:35 +02:00
|
|
|
|
|
|
|
|
pub struct Js;
|
2024-05-23 22:32:43 +02:00
|
|
|
|
2024-05-18 20:45:35 +02:00
|
|
|
impl Js {
|
|
|
|
|
thread_local! {
|
|
|
|
|
pub static SSR: RefCell<Ssr<'static, 'static>> = RefCell::new(
|
|
|
|
|
Ssr::from(
|
2024-06-23 20:15:33 +02:00
|
|
|
read_to_string(PathBuf::from(*BUNDLE_PATH)).expect("Server bundle not found"), ""
|
2024-05-18 20:45:35 +02:00
|
|
|
).unwrap()
|
|
|
|
|
)
|
|
|
|
|
}
|
|
|
|
|
}
|