Created
March 3, 2020 10:52
-
-
Save felipesere/ff1b40810e2204638cfff2f9ca5fde0b to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
let mut app = tide::with_state(state.clone()); | |
app.middleware(RequestLogger::new()); | |
/* | |
app.at("/").get(tide::redirect("/files/index.html")); | |
app.at("/files").strip_prefix().get(StaticFilesEndpoint { | |
root: "./tldr-github-parcel/dist".into(), | |
}); | |
*/ | |
let root_for_files = "./tldr-github-parcel/dist"; | |
let dir = std::fs::read_dir(root_for_files)?; | |
for entry in dir.into_iter() { | |
let entry = entry?; | |
let path = entry.path(); | |
if !path.is_dir() { | |
if let Some(file) = path.file_name() { | |
if file == "index.html" { | |
let protected = Rc::new(path); | |
let x = protected.clone(); | |
app.at("/").get(|_req: Request<State>| async move { | |
let content = async_std::fs::read_to_string(&x).await.expect("Could not read index.html"); | |
Response::new(200).body_string(content).set_header("Content-Type", "text/html") | |
}); | |
} | |
} | |
} | |
} | |
app.at("/").get(|_req: Request<State>| async move { | |
let content = async_std::fs::read_to_string("./tldr-github-parcel/dist/index.html").await.expect("Could not read index.html"); | |
Response::new(200).body_string(content).set_header("Content-Type", "text/html") | |
}); | |
app.at("/main.dd4cbad9.css").get(|_req: Request<State>| async move { | |
let content = async_std::fs::read_to_string("./tldr-github-parcel/dist/main.dd4cbad9.css").await.expect("Could not read css"); | |
Response::new(200).body_string(content).set_header("Content-Type", "text/css") | |
}); | |
app.at("/tldr-github.e833be49.js").get(|_req: Request<State>| async move { | |
let content = async_std::fs::read_to_string("./tldr-github-parcel/dist/tldr-github.e833be49.js").await.expect("Could not read js"); | |
Response::new(200).body_string(content).set_header("Content-Type", "application/javascript") | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Compile error: