shared-framework 0.0.17

Reusable building blocks for HTTP services — Hyper routing, SeaORM data layer, validation, OpenAPI docs, jobs, queues, cache.
Documentation
//! Bundled Swagger UI assets served by the documentation controller.
//!
//! The files under `doc/static/` are compiled into the binary via
//! `include_bytes!`, so the documentation UI resolves regardless of the
//! process working directory. Filesystem lookup under [`FS_DIR`] is kept as a
//! fallback so locally edited assets are picked up without a rebuild.
//!
//! Use [`lookup`] to resolve an asset name to its content type and bytes, or
//! [`FS_DIR`] when reading the same files from disk.

/// Filesystem directory (relative to the crate root) holding the same assets.
/// Used as a fallback when the process runs with the crate root as cwd.
pub const FS_DIR: &str = "doc/static";

/// Returns `(content_type, bytes)` for a bundled asset, or `None` if unknown.
///
/// An empty name resolves to `index.html`. The returned content type is the
/// MIME type to send (for example `"text/html"` or `"text/css"`).
/// Returns `None` for names with no bundled file.
pub fn lookup(name: &str) -> Option<(&'static str, &'static [u8])> {
    let name = name.trim_start_matches('/');
    let key = if name.is_empty() { "index.html" } else { name };
    match key {
        "index.html" => Some(("text/html", include_bytes!("static/index.html"))),
        "index.css" => Some(("text/css", include_bytes!("static/index.css"))),
        "swagger-ui.css" => Some(("text/css", include_bytes!("static/swagger-ui.css"))),
        "swagger-ui.js" => Some(("application/javascript", include_bytes!("static/swagger-ui.js"))),
        "swagger-ui-bundle.js" => {
            Some(("application/javascript", include_bytes!("static/swagger-ui-bundle.js")))
        }
        "swagger-ui-standalone-preset.js" => Some((
            "application/javascript",
            include_bytes!("static/swagger-ui-standalone-preset.js"),
        )),
        "swagger-ui-es-bundle.js" => Some((
            "application/javascript",
            include_bytes!("static/swagger-ui-es-bundle.js"),
        )),
        "swagger-ui-es-bundle-core.js" => Some((
            "application/javascript",
            include_bytes!("static/swagger-ui-es-bundle-core.js"),
        )),
        "swagger-initializer.js" => Some((
            "application/javascript",
            include_bytes!("static/swagger-initializer.js"),
        )),
        "oauth2-redirect.html" => {
            Some(("text/html", include_bytes!("static/oauth2-redirect.html")))
        }
        "oauth2-redirect.js" => Some((
            "application/javascript",
            include_bytes!("static/oauth2-redirect.js"),
        )),
        "favicon-16x16.png" => {
            Some(("image/png", include_bytes!("static/favicon-16x16.png")))
        }
        "favicon-32x32.png" => {
            Some(("image/png", include_bytes!("static/favicon-32x32.png")))
        }
        _ => None,
    }
}