52 lines
1.3 KiB
Rust
52 lines
1.3 KiB
Rust
//! Модуль веб сервера.
|
|
//!
|
|
//! Все модули отвечают только за Web сторону. Такие вещи как
|
|
//! [crate::web_server::old_device_sensor_api] отвечают только за веб версию.
|
|
//!
|
|
//! TODO: Начать работу над TCP/UDP и MQTT сервером
|
|
|
|
use fred::bytes_utils::Str;
|
|
use fred::prelude::*;
|
|
use fred::clients::Client as RedisClient;
|
|
|
|
use old_app_api::old_api_handler;
|
|
|
|
pub mod app_error;
|
|
pub mod old_app_api;
|
|
pub mod old_device_sensor_api;
|
|
pub mod utils;
|
|
|
|
#[derive(Clone)]
|
|
pub struct NMAppState {
|
|
pub redis_client: RedisClient,
|
|
}
|
|
|
|
use crate::web_server::old_device_sensor_api::device_handler;
|
|
|
|
use ntex::web;
|
|
|
|
pub async fn server_main() {
|
|
let client = RedisClient::default();
|
|
client.init().await.unwrap();
|
|
|
|
let asd: Str = client.ping(None).await.unwrap();
|
|
|
|
println!("Ping result: {}", asd);
|
|
|
|
let state = NMAppState {
|
|
redis_client: client,
|
|
};
|
|
|
|
web::HttpServer::new(move || {
|
|
web::App::new()
|
|
.state(state.clone())
|
|
.route("/api", web::post().to(old_api_handler))
|
|
.route("/get", web::route().to(device_handler))
|
|
.route("/post", web::route().to(device_handler))
|
|
})
|
|
.bind(("127.0.0.1", 8080))
|
|
.unwrap()
|
|
.run()
|
|
.await
|
|
.unwrap(); // TODO figure out how to handle what
|
|
}
|