2021-11-04 22:37:16 +00:00
|
|
|
#[macro_use]
|
|
|
|
extern crate diesel;
|
|
|
|
#[macro_use]
|
|
|
|
extern crate diesel_migrations;
|
2022-04-02 23:35:51 +00:00
|
|
|
extern crate core;
|
2022-07-17 18:19:36 +00:00
|
|
|
extern crate dotenv;
|
2021-11-04 22:37:16 +00:00
|
|
|
|
2021-11-06 13:54:45 +00:00
|
|
|
use actix_web::middleware::normalize::TrailingSlash;
|
2022-07-17 18:19:36 +00:00
|
|
|
use actix_web::{middleware, web, App, HttpServer};
|
2021-11-06 13:54:45 +00:00
|
|
|
use env_logger::{Builder, Env};
|
2022-04-15 00:11:34 +00:00
|
|
|
use wiringpi::pin::Value::High;
|
2021-11-05 15:32:30 +00:00
|
|
|
|
|
|
|
mod db;
|
|
|
|
mod handlers;
|
2022-04-02 23:35:51 +00:00
|
|
|
mod return_models;
|
2021-11-05 15:32:30 +00:00
|
|
|
mod types;
|
2022-07-17 18:19:36 +00:00
|
|
|
mod utils;
|
2021-11-04 22:37:16 +00:00
|
|
|
|
|
|
|
#[actix_web::main]
|
|
|
|
async fn main() -> std::io::Result<()> {
|
|
|
|
db::run_migrations();
|
|
|
|
|
2021-11-06 13:54:45 +00:00
|
|
|
Builder::from_env(Env::default().default_filter_or("info")).init();
|
|
|
|
|
2022-04-15 00:11:34 +00:00
|
|
|
let pi = wiringpi::setup();
|
|
|
|
|
|
|
|
//Use WiringPi pin 0 as output
|
|
|
|
let pin = pi.output_pin(0);
|
|
|
|
pin.digital_write(High);
|
|
|
|
|
2021-11-04 22:37:16 +00:00
|
|
|
HttpServer::new(|| {
|
|
|
|
App::new()
|
2022-07-17 18:19:36 +00:00
|
|
|
.wrap(
|
|
|
|
middleware::DefaultHeaders::new()
|
|
|
|
.header("Access-Control-Allow-Origin", "*")
|
|
|
|
.header("Access-Control-Allow-Headers", "*")
|
|
|
|
.header("Access-Control-Allow-Methods", "*"),
|
2021-11-06 13:54:45 +00:00
|
|
|
)
|
|
|
|
.wrap(middleware::Logger::default())
|
|
|
|
.wrap(middleware::NormalizePath::new(TrailingSlash::Trim))
|
2021-11-08 12:11:20 +00:00
|
|
|
.app_data(web::JsonConfig::default().error_handler(handlers::json_error_handler))
|
2022-04-03 16:39:31 +00:00
|
|
|
.service(handlers::v1::schedules::index)
|
|
|
|
.service(handlers::v1::schedules::tagged)
|
2021-11-05 15:32:30 +00:00
|
|
|
.service(handlers::v1::schedules::show)
|
2022-04-03 16:39:31 +00:00
|
|
|
.service(handlers::v1::schedules::add)
|
2022-07-17 18:19:36 +00:00
|
|
|
.service(handlers::v1::schedules::add_list)
|
2022-04-03 16:39:31 +00:00
|
|
|
.service(handlers::v1::schedules::update)
|
2021-11-08 12:11:20 +00:00
|
|
|
.service(handlers::v1::schedules::delete)
|
2021-11-04 22:37:16 +00:00
|
|
|
})
|
|
|
|
.bind("127.0.0.1:5000")?
|
|
|
|
.run()
|
|
|
|
.await
|
|
|
|
}
|