controller/src/main.rs

53 lines
1.6 KiB
Rust

#[macro_use]
extern crate diesel;
#[macro_use]
extern crate diesel_migrations;
extern crate core;
extern crate dotenv;
use actix_web::middleware::normalize::TrailingSlash;
use actix_web::{middleware, web, App, HttpServer};
use env_logger::{Builder, Env};
use wiringpi::pin::Value::High;
mod db;
mod handlers;
mod return_models;
mod types;
mod utils;
#[actix_web::main]
async fn main() -> std::io::Result<()> {
db::run_migrations();
Builder::from_env(Env::default().default_filter_or("info")).init();
let pi = wiringpi::setup();
//Use WiringPi pin 0 as output
let pin = pi.output_pin(0);
pin.digital_write(High);
HttpServer::new(|| {
App::new()
.wrap(
middleware::DefaultHeaders::new()
.header("Access-Control-Allow-Origin", "*")
.header("Access-Control-Allow-Headers", "*")
.header("Access-Control-Allow-Methods", "*"),
)
.wrap(middleware::Logger::default())
.wrap(middleware::NormalizePath::new(TrailingSlash::Trim))
.app_data(web::JsonConfig::default().error_handler(handlers::json_error_handler))
.service(handlers::v1::schedules::index)
.service(handlers::v1::schedules::tagged)
.service(handlers::v1::schedules::show)
.service(handlers::v1::schedules::add)
.service(handlers::v1::schedules::add_list)
.service(handlers::v1::schedules::update)
.service(handlers::v1::schedules::delete)
})
.bind("127.0.0.1:5000")?
.run()
.await
}