controller/src/main.rs

48 lines
1.3 KiB
Rust
Raw Normal View History

2021-11-04 22:37:16 +00:00
#[macro_use]
extern crate diesel;
#[macro_use]
extern crate diesel_migrations;
extern crate dotenv;
2021-11-06 13:54:45 +00:00
use actix_web::{middleware, web, App, HttpServer};
use actix_web::middleware::normalize::TrailingSlash;
use env_logger::{Builder, Env};
2021-11-05 15:32:30 +00:00
mod db;
mod handlers;
mod types;
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();
2021-11-04 22:37:16 +00:00
HttpServer::new(|| {
App::new()
2021-11-06 13:54:45 +00:00
.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))
2021-11-04 22:37:16 +00:00
.route(
"/api/v1/schedules",
web::get().to(handlers::v1::schedules::index),
)
.route(
"/api/v1/schedules",
web::post().to(handlers::v1::schedules::add),
)
2021-11-05 15:32:30 +00:00
.service(handlers::v1::schedules::show)
2021-11-04 22:37:16 +00:00
.route(
"/api/v1/schedules/{id}",
web::delete().to(handlers::v1::schedules::delete),
)
})
.bind("127.0.0.1:5000")?
.run()
.await
}