|
|
@@ -2,6 +2,7 @@ use actix_web::{HttpServer, web, middleware, App};
|
|
|
use actix_cors::Cors;
|
|
|
use sqlx::PgPool;
|
|
|
use rumqttc::{MqttOptions, AsyncClient};
|
|
|
+use std::env;
|
|
|
use crate::app_error::AppError;
|
|
|
|
|
|
mod app_error;
|
|
|
@@ -13,6 +14,14 @@ mod auth;
|
|
|
|
|
|
#[actix_web::main]
|
|
|
async fn main() -> Result<(), AppError> {
|
|
|
+ //Environment variables
|
|
|
+ dotenvy::dotenv().expect("Failed to load .env file");
|
|
|
+
|
|
|
+ let port:u16 = env::var("PORT")
|
|
|
+ .expect("Environment variable PORT not set")
|
|
|
+ .parse()
|
|
|
+ .expect("PORT must be a valid number");
|
|
|
+
|
|
|
//MQTT
|
|
|
let mut options = MqttOptions::new("actix_server", "localhost", 1883);
|
|
|
options.set_keep_alive(std::time::Duration::from_secs(10));
|
|
|
@@ -64,7 +73,7 @@ async fn main() -> Result<(), AppError> {
|
|
|
.configure(routes::home::config)
|
|
|
.configure(routes::device::config)
|
|
|
})
|
|
|
- .bind(("0.0.0.0", 8000))
|
|
|
+ .bind(("0.0.0.0", port))
|
|
|
.expect("Failed to bind to port")
|
|
|
.run()
|
|
|
.await
|