#middleware #stack #wasm-file #suika #serve #pre-compiled #web

suika_wasm

A middleware for the suika web stack to serve pre-compiled WebAssembly (Wasm) files

9 releases

new 0.1.8 Jan 8, 2025
0.1.7 Jan 5, 2025

#229 in WebAssembly

Download history 206/week @ 2024-12-27 623/week @ 2025-01-03

829 downloads per month
Used in suika

MIT license

180KB
3K SLoC

Rust 2.5K SLoC // 0.0% comments JavaScript 455 SLoC // 0.0% comments TypeScript 29 SLoC // 0.4% comments

suika_wasm

suika_wasm is a middleware for the Suika web stack to serve pre-compiled WebAssembly (Wasm) files.

Note: Suika is under active development and not intended for production use. The API is subject to change and may lack comprehensive testing and documentation.

use suika::server::{Server, Router};
use suika::middleware::WasmFileMiddleware;
use std::sync::Arc;

pub fn main() {
    let mut server = Server::new("127.0.0.1:8080");
    let mut router = Router::new("/");

    router.get(r"/?$", |_req, res| {
        Box::pin(async move {
            res.set_status(201).await;
            res.body("Hello World!".to_string()).await;
            Ok(())
        })
    });

    server.use_middleware(Arc::new(WasmFileMiddleware::new("/wasm", 86400)));
    server.use_middleware(Arc::new(router));

    server.run();
}

Dependencies

~6–13MB
~157K SLoC