Adds image route

This commit is contained in:
2025-10-05 21:02:33 +02:00
parent f45900d69d
commit b869e1641b
5 changed files with 96 additions and 4 deletions

View File

@@ -4,6 +4,7 @@ mod models;
mod schema;
use crate::api::hit;
use crate::api::image;
use crate::api::tracker;
use diesel::{Connection, PgConnection};
use std::env;
@@ -16,15 +17,19 @@ fn index() -> &'static str {
"Hello world!"
}
// TODO: add logging
// TODO: add auth
#[launch]
fn rocket() -> _ {
dotenv::dotenv().ok();
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 db = PgConnection::establish(&database_url)
.expect(&format!("Error connecting to {}", database_url));
let app_data = models::AppState::new(db);
let app_data = models::AppState::new(db, image_path);
rocket::build()
.manage(app_data)
.mount("/", routes![index])
@@ -38,4 +43,5 @@ fn rocket() -> _ {
],
)
.mount("/hit", routes![hit::index, hit::get, hit::delete])
.mount("/image", routes![image::get])
}