1 extern crate lemmy_server;
3 extern crate diesel_migrations;
7 use diesel::r2d2::{ConnectionManager, Pool};
8 use diesel::PgConnection;
10 use lemmy_server::apub::puller::fetch_all;
11 use lemmy_server::db::code_migrations::run_advanced_migrations;
12 use lemmy_server::routes::{api, federation, feeds, index, nodeinfo, webfinger, websocket};
13 use lemmy_server::settings::Settings;
14 use lemmy_server::websocket::server::*;
17 use std::thread::sleep;
18 use std::time::Duration;
23 async fn main() -> Result<(), Error> {
25 let settings = Settings::get();
27 // Set up the r2d2 connection pool
28 let manager = ConnectionManager::<PgConnection>::new(&settings.get_database_url());
29 let pool = Pool::builder()
30 .max_size(settings.database.pool_size)
32 .unwrap_or_else(|_| panic!("Error connecting to {}", settings.get_database_url()));
34 // Run the migrations from code
35 let conn = pool.get().unwrap();
36 embedded_migrations::run(&conn).unwrap();
37 run_advanced_migrations(&conn).unwrap();
39 // Set up websocket server
40 let server = ChatServer::startup(pool.clone()).start();
42 // TODO: its probably failing because the other instance is not up yet
43 // need to make a new thread and wait a bit before fetching
44 thread::spawn(move || {
46 sleep(Duration::from_secs(5));
47 println!("Fetching apub data");
48 match fetch_all(&conn) {
50 Err(e) => warn!("Error during apub fetch: {}", e),
55 "Starting http server at {}:{}",
56 settings.bind, settings.port
59 // Create Http server with websocket support
61 HttpServer::new(move || {
63 .wrap(middleware::Logger::default())
67 .configure(api::config)
68 .configure(federation::config)
69 .configure(feeds::config)
70 .configure(index::config)
71 .configure(nodeinfo::config)
72 .configure(webfinger::config)
73 .configure(websocket::config)
75 .service(actix_files::Files::new(
77 settings.front_end_dir.to_owned(),
79 .service(actix_files::Files::new(
81 settings.front_end_dir.to_owned() + "/documentation",
84 .bind((settings.bind, settings.port))?