-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
🧱 Use SSR on the website local server.
- Loading branch information
Showing
7 changed files
with
76 additions
and
55 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
use anyhow::Result; | ||
|
||
use axum::{ | ||
extract::Path, | ||
http::{header, HeaderMap, StatusCode}, | ||
response::IntoResponse, | ||
routing::get, | ||
Router, | ||
}; | ||
|
||
use hikari_boot::Application; | ||
use hikari_website::app::App; | ||
|
||
pub async fn html(url: String) -> Result<impl IntoResponse, (StatusCode, String)> { | ||
let raw = App::render_to_string(url, Default::default()) | ||
.await | ||
.map_err(|err| (StatusCode::INTERNAL_SERVER_ERROR, err.to_string()))?; | ||
let raw = format!( | ||
r#" | ||
<body> | ||
<div id='app'> | ||
<script src='./a.js'></script> | ||
<script> | ||
(async () => {{ | ||
await __wasm_vendor_entry('./a.wasm'); | ||
(await (new __wasm_vendor_entry.WebHandle())).start(); | ||
}})() | ||
</script> | ||
{raw} | ||
</div> | ||
</body>"# | ||
); | ||
|
||
{ | ||
let mut headers = HeaderMap::new(); | ||
headers.insert(header::CONTENT_TYPE, "text/html".parse().unwrap()); | ||
|
||
Ok((headers, raw)) | ||
} | ||
} | ||
|
||
pub async fn route() -> Result<Router> { | ||
let router = Router::new() | ||
.route("/", get(|| async { html("/".to_string()).await })) | ||
.route( | ||
"/guide/:id", | ||
get(move |Path(id): Path<String>| async move { html(format!("/guide/{}", id)).await }), | ||
) | ||
.route( | ||
"/component/:id", | ||
get(move |Path(id): Path<String>| async move { html(format!("/component/{}", id)).await }), | ||
); | ||
|
||
Ok(router) | ||
} |
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