Embed static resources (GUI, assets, images, styles, html) within executable. Serve with hyper or any server of your choice.
pack
. Use simple CLI tool web-static-pack-packer
to create a pack.std::include_bytes
single macro.loader
provides by-name access to files.hyper_loader
allows super-quick integration with hyper-based server.Content-Type
, ETag
(using sha3)Create a pack from cargo doc
:
bash
$ cargo doc --no-deps
$ cargo run ./target/doc/ docs.pack
Serve docs.pack from your web-application (see examples/docs
)
```rust
use failure::Error;
use hyper::service::{makeservicefn, servicefn};
use hyper::{Body, Request, Response, Server};
use lazystatic::lazystatic;
use std::convert::Infallible;
use std::net::SocketAddr;
use webstaticpack::hyperloader::{Responder, StaticBody};
use webstaticpack::loader::Loader;
async fn main() -> () { simplelogger::initwithlevel(log::Level::Info).unwrap(); mainresult().await.unwrap() }
async fn service(request: Request
) -> ResultOk(RESPONDER.request_respond(&request))
}
async fn mainresult() -> Result<(), Error> { let address = SocketAddr::from(([0, 0, 0, 0], 8080)); let server = Server::bind(&address).serve(makeservicefn(|connection| async { Ok::<_, Infallible>(service_fn(service)) }));
log::info!("Server listening on {:?}", address);
Ok(server.await?)
} ```