summaryrefslogtreecommitdiffstats
path: root/server/src/main.rs
diff options
context:
space:
mode:
authorFelix Ableitner <me@nutomic.com>2020-04-07 18:47:19 +0200
committerFelix Ableitner <me@nutomic.com>2020-04-07 18:47:19 +0200
commitb7103a7e1481e8d7fb2a36938faba520a8cbe013 (patch)
tree5645115f978f5053e991890a18a1536a2ef0131b /server/src/main.rs
parent1b0da74b57975d01ea166f45ea1fcacf4f1651dd (diff)
Store remote communities/posts in db, federate posts!
Diffstat (limited to 'server/src/main.rs')
-rw-r--r--server/src/main.rs75
1 files changed, 47 insertions, 28 deletions
diff --git a/server/src/main.rs b/server/src/main.rs
index f2a19d30..c1bec7e0 100644
--- a/server/src/main.rs
+++ b/server/src/main.rs
@@ -6,16 +6,21 @@ use actix::prelude::*;
use actix_web::*;
use diesel::r2d2::{ConnectionManager, Pool};
use diesel::PgConnection;
+use failure::Error;
+use lemmy_server::apub::puller::fetch_all;
use lemmy_server::db::code_migrations::run_advanced_migrations;
use lemmy_server::routes::{api, federation, feeds, index, nodeinfo, webfinger, websocket};
use lemmy_server::settings::Settings;
use lemmy_server::websocket::server::*;
-use std::io;
+use log::warn;
+use std::thread;
+use std::thread::sleep;
+use std::time::Duration;
embed_migrations!();
#[actix_rt::main]
-async fn main() -> io::Result<()> {
+async fn main() -> Result<(), Error> {
env_logger::init();
let settings = Settings::get();
@@ -34,36 +39,50 @@ async fn main() -> io::Result<()> {
// Set up websocket server
let server = ChatServer::startup(pool.clone()).start();
+ // TODO: its probably failing because the other instance is not up yet
+ // need to make a new thread and wait a bit before fetching
+ thread::spawn(move || {
+ // some work here
+ sleep(Duration::from_secs(5));
+ println!("Fetching apub data");
+ match fetch_all(&conn) {
+ Ok(_) => {}
+ Err(e) => warn!("Error during apub fetch: {}", e),
+ }
+ });
+
println!(
"Starting http server at {}:{}",
settings.bind, settings.port
);
// Create Http server with websocket support
- HttpServer::new(move || {
- App::new()
- .wrap(middleware::Logger::default())
- .data(pool.clone())
- .data(server.clone())
- // The routes
- .configure(api::config)
- .configure(federation::config)
- .configure(feeds::config)
- .configure(index::config)
- .configure(nodeinfo::config)
- .configure(webfinger::config)
- .configure(websocket::config)
- // static files
- .service(actix_files::Files::new(
- "/static",
- settings.front_end_dir.to_owned(),
- ))
- .service(actix_files::Files::new(
- "/docs",
- settings.front_end_dir.to_owned() + "/documentation",
- ))
- })
- .bind((settings.bind, settings.port))?
- .run()
- .await
+ Ok(
+ HttpServer::new(move || {
+ App::new()
+ .wrap(middleware::Logger::default())
+ .data(pool.clone())
+ .data(server.clone())
+ // The routes
+ .configure(api::config)
+ .configure(federation::config)
+ .configure(feeds::config)
+ .configure(index::config)
+ .configure(nodeinfo::config)
+ .configure(webfinger::config)
+ .configure(websocket::config)
+ // static files
+ .service(actix_files::Files::new(
+ "/static",
+ settings.front_end_dir.to_owned(),
+ ))
+ .service(actix_files::Files::new(
+ "/docs",
+ settings.front_end_dir.to_owned() + "/documentation",
+ ))
+ })
+ .bind((settings.bind, settings.port))?
+ .run()
+ .await?,
+ )
}