1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67
use crate::error_pages::ErrorPages;
use crate::i18n::Locales;
use crate::i18n::TranslationsManager;
use crate::state::GlobalStateCreator;
use crate::stores::{ImmutableStore, MutableStore};
use crate::template::ArcTemplateMap;
use crate::SsrNode;
use std::collections::HashMap;
use std::sync::Arc;
use super::HtmlShell;
/// The options for setting up all server integrations. This should be literally
/// constructed, as nothing is optional. If integrations need further
/// properties, they should expose their own options in addition to these.
#[derive(Debug, Clone)]
pub struct ServerOptions {
/// The location on the filesystem of your JavaScript bundle.
pub js_bundle: String,
/// The location on the filesystem of your Wasm bundle.
pub wasm_bundle: String,
/// The location on the filesystem of your JS bundle converted from your
/// Wasm bundle. This isn't required, and if you haven't generated this, you
/// should provide a fake path.
pub wasm_js_bundle: String,
/// The HTML shell to interpolate Perseus into.
pub html_shell: HtmlShell,
/// A `HashMap` of your app's templates by their paths.
pub templates_map: ArcTemplateMap<SsrNode>,
/// The locales information for the app.
pub locales: Locales,
/// The HTML `id` of the element at which to render Perseus. On the
/// server-side, interpolation will be done here in a highly
/// efficient manner by not parsing the HTML, so this MUST be of the form
/// `<div id="root_id">` in your markup (double or single
/// quotes, `root_id` replaced by what this property is set to).
pub root_id: String,
/// The location of the JS interop snippets to be served as static files.
pub snippets: String,
/// The error pages for the app. These will be server-rendered if an initial
/// load fails.
pub error_pages: Arc<ErrorPages<SsrNode>>,
/// The directory to serve static content from, which will be mapped to
/// `/.perseus/static`in the browser.
pub static_dir: Option<String>,
/// A map of URLs to act as aliases for certain static resources. These are
/// particularly designed for things like a site manifest or
/// favicons, which should be stored in a static directory, but need to be
/// aliased at a path like `/favicon.ico`.
pub static_aliases: HashMap<String, String>,
}
/// The full set of properties that all server integrations take.
#[derive(Debug, Clone)]
pub struct ServerProps<M: MutableStore, T: TranslationsManager> {
/// The options for setting up the server.
pub opts: ServerOptions,
/// An immutable store to use.
pub immutable_store: ImmutableStore,
/// A mutable store to use.
pub mutable_store: M,
/// A translations manager to use.
pub translations_manager: T,
/// The global state creator. This is used to avoid issues with `async` and
/// cloning in Actix Web.
pub global_state_creator: Arc<GlobalStateCreator>,
}