Files
Modrinth-plus/src/main.rs

56 lines
1.4 KiB
Rust
Raw Normal View History

2020-05-09 22:11:48 -07:00
#[macro_use]
extern crate serde_json;
2020-05-14 22:53:22 -07:00
#[macro_use]
2020-05-28 13:28:58 -07:00
extern crate bson;
#[macro_use]
extern crate log;
2020-05-14 22:53:22 -07:00
2020-05-27 20:51:28 +02:00
use actix_files as fs;
2020-05-15 22:00:47 -07:00
use actix_web::{web, App, HttpServer};
2020-05-11 22:53:08 -07:00
use handlebars::*;
2020-05-28 13:28:58 -07:00
use actix_web::middleware::Logger;
use env_logger::Env;
2020-05-10 22:30:28 -07:00
2020-05-14 22:53:22 -07:00
mod database;
2020-05-27 20:51:28 +02:00
mod helpers;
mod routes;
2020-05-09 22:11:48 -07:00
#[actix_rt::main]
2020-05-10 22:30:28 -07:00
async fn main() -> std::io::Result<()> {
2020-05-28 13:28:58 -07:00
env_logger::from_env(Env::default().default_filter_or("info")).init();
2020-05-09 22:11:48 -07:00
//Handlebars
let mut handlebars = Handlebars::new();
2020-05-11 22:53:08 -07:00
2020-05-14 22:53:22 -07:00
handlebars.register_helper("contains", Box::new(helpers::ContainsHelper));
2020-05-21 22:38:39 -07:00
handlebars.register_helper("format", Box::new(helpers::HumanFormatHelper));
2020-05-09 22:11:48 -07:00
handlebars
2020-05-10 22:30:28 -07:00
.register_templates_directory(".hbs", "./templates")
2020-05-09 22:11:48 -07:00
.unwrap();
2020-05-11 22:53:08 -07:00
2020-05-09 22:11:48 -07:00
let handlebars_ref = web::Data::new(handlebars);
2020-05-28 13:28:58 -07:00
let client = database::connect().await.unwrap();
2020-06-02 12:03:45 -07:00
routes::index_mods(client).await.unwrap();
2020-05-09 22:11:48 -07:00
2020-05-28 13:28:58 -07:00
info!("Starting Actix HTTP server!");
2020-05-09 22:11:48 -07:00
//Init App
HttpServer::new(move || {
App::new()
2020-05-28 13:28:58 -07:00
.wrap(Logger::default())
.wrap(Logger::new("%a %{User-Agent}i"))
2020-05-09 22:11:48 -07:00
.app_data(handlebars_ref.clone())
2020-05-10 22:30:28 -07:00
.service(fs::Files::new("/static", "./static").show_files_listing())
2020-05-14 22:53:22 -07:00
.service(routes::index_get)
.service(routes::search_post)
.service(routes::search_get)
.service(routes::mod_page_get)
2020-06-20 18:19:19 -07:00
.service(routes::mod_create_get)
2020-05-09 22:11:48 -07:00
})
2020-05-27 20:51:28 +02:00
.bind("127.0.0.1:8000")?
.run()
.await
2020-05-09 22:11:48 -07:00
}