Files
Modrinth-plus/src/main.rs

47 lines
1.2 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-10 22:30:28 -07:00
use actix_web::{web, web::Data, App, HttpRequest, HttpResponse, HttpServer, Responder, get, post};
2020-05-11 22:53:08 -07:00
use handlebars::*;
2020-05-10 22:30:28 -07:00
use meilisearch_sdk::{document::*, indexes::*, client::*, search::*};
use serde::{Serialize, Deserialize};
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();
routes::index_mods(database);
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-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
}