From 80aef61aed29d25099835ee4769bb8e1e363eb47 Mon Sep 17 00:00:00 2001 From: nutomic Date: Fri, 10 Jul 2020 18:15:41 +0000 Subject: Split code into cargo workspaces (#67) More fixes - fixed docker builds - fixed mentions regex test - fixed DATABASE_URL stuff - change schema path in diesel.toml Address review comments - add jsonb column back into activity table - remove authors field from cargo.toml - adjust LEMMY_DATABASE_URL env var usage - rename all occurences of LEMMY_DATABASE_URL to DATABASE_URL Decouple utils and db Split code into cargo workspaces Co-authored-by: Felix Ableitner Reviewed-on: https://yerbamate.dev/LemmyNet/lemmy/pulls/67 --- server/src/main.rs | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) (limited to 'server/src/main.rs') diff --git a/server/src/main.rs b/server/src/main.rs index 30be711f..7689d7ad 100644 --- a/server/src/main.rs +++ b/server/src/main.rs @@ -22,22 +22,20 @@ use diesel::{ r2d2::{ConnectionManager, Pool}, PgConnection, }; +use lemmy_db::get_database_url_from_env; use lemmy_server::{ blocking, - db::code_migrations::run_advanced_migrations, + code_migrations::run_advanced_migrations, rate_limit::{rate_limiter::RateLimiter, RateLimit}, routes::{api, federation, feeds, index, nodeinfo, webfinger}, - settings::Settings, websocket::server::*, LemmyError, }; -use regex::Regex; +use lemmy_utils::{settings::Settings, CACHE_CONTROL_REGEX}; use std::sync::Arc; use tokio::sync::Mutex; lazy_static! { - static ref CACHE_CONTROL_REGEX: Regex = - Regex::new("^((text|image)/.+|application/javascript)$").unwrap(); // static ref CACHE_CONTROL_VALUE: String = format!("public, max-age={}", 365 * 24 * 60 * 60); // Test out 1 hour here, this is breaking some things static ref CACHE_CONTROL_VALUE: String = format!("public, max-age={}", 60 * 60); @@ -51,11 +49,15 @@ async fn main() -> Result<(), LemmyError> { let settings = Settings::get(); // Set up the r2d2 connection pool - let manager = ConnectionManager::::new(&settings.get_database_url()); + let db_url = match get_database_url_from_env() { + Ok(url) => url, + Err(_) => settings.get_database_url(), + }; + let manager = ConnectionManager::::new(&db_url); let pool = Pool::builder() .max_size(settings.database.pool_size) .build(manager) - .unwrap_or_else(|_| panic!("Error connecting to {}", settings.get_database_url())); + .unwrap_or_else(|_| panic!("Error connecting to {}", db_url)); // Run the migrations from code blocking(&pool, move |conn| { -- cgit v1.2.3