diff --git a/src/api/image.rs b/src/api/image.rs index f307983..ae19146 100644 --- a/src/api/image.rs +++ b/src/api/image.rs @@ -78,7 +78,7 @@ pub async fn get(id: &str, meta: ReqMeta, state: &State) -> Result &'static str { - "Hello world!" +async fn index(state: &State) -> Result { + NamedFile::open(Path::new(state.static_dir.as_str()).join("index.html")) + .await + .map_err(|_| Status::InternalServerError) } -// TODO: add auth - fn setup_logging() -> Result<(), fern::InitError> { let level_raw = env::var("LOG_LEVEL").unwrap_or("INFO".to_string()); let level = log::LevelFilter::from_str(&level_raw).expect("LOG_LEVEL invalid"); @@ -49,11 +54,11 @@ fn rocket() -> _ { setup_logging().expect("Failed to setup logging"); let database_url = env::var("DATABASE_URL").expect("DATABASE_URL must be set"); - let image_path = env::var("IMAGE_PATH").expect("IMAGE_PATH must be set"); + let static_dir = env::var("STATIC_DIR").expect("STATIC_DIR must be set"); let db = PgConnection::establish(&database_url) .expect(&format!("Error connecting to {}", database_url)); - let app_data = models::AppState::new(db, image_path); + let app_data = AppState::new(db, static_dir); rocket::build() .manage(app_data) .mount("/", routes![index]) diff --git a/src/models/mod.rs b/src/models/mod.rs index a6007e0..2cd6f1e 100644 --- a/src/models/mod.rs +++ b/src/models/mod.rs @@ -6,14 +6,14 @@ pub mod tracker; pub struct AppState { pub db: Arc>, - pub image_path: String, + pub static_dir: String, } impl AppState { - pub fn new(db: PgConnection, image_path: String) -> Self { + pub fn new(db: PgConnection, static_dir: String) -> Self { AppState { db: Arc::new(Mutex::new(db)), - image_path, + static_dir, } } } diff --git a/static/index.html b/static/index.html new file mode 100644 index 0000000..b1d94c8 --- /dev/null +++ b/static/index.html @@ -0,0 +1,147 @@ + + + + + + Setra + + + +
+

Setra

+ +
+ + + + +
+ +
+
+ + + + +
+
+
+ + + +