Add all connectors
This commit is contained in:
@ -1,5 +1,79 @@
|
||||
fn main() {
|
||||
use actix_cors::Cors;
|
||||
use actix_multipart::form::tempfile::TempFileConfig;
|
||||
use actix_remote_ip::RemoteIPConfig;
|
||||
use actix_session::SessionMiddleware;
|
||||
use actix_session::config::SessionLifecycle;
|
||||
use actix_session::storage::RedisSessionStore;
|
||||
use actix_web::cookie::Key;
|
||||
use actix_web::middleware::Logger;
|
||||
use actix_web::{App, HttpServer, web};
|
||||
use moneymgr_backend::app_config::AppConfig;
|
||||
use moneymgr_backend::connections::{db_connection, s3_connection};
|
||||
use moneymgr_backend::controllers::server_controller;
|
||||
use moneymgr_backend::routines;
|
||||
use moneymgr_backend::services::users_service;
|
||||
|
||||
#[actix_web::main]
|
||||
async fn main() -> std::io::Result<()> {
|
||||
env_logger::init_from_env(env_logger::Env::new().default_filter_or("info"));
|
||||
|
||||
println!("Hello, world!");
|
||||
log::info!(
|
||||
"Money manager server, start to listen on {}",
|
||||
AppConfig::get().listen_address
|
||||
);
|
||||
|
||||
// Initialize bucket
|
||||
log::info!("Initialize S3 bucket");
|
||||
s3_connection::create_bucket_if_required()
|
||||
.await
|
||||
.expect("Failed to initialize S3 bucket!");
|
||||
|
||||
// Connect to Redis
|
||||
let cookie_secret_key = Key::from(AppConfig::get().secret().as_bytes());
|
||||
let redis_store = RedisSessionStore::new(AppConfig::get().redis_connection_string())
|
||||
.await
|
||||
.expect("Failed to connect to Redis!");
|
||||
|
||||
// Initialize database connection
|
||||
db_connection::initialize_conn().expect("Failed to connect to PostgresSQL database!");
|
||||
|
||||
// Auto create default account, if requested
|
||||
if let Some(mail) = &AppConfig::get().unsecure_auto_login_email {
|
||||
users_service::create_or_update_user(mail, "Anonymous")
|
||||
.await
|
||||
.expect("Failed to create default account!");
|
||||
}
|
||||
|
||||
// Automatically execute routines
|
||||
tokio::spawn(routines::main_routine());
|
||||
|
||||
HttpServer::new(move || {
|
||||
let session_mw = SessionMiddleware::builder(redis_store.clone(), cookie_secret_key.clone())
|
||||
.cookie_name("matrixgw-session".to_string())
|
||||
.session_lifecycle(SessionLifecycle::BrowserSession(Default::default()))
|
||||
.build();
|
||||
|
||||
let cors = Cors::default()
|
||||
.allowed_origin(&AppConfig::get().website_origin)
|
||||
.allowed_methods(vec!["GET", "POST", "PUT", "PATCH", "DELETE", "OPTIONS"])
|
||||
.allowed_header("X-Auth-Token")
|
||||
.allow_any_header()
|
||||
.supports_credentials()
|
||||
.max_age(3600);
|
||||
|
||||
App::new()
|
||||
.wrap(Logger::default())
|
||||
.wrap(session_mw)
|
||||
.wrap(cors)
|
||||
.app_data(web::Data::new(RemoteIPConfig {
|
||||
proxy: AppConfig::get().proxy_ip.clone(),
|
||||
}))
|
||||
// Uploaded files
|
||||
.app_data(TempFileConfig::default().directory(&AppConfig::get().temp_dir))
|
||||
// Server controller
|
||||
.route("/robots.txt", web::get().to(server_controller::robots_txt))
|
||||
})
|
||||
.bind(AppConfig::get().listen_address.as_str())?
|
||||
.run()
|
||||
.await
|
||||
}
|
||||
|
Reference in New Issue
Block a user