Files
iot-cloud-api/src/main.rs
Tobias Maier add82496a6
Some checks failed
Build Project / test (push) Failing after 9m3s
Fixed clippy, updated dependencies
2025-10-17 15:58:52 +00:00

59 lines
1.8 KiB
Rust

use std::{env, path::PathBuf, process};
use actix_web::{web, App, HttpServer};
use database::Database;
use dotenvy::dotenv;
use log::{error, info};
use schemas::AppState;
mod database;
mod device_telemetry_api;
mod firmware_api;
mod schemas;
mod util;
#[actix_web::main]
async fn main() -> std::io::Result<()> {
dotenv().ok();
env_logger::init();
info!("Starting");
let db_url = match env::var("DATABASE_URL") {
Ok(url) => url,
Err(e) => {
error!("Failed reading DATABASE_URL: {e}");
process::exit(1);
}
};
let external_url = env::var("URL").unwrap_or("localhost".to_string());
let firmware_path = env::var("FIRMWARE_PATH").unwrap_or("/firmware".to_string());
info!("External URL: {external_url}");
info!("Firmware path set to: {firmware_path}");
info!("Connecting to Database {db_url}");
let db = Database::init(&db_url).await;
db.init_db().await;
HttpServer::new(move || {
App::new()
.app_data(web::Data::new(AppState {
db: db.clone(),
firmwares_path: PathBuf::from(firmware_path.clone()),
hostname: external_url.clone(),
}))
.app_data(web::PayloadConfig::new(2 * 1024 * 1024 * 1024)) //1GB
.service(device_telemetry_api::receive_telemetry)
.service(device_telemetry_api::get_telemetry)
.service(device_telemetry_api::receive_value)
.service(device_telemetry_api::get_value)
.service(device_telemetry_api::get_devices)
.service(firmware_api::upload_firmware)
.service(firmware_api::get_firmware_json)
.service(firmware_api::serve_firmware)
})
.bind(("0.0.0.0", 8282))?
.run()
.await
}