rust-embed 3.0.2

Rust Custom Derive Macro which loads files into the rust binary at compile time during release and loads the file from the fs during dev
Documentation
extern crate actix_web;
#[macro_use]
extern crate rust_embed;
extern crate mime_guess;

use actix_web::{App, HttpRequest, HttpResponse, server};
use actix_web::http::Method;
use mime_guess::guess_mime_type;

#[derive(RustEmbed)]
#[folder = "examples/public/"]
struct Asset;

fn handle_embedded_file(path: &str) -> HttpResponse {
  match Asset::get(path) {
    Some(content) => {
      HttpResponse::Ok()
        .content_type(guess_mime_type(path).as_ref())
        .body(content)
    }
    None => HttpResponse::NotFound().body("404 Not Found"),
  }
}

fn index(_req: HttpRequest) -> HttpResponse {
  handle_embedded_file("index.html")
}

fn dist(req: HttpRequest) -> HttpResponse {
  let path = &req.path()["/dist/".len()..]; // trim the preceding `/dist/` in path
  handle_embedded_file(path)
}

fn main() {
  server::new(|| {
    App::new().route("/", Method::GET, index).route(
      "/dist/{_:.*}",
      Method::GET,
      dist,
    )
  }).bind("127.0.0.1:8000")
    .unwrap()
    .run();
}