summaryrefslogtreecommitdiffstats
path: root/server/src/main.rs
diff options
context:
space:
mode:
authorRiley <asonix@asonix.dog>2020-07-01 07:54:29 -0500
committerGitHub <noreply@github.com>2020-07-01 08:54:29 -0400
commita074564458b8a108b77d98e5e8ce24168656763a (patch)
tree8cfb4e463b6b2dbd3c4b3ac2f312a42542f38d64 /server/src/main.rs
parent4c1cb5999cad496714cec67f101be38cd281d416 (diff)
Federation async (#848)
* Asyncify more * I guess these changed * Clean PR a bit * Convert more away from failure error * config changes for testing federation * It was DNS So actix-web's client relies on TRust DNS Resolver to figure out where to send data, but TRust DNS Resolver seems to not play nice with docker, which expressed itself as not resolving the name to an IP address _the first time_ when making a request. The fix was literally to make the request again (which I limited to 3 times total, and not exceeding the request timeout in total) * Only retry for connecterror Since TRust DNS Resolver was causing ConnectError::Timeout, this change limits the retry to only this error, returning immediately for any other error * Use http sig norm 0.4.0-alpha for actix-web 3.0 support * Blocking function, retry http requests * cargo +nightly fmt * Only create one pictrs dir * Don't yarn build * cargo +nightly fmt
Diffstat (limited to 'server/src/main.rs')
-rw-r--r--server/src/main.rs25
1 files changed, 18 insertions, 7 deletions
diff --git a/server/src/main.rs b/server/src/main.rs
index 2f53f3ac..30be711f 100644
--- a/server/src/main.rs
+++ b/server/src/main.rs
@@ -4,10 +4,13 @@ extern crate diesel_migrations;
#[macro_use]
pub extern crate lazy_static;
+pub type DbPool = Pool<ConnectionManager<PgConnection>>;
+
use crate::lemmy_server::actix_web::dev::Service;
use actix::prelude::*;
use actix_web::{
body::Body,
+ client::Client,
dev::{ServiceRequest, ServiceResponse},
http::{
header::{CACHE_CONTROL, CONTENT_TYPE},
@@ -20,14 +23,16 @@ use diesel::{
PgConnection,
};
use lemmy_server::{
+ blocking,
db::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 std::{io, sync::Arc};
+use std::sync::Arc;
use tokio::sync::Mutex;
lazy_static! {
@@ -41,7 +46,7 @@ lazy_static! {
embed_migrations!();
#[actix_rt::main]
-async fn main() -> io::Result<()> {
+async fn main() -> Result<(), LemmyError> {
env_logger::init();
let settings = Settings::get();
@@ -53,9 +58,12 @@ async fn main() -> io::Result<()> {
.unwrap_or_else(|_| panic!("Error connecting to {}", settings.get_database_url()));
// Run the migrations from code
- let conn = pool.get().unwrap();
- embedded_migrations::run(&conn).unwrap();
- run_advanced_migrations(&conn).unwrap();
+ blocking(&pool, move |conn| {
+ embedded_migrations::run(conn)?;
+ run_advanced_migrations(conn)?;
+ Ok(()) as Result<(), LemmyError>
+ })
+ .await??;
// Set up the rate limiter
let rate_limiter = RateLimit {
@@ -63,7 +71,7 @@ async fn main() -> io::Result<()> {
};
// Set up websocket server
- let server = ChatServer::startup(pool.clone(), rate_limiter.clone()).start();
+ let server = ChatServer::startup(pool.clone(), rate_limiter.clone(), Client::default()).start();
println!(
"Starting http server at {}:{}",
@@ -79,6 +87,7 @@ async fn main() -> io::Result<()> {
.wrap(middleware::Logger::default())
.data(pool.clone())
.data(server.clone())
+ .data(Client::default())
// The routes
.configure(move |cfg| api::config(cfg, &rate_limiter))
.configure(federation::config)
@@ -98,7 +107,9 @@ async fn main() -> io::Result<()> {
})
.bind((settings.bind, settings.port))?
.run()
- .await
+ .await?;
+
+ Ok(())
}
fn add_cache_headers<S>(