fix(Leptos): Explicitly tell Leptos where to find the configuration
This commit is contained in:
parent
0f28394fce
commit
09dd736082
1 changed files with 11 additions and 4 deletions
15
src/main.rs
15
src/main.rs
|
@ -3,9 +3,10 @@ use actix_web::{web, HttpResponse, Responder};
|
||||||
use std::sync::Arc;
|
use std::sync::Arc;
|
||||||
use tokio::sync::Mutex;
|
use tokio::sync::Mutex;
|
||||||
use compareware::db::Database;
|
use compareware::db::Database;
|
||||||
use compareware::api::{ItemRequest,create_item, get_items, get_selected_properties, add_selected_property};
|
use compareware::api::{ItemRequest, create_item, get_items, get_selected_properties, add_selected_property};
|
||||||
use compareware::models::item::Item;
|
use compareware::models::item::Item;
|
||||||
|
|
||||||
|
#[cfg(feature = "ssr")]
|
||||||
#[actix_web::main]
|
#[actix_web::main]
|
||||||
async fn main() -> std::io::Result<()> {
|
async fn main() -> std::io::Result<()> {
|
||||||
use actix_files::Files;
|
use actix_files::Files;
|
||||||
|
@ -18,17 +19,19 @@ async fn main() -> std::io::Result<()> {
|
||||||
use std::sync::Arc;
|
use std::sync::Arc;
|
||||||
use tokio::sync::Mutex;
|
use tokio::sync::Mutex;
|
||||||
|
|
||||||
|
// Setup logging
|
||||||
|
std::env::set_var("RUST_LOG", "info");
|
||||||
|
|
||||||
// Initialize the database
|
// Initialize the database
|
||||||
let db = Database::new("compareware.db").unwrap();
|
let db = Database::new("compareware.db").unwrap();
|
||||||
db.create_schema().await.unwrap(); // Ensure the schema is created
|
db.create_schema().await.unwrap(); // Ensure the schema is created
|
||||||
let db = Arc::new(Mutex::new(db)); // Wrap the database in an Arc<Mutex<T>> for shared state
|
let db = Arc::new(Mutex::new(db)); // Wrap the database in an Arc<Mutex<T>> for shared state
|
||||||
println!("Schema created successfully!");
|
println!("Schema created successfully!");
|
||||||
|
|
||||||
// Load configuration
|
// Load configuration
|
||||||
let conf = get_configuration(None).await.unwrap();
|
let conf = get_configuration(Some("Cargo.toml")).await.unwrap();
|
||||||
let addr = conf.leptos_options.site_addr;
|
let addr = conf.leptos_options.site_addr;
|
||||||
|
|
||||||
|
|
||||||
// Generate the list of routes in your Leptos App
|
// Generate the list of routes in your Leptos App
|
||||||
let routes = generate_route_list(App);
|
let routes = generate_route_list(App);
|
||||||
println!("listening on http://{}", &addr);
|
println!("listening on http://{}", &addr);
|
||||||
|
@ -79,6 +82,7 @@ async fn main() -> std::io::Result<()> {
|
||||||
.await
|
.await
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[cfg(feature = "ssr")]
|
||||||
// Handler to get items for a specific URL
|
// Handler to get items for a specific URL
|
||||||
async fn get_items_handler(
|
async fn get_items_handler(
|
||||||
db: web::Data<Arc<Mutex<Database>>>,
|
db: web::Data<Arc<Mutex<Database>>>,
|
||||||
|
@ -87,6 +91,7 @@ async fn get_items_handler(
|
||||||
get_items(db, web::Query(url.into_inner())).await
|
get_items(db, web::Query(url.into_inner())).await
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[cfg(feature = "ssr")]
|
||||||
// Handler to create an item for a specific URL
|
// Handler to create an item for a specific URL
|
||||||
async fn create_item_handler(
|
async fn create_item_handler(
|
||||||
db: web::Data<Arc<Mutex<Database>>>,
|
db: web::Data<Arc<Mutex<Database>>>,
|
||||||
|
@ -125,11 +130,13 @@ async fn add_selected_property_handler(
|
||||||
) -> impl Responder {
|
) -> impl Responder {
|
||||||
add_selected_property(db, url, property).await
|
add_selected_property(db, url, property).await
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(feature = "ssr")]
|
#[cfg(feature = "ssr")]
|
||||||
// Define the index handler
|
// Define the index handler
|
||||||
async fn index() -> HttpResponse {
|
async fn index() -> HttpResponse {
|
||||||
HttpResponse::Ok().body("Welcome to CompareWare!")
|
HttpResponse::Ok().body("Welcome to CompareWare!")
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(feature = "ssr")]
|
#[cfg(feature = "ssr")]
|
||||||
// Define the URL handler
|
// Define the URL handler
|
||||||
async fn url_handler(url: web::Path<String>) -> HttpResponse {
|
async fn url_handler(url: web::Path<String>) -> HttpResponse {
|
||||||
|
|
Loading…
Add table
Reference in a new issue