crablog/site/src/main.rs

39 lines
1 KiB
Rust
Raw Normal View History

2020-10-25 23:23:32 +01:00
mod api;
2020-10-22 23:51:20 +02:00
mod config;
2020-10-22 00:17:52 +02:00
mod db;
mod routes;
#[macro_use]
extern crate diesel;
extern crate chrono;
extern crate serde_derive;
extern crate tera;
use actix_files as fs;
2020-10-22 23:51:20 +02:00
use actix_web::{App, HttpServer};
2020-10-23 00:55:27 +02:00
use config::get_from_env;
2020-10-22 00:17:52 +02:00
#[actix_web::main]
async fn main() -> std::io::Result<()> {
HttpServer::new(|| {
2020-10-23 00:55:27 +02:00
let root_path = get_from_env("ROOT_PATH", true);
2020-10-22 00:17:52 +02:00
App::new()
.service(routes::root)
.service(routes::blog)
2020-10-25 23:23:32 +01:00
.service(routes::blog_by_id)
.service(routes::blog_submit)
2020-10-25 23:23:32 +01:00
.service(routes::blog_edit)
.service(routes::blog_edit_by_id)
.service(api::blog_get_posts_json)
.service(api::blog_create_post)
.service(api::blog_edit_post)
.service(api::blog_hide_post)
.service(api::blog_delete_post)
2020-10-22 23:51:20 +02:00
.service(fs::Files::new("/static", root_path + "/static"))
2020-10-22 00:17:52 +02:00
})
2020-10-23 00:55:27 +02:00
.bind(String::from("localhost:") + &get_from_env("BIND_PORT", true))?
2020-10-22 00:17:52 +02:00
.run()
.await
}