Rewrite the app (#23)

* chore: Removed everything not needed, and added base for rewrite
feat(error_handling): Added 404 general cache
feat(index): Added informations about the app in the / route.

* feat(indexing): Brought back the indexing, with conditions to make it easier

* fix: Fixed build error with a forgotten call

* feat: Add Docker development enviroment (#19)

* ci: add a *lot* of new actions

* fix: rename linting action

* fix: invalid yaml begone(?)

* ci: Added cache to speed up build times

* fix(ci): 🦀ed the yaml errors

* fix(ci): fixed a missing hyphen

* ci: Added matrix of rust versions, and changed way to install rust toolchain

* fix(ci): Added names to build with the matrix so it's easier to find the source of the problem

* style(ci): Added eof lines

* refactor: Finished moving the search.rs file to a separate module.

* Search Endpoint

* refactor: Moved around functions and struct for a better understanding of what it does.

* chore: Change env default settings to resolve conversation

* refactor: Removed #[use_macros]
fix: Fixed meilisearch address from env

* chore: Added email to Aeledfyr

* fix: Brought back the dotenv variables

* style: Ran `cargo fmt`

Co-authored-by: Charalampos Fanoulis <charalampos.fanoulis@gmail.com>
Co-authored-by: Jai A <jai.a@tuta.io>
This commit is contained in:
Valentin Ricard
2020-06-30 19:23:52 +02:00
committed by GitHub
parent 1ff2a08d19
commit 7a6ecd86c6
87 changed files with 881 additions and 3231 deletions

View File

@@ -1,40 +1,40 @@
#[macro_use]
extern crate serde_json;
#[macro_use]
extern crate bson;
#[macro_use]
extern crate log;
use actix_files as fs;
use actix_web::{web, App, HttpServer};
use handlebars::*;
use crate::search::indexing::index_mods;
use actix_web::middleware::Logger;
use actix_web::{web, App, HttpServer};
use env_logger::Env;
use log::info;
use std::env;
use std::fs::File;
mod database;
mod helpers;
mod models;
mod routes;
mod search;
#[actix_rt::main]
async fn main() -> std::io::Result<()> {
env_logger::from_env(Env::default().default_filter_or("info")).init();
dotenv::dotenv().ok();
//Handlebars
let mut handlebars = Handlebars::new();
helpers::register_helpers(&mut handlebars);
handlebars
.register_templates_directory(".hbs", "./templates")
.unwrap();
let handlebars_ref = web::Data::new(handlebars);
let client = database::connect().await.unwrap();
routes::index_mods(client).await.unwrap();
// Get executable path
let mut exe_path = env::current_exe()?.parent().unwrap().to_path_buf();
// Create the path to the index lock file
exe_path.push("index.v1.lock");
//Indexing mods if not already done
if env::args().any(|x| x == "regen") {
// User forced regen of indexing
info!("Forced regeneration of indexes!");
index_mods(client).await.unwrap();
} else if exe_path.exists() {
// The indexes were not created, or the version was upgraded
info!("Indexing of mods for first time...");
index_mods(client).await.unwrap();
// Create the lock file
File::create(exe_path)?;
}
info!("Starting Actix HTTP server!");
@@ -43,15 +43,11 @@ async fn main() -> std::io::Result<()> {
App::new()
.wrap(Logger::default())
.wrap(Logger::new("%a %{User-Agent}i"))
.app_data(handlebars_ref.clone())
.service(fs::Files::new("/static", "./static").show_files_listing())
.service(routes::index_get)
.service(routes::search_post)
.service(routes::search_get)
.service(routes::mod_page_get)
.service(routes::mod_create_get)
.service(routes::mod_search)
.default_service(web::get().to(routes::not_found))
})
.bind("127.0.0.1:8000")?
.bind("127.0.0.1:".to_string() + &dotenv::var("PORT").unwrap())?
.run()
.await
}