-
Notifications
You must be signed in to change notification settings - Fork 39
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* refactor: move catch_all in tuono_lib * refactor: moved server to tuono_lib * refactor: move router and server into tuono_lib * refactor: reduce exports from examples * refactor: re-organize exports * refactor: removed mode set on project builder * feat: update version to v0.3.1
- Loading branch information
1 parent
b6d0bb1
commit 9cd90ba
Showing
14 changed files
with
107 additions
and
98 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
[package] | ||
name = "tuono" | ||
version = "0.3.0" | ||
version = "0.3.1" | ||
edition = "2021" | ||
authors = ["V. Ageno <[email protected]>"] | ||
description = "The react/rust fullstack framework" | ||
|
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 |
---|---|---|
@@ -1,6 +1,6 @@ | ||
[package] | ||
name = "tuono_lib" | ||
version = "0.3.0" | ||
version = "0.3.1" | ||
edition = "2021" | ||
authors = ["V. Ageno <[email protected]>"] | ||
description = "The react/rust fullstack framework" | ||
|
@@ -19,14 +19,16 @@ path = "src/lib.rs" | |
|
||
[dependencies] | ||
ssr_rs = "0.5.5" | ||
axum = "0.7.5" | ||
axum = {version = "0.7.5", features = ["json"]} | ||
tokio = { version = "1.37.0", features = ["full"] } | ||
serde = { version = "1.0.202", features = ["derive"] } | ||
erased-serde = "0.4.5" | ||
serde_json = "1.0" | ||
|
||
tuono_lib_macros = {path = "../tuono_lib_macros", version = "0.3.0"} | ||
tuono_lib_macros = {path = "../tuono_lib_macros", version = "0.3.1"} | ||
once_cell = "1.19.0" | ||
lazy_static = "1.5.0" | ||
regex = "1.10.5" | ||
either = "1.13.0" | ||
tower-http = {version = "0.5.2", features = ["fs"]} | ||
|
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,24 @@ | ||
use crate::{ssr::Js, Payload}; | ||
use axum::extract::{Path, Request}; | ||
use axum::response::Html; | ||
use std::collections::HashMap; | ||
|
||
pub async fn catch_all( | ||
Path(params): Path<HashMap<String, String>>, | ||
request: Request, | ||
) -> Html<String> { | ||
let pathname = &request.uri(); | ||
let headers = &request.headers(); | ||
|
||
let req = crate::Request::new(pathname, headers, params); | ||
|
||
// TODO: remove unwrap | ||
let payload = Payload::new(&req, &"").client_payload().unwrap(); | ||
|
||
let result = Js::SSR.with(|ssr| ssr.borrow_mut().render_to_string(Some(&payload))); | ||
|
||
match result { | ||
Ok(html) => Html(html), | ||
_ => Html("500 internal server error".to_string()), | ||
} | ||
} |
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,14 +1,19 @@ | ||
pub mod manifest; | ||
mod catch_all; | ||
mod manifest; | ||
mod mode; | ||
mod payload; | ||
mod request; | ||
mod response; | ||
mod server; | ||
mod ssr; | ||
|
||
pub mod ssr; | ||
|
||
pub use mode::{Mode, GLOBAL_MODE}; | ||
pub use mode::Mode; | ||
pub use payload::Payload; | ||
pub use request::Request; | ||
pub use response::{Props, Response}; | ||
pub use ssr_rs::Ssr; | ||
pub use server::Server; | ||
pub use tuono_lib_macros::handler; | ||
|
||
// Re-exports | ||
pub use axum; | ||
pub use tokio; |
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,53 @@ | ||
use crate::mode::{Mode, GLOBAL_MODE}; | ||
|
||
use crate::manifest::load_manifest; | ||
use axum::routing::{get, Router}; | ||
use ssr_rs::Ssr; | ||
use tower_http::services::ServeDir; | ||
|
||
use crate::catch_all::catch_all; | ||
|
||
const DEV_PUBLIC_DIR: &str = "public"; | ||
const PROD_PUBLIC_DIR: &str = "out/client"; | ||
|
||
pub struct Server { | ||
router: Router, | ||
mode: Mode, | ||
} | ||
|
||
impl Server { | ||
pub fn init(router: Router, mode: Mode) -> Server { | ||
Ssr::create_platform(); | ||
|
||
GLOBAL_MODE.set(mode).unwrap(); | ||
|
||
if mode == Mode::Prod { | ||
load_manifest() | ||
} | ||
|
||
Server { router, mode } | ||
} | ||
|
||
pub async fn start(&self) { | ||
let listener = tokio::net::TcpListener::bind("0.0.0.0:3000").await.unwrap(); | ||
|
||
if self.mode == Mode::Dev { | ||
println!("\nDevelopment app ready at http://localhost:3000/"); | ||
} else { | ||
println!("\nProduction app ready at http://localhost:3000/"); | ||
} | ||
|
||
let public_dir = if self.mode == Mode::Dev { | ||
DEV_PUBLIC_DIR | ||
} else { | ||
PROD_PUBLIC_DIR | ||
}; | ||
|
||
let router = self | ||
.router | ||
.to_owned() | ||
.fallback_service(ServeDir::new(public_dir).fallback(get(catch_all))); | ||
|
||
axum::serve(listener, router).await.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
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