2023-06-04 12:37:22 +02:00
|
|
|
#[cfg(feature = "ssr")]
|
2023-06-04 20:11:02 +02:00
|
|
|
#[tokio::main]
|
|
|
|
async fn main() {
|
|
|
|
use axum::{extract::Extension, routing::post, Router};
|
|
|
|
use como_web::app::*;
|
|
|
|
use como_web::fallback::file_and_error_handler;
|
2023-06-04 12:37:22 +02:00
|
|
|
use leptos::*;
|
2023-06-04 20:11:02 +02:00
|
|
|
use leptos_axum::{generate_route_list, LeptosRoutes};
|
|
|
|
use std::sync::Arc;
|
|
|
|
use tracing_subscriber::EnvFilter;
|
|
|
|
|
|
|
|
std::env::set_var("COMO_GATEWAY_URL", "https://api.como.i.kjuulh.io/graphql");
|
|
|
|
tracing_subscriber::fmt()
|
|
|
|
.with_env_filter(EnvFilter::from_default_env())
|
|
|
|
.init();
|
2023-06-04 12:37:22 +02:00
|
|
|
|
|
|
|
let conf = get_configuration(None).await.unwrap();
|
|
|
|
let addr = conf.leptos_options.site_addr;
|
2023-06-04 20:11:02 +02:00
|
|
|
let leptos_options = conf.leptos_options;
|
2023-06-04 12:37:22 +02:00
|
|
|
// Generate the list of routes in your Leptos App
|
2023-10-20 23:06:21 +02:00
|
|
|
let routes = generate_route_list(App);
|
2023-06-04 20:11:02 +02:00
|
|
|
|
|
|
|
como_web::api::register();
|
2023-06-04 12:37:22 +02:00
|
|
|
|
2023-06-04 20:11:02 +02:00
|
|
|
let app = Router::new()
|
|
|
|
.route("/api/*fn_name", post(leptos_axum::handle_server_fns))
|
2023-10-20 23:06:21 +02:00
|
|
|
.leptos_routes(&leptos_options.clone(), routes, || view! { <App/> })
|
2023-06-04 20:11:02 +02:00
|
|
|
.fallback(file_and_error_handler)
|
2023-10-20 23:06:21 +02:00
|
|
|
.with_state(leptos_options);
|
2023-06-04 12:37:22 +02:00
|
|
|
|
2023-06-04 20:11:02 +02:00
|
|
|
// run our app with hyper
|
|
|
|
// `axum::Server` is a re-export of `hyper::Server`
|
2023-10-20 23:06:21 +02:00
|
|
|
// log!("listening on http://{}", &addr);
|
2023-06-04 20:11:02 +02:00
|
|
|
axum::Server::bind(&addr)
|
|
|
|
.serve(app.into_make_service())
|
|
|
|
.await
|
|
|
|
.unwrap();
|
2023-06-04 12:37:22 +02:00
|
|
|
}
|
|
|
|
|
2023-06-04 20:11:02 +02:00
|
|
|
#[cfg(not(feature = "ssr"))]
|
2023-06-04 12:37:22 +02:00
|
|
|
pub fn main() {
|
|
|
|
// no client-side main function
|
|
|
|
// unless we want this to work with e.g., Trunk for pure client-side testing
|
|
|
|
// see lib.rs for hydration function instead
|
|
|
|
}
|