Files
Modrinth-plus/src/main.rs

46 lines
1.0 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]
extern crate diesel;
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-10 22:30:28 -07:00
use actix_files as fs;
2020-05-14 22:53:22 -07:00
mod schema;
mod routes;
mod helpers;
mod database;
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-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-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-14 22:53:22 -07:00
let database = database::connect();
2020-05-20 22:32:57 -07:00
routes::index_mods(database).await;
2020-05-09 22:11:48 -07:00
//Init App
HttpServer::new(move || {
App::new()
.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)
2020-05-16 22:37:02 -07:00
.service(routes::mod_editor_get)
2020-05-09 22:11:48 -07:00
})
.bind("127.0.0.1:8000")?
.run()
2020-05-10 22:30:28 -07:00
.await
2020-05-09 22:11:48 -07:00
}