fix preact routes by serving index.html for any 404
This commit is contained in:
parent
da384ceeb8
commit
35a912bd7a
14
src/main.rs
14
src/main.rs
|
@ -15,7 +15,11 @@ pub mod models;
|
|||
pub mod schema;
|
||||
|
||||
use chrono::prelude::*;
|
||||
use rocket::{http::RawStr, State};
|
||||
use rocket::{
|
||||
http::RawStr,
|
||||
response::{NamedFile, Redirect},
|
||||
State,
|
||||
};
|
||||
use std::{
|
||||
collections::BTreeMap,
|
||||
fmt::Display,
|
||||
|
@ -77,6 +81,11 @@ fn log_get(device_name: &RawStr, conn: DbConn) -> Result<String, anyhow::Error>
|
|||
Ok(lines)
|
||||
}
|
||||
|
||||
#[catch(404)]
|
||||
fn not_found() -> Option<NamedFile> {
|
||||
NamedFile::open("frontend/build/index.html").ok()
|
||||
}
|
||||
|
||||
fn main() {
|
||||
rocket::ignite()
|
||||
.attach(DbConn::fairing())
|
||||
|
@ -84,7 +93,8 @@ fn main() {
|
|||
"/",
|
||||
rocket_contrib::serve::StaticFiles::from("frontend/build"),
|
||||
)
|
||||
.mount("/", routes![log_new, log_get])
|
||||
.mount("/api", routes![log_new, log_get])
|
||||
.register(catchers![not_found])
|
||||
.launch();
|
||||
|
||||
println!("after");
|
||||
|
|
Loading…
Reference in New Issue