-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
a84e377
commit c78ac31
Showing
7 changed files
with
112 additions
and
8 deletions.
There are no files selected for viewing
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
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
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
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
use futures_util::StreamExt; | ||
use std::path::PathBuf; | ||
use titan_core::Service; | ||
|
||
use titan_http::body::Body; | ||
use titan_http::header; | ||
use titan_http::Request; | ||
|
||
pub async fn build_static(app: crate::App, path: PathBuf) { | ||
let inner_app = app.into_inner(); | ||
|
||
for route in inner_app.router.into_iter() { | ||
if route.0.num_params() != 0 { | ||
panic!("Error: Can't statically build a dynamic path: {}", route.0) | ||
} | ||
|
||
println!("Route: {}", route.0); | ||
|
||
let request = Request::new(Box::new([])); | ||
|
||
let response = match route.1.clone().call(request).await { | ||
Ok(value) => value, | ||
Err(err) => { | ||
panic!("Handler error in path: {:?}", route.0) | ||
} | ||
}; | ||
|
||
let (parts, body) = response.into_parts(); | ||
|
||
let bodyv2 = match body { | ||
Body::Full(body) => body, | ||
Body::Stream(mut stream) => { | ||
let mut full_body_message = Vec::default(); | ||
while let Some(value) = stream.next().await { | ||
full_body_message.extend(value) | ||
} | ||
|
||
full_body_message.into_boxed_slice() | ||
} | ||
}; | ||
if let Some(value) = parts.headers.get(header::CONTENT_TYPE) { | ||
if value | ||
!= header::HeaderValue::from_str(titan_http::mime::HTML.as_str()) | ||
.unwrap() | ||
{ | ||
panic!("only works on html for now"); | ||
} | ||
} else { | ||
panic!("wtf"); | ||
} | ||
|
||
let text_string = String::from_utf8(bodyv2.to_vec()).unwrap(); | ||
|
||
let mut path = route.0.to_string(); | ||
|
||
path.push_str(".html"); | ||
|
||
let mut this_path = path.clone(); | ||
|
||
this_path.push_str(&path); | ||
|
||
let mut nice = std::fs::OpenOptions::new() | ||
.create(true) | ||
.write(true) | ||
.open(this_path) | ||
.unwrap(); | ||
|
||
use std::io::Write; | ||
nice.write_all(text_string.as_bytes()).unwrap(); | ||
} | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,5 @@ | ||
mod app; | ||
pub mod build; | ||
pub mod guard; | ||
pub mod prelude; | ||
pub mod route; | ||
|