init
This commit is contained in:
51
src/app.rs
Normal file
51
src/app.rs
Normal file
@@ -0,0 +1,51 @@
|
||||
use leptos::logging;
|
||||
use leptos::prelude::*;
|
||||
|
||||
pub fn shell(options: LeptosOptions) -> impl IntoView {
|
||||
use leptos_meta::MetaTags;
|
||||
|
||||
view! {
|
||||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="utf-8" />
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1" />
|
||||
<AutoReload options=options.clone() />
|
||||
<HydrationScripts options />
|
||||
<MetaTags />
|
||||
</head>
|
||||
<body>
|
||||
<App />
|
||||
</body>
|
||||
</html>
|
||||
}
|
||||
}
|
||||
|
||||
#[leptos::component]
|
||||
pub fn App() -> impl leptos::IntoView {
|
||||
use leptos_meta::Stylesheet;
|
||||
use leptos_meta::Title;
|
||||
|
||||
// Provides context that manages stylesheets, titles, meta tags, etc.
|
||||
leptos_meta::provide_meta_context();
|
||||
|
||||
leptos::view! {
|
||||
<Stylesheet id="leptos" href="/pkg/ascend.css" />
|
||||
|
||||
// sets the document title
|
||||
<Title text="Ascend" />
|
||||
|
||||
<Ascend />
|
||||
}
|
||||
}
|
||||
|
||||
#[leptos::component]
|
||||
fn Ascend() -> impl leptos::IntoView {
|
||||
logging::log!("Rendering root component");
|
||||
|
||||
leptos::view! {
|
||||
<div>
|
||||
{ "hello world" }
|
||||
</div>
|
||||
}
|
||||
}
|
||||
16
src/lib.rs
Normal file
16
src/lib.rs
Normal file
@@ -0,0 +1,16 @@
|
||||
pub mod app;
|
||||
pub mod pages {}
|
||||
|
||||
#[cfg(feature = "hydrate")]
|
||||
#[wasm_bindgen::prelude::wasm_bindgen]
|
||||
pub fn hydrate() {
|
||||
use crate::app::*;
|
||||
console_error_panic_hook::set_once();
|
||||
leptos::mount::hydrate_body(App);
|
||||
}
|
||||
|
||||
#[cfg(feature = "ssr")]
|
||||
pub mod server {
|
||||
#[derive(Debug, Clone)]
|
||||
pub struct AppState {}
|
||||
}
|
||||
73
src/main.rs
Normal file
73
src/main.rs
Normal file
@@ -0,0 +1,73 @@
|
||||
#[cfg(feature = "ssr")]
|
||||
mod cli {
|
||||
#[derive(clap::Parser)]
|
||||
#[command(version, about, long_about = None)]
|
||||
pub struct Cli {
|
||||
#[command(subcommand)]
|
||||
pub command: Command,
|
||||
}
|
||||
|
||||
#[derive(clap::Subcommand, Default)]
|
||||
pub enum Command {
|
||||
#[default]
|
||||
Serve,
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(feature = "ssr")]
|
||||
#[tokio::main]
|
||||
async fn main() {
|
||||
use ascend::app::App;
|
||||
use ascend::app::shell;
|
||||
use ascend::server::AppState;
|
||||
use axum::Router;
|
||||
use clap::Parser as _;
|
||||
use leptos::logging;
|
||||
use leptos::prelude::*;
|
||||
use leptos_axum::LeptosRoutes;
|
||||
use leptos_axum::generate_route_list;
|
||||
use tracing_subscriber::EnvFilter;
|
||||
|
||||
tracing_subscriber::fmt()
|
||||
.without_time()
|
||||
.with_env_filter(EnvFilter::from_default_env())
|
||||
.pretty()
|
||||
.init();
|
||||
|
||||
let cli = cli::Cli::parse();
|
||||
match cli.command {
|
||||
cli::Command::Serve => {}
|
||||
}
|
||||
|
||||
// Setting get_configuration(None) means we'll be using cargo-leptos's env values
|
||||
// For deployment these variables are:
|
||||
// <https://github.com/leptos-rs/start-axum#executing-a-server-on-a-remote-machine-without-the-toolchain>
|
||||
// Alternately a file can be specified such as Some("Cargo.toml")
|
||||
// The file would need to be included with the executable when moved to deployment
|
||||
let conf = get_configuration(None).unwrap();
|
||||
let leptos_options = conf.leptos_options;
|
||||
let addr = leptos_options.site_addr;
|
||||
let routes = generate_route_list(App);
|
||||
|
||||
let app_state = AppState {};
|
||||
|
||||
// build our application with a route
|
||||
let app = Router::new()
|
||||
.leptos_routes_with_context(&leptos_options, routes, move || provide_context(app_state.clone()), {
|
||||
let leptos_options = leptos_options.clone();
|
||||
move || shell(leptos_options.clone())
|
||||
})
|
||||
.fallback(leptos_axum::file_and_error_handler(shell))
|
||||
.with_state(leptos_options);
|
||||
|
||||
let listener = tokio::net::TcpListener::bind(&addr).await.unwrap();
|
||||
logging::log!("listening on http://{addr}");
|
||||
axum::serve(listener, app.into_make_service()).await.unwrap();
|
||||
}
|
||||
|
||||
#[cfg(not(feature = "ssr"))]
|
||||
pub fn main() {
|
||||
// no client-side main function
|
||||
// unless we want this to work with e.g., Trunk for a purely client-side app
|
||||
// see lib.rs for hydration function instead
|
||||
}
|
||||
Reference in New Issue
Block a user