2018-04-30 19:37:19 +00:00
|
|
|
#![feature(plugin, custom_derive, iterator_find_map)]
|
2018-04-22 13:35:37 +00:00
|
|
|
#![plugin(rocket_codegen)]
|
|
|
|
|
2018-06-10 11:13:07 +00:00
|
|
|
extern crate activitypub;
|
2018-05-13 14:39:55 +00:00
|
|
|
extern crate array_tool;
|
2018-04-29 15:40:10 +00:00
|
|
|
extern crate base64;
|
2018-04-24 09:21:39 +00:00
|
|
|
extern crate bcrypt;
|
2018-04-29 15:40:10 +00:00
|
|
|
extern crate chrono;
|
2018-05-24 10:42:45 +00:00
|
|
|
extern crate comrak;
|
2018-05-16 18:20:44 +00:00
|
|
|
extern crate failure;
|
|
|
|
#[macro_use]
|
|
|
|
extern crate failure_derive;
|
2018-06-15 13:08:38 +00:00
|
|
|
extern crate gettextrs;
|
2018-04-24 09:21:39 +00:00
|
|
|
extern crate heck;
|
2018-04-29 15:40:10 +00:00
|
|
|
extern crate hex;
|
2018-04-22 13:35:37 +00:00
|
|
|
#[macro_use]
|
2018-05-04 15:18:00 +00:00
|
|
|
extern crate hyper;
|
|
|
|
#[macro_use]
|
2018-04-22 13:35:37 +00:00
|
|
|
extern crate diesel;
|
|
|
|
extern crate dotenv;
|
2018-05-02 11:53:42 +00:00
|
|
|
#[macro_use]
|
|
|
|
extern crate lazy_static;
|
2018-04-29 15:40:10 +00:00
|
|
|
extern crate openssl;
|
2018-04-30 18:08:44 +00:00
|
|
|
extern crate reqwest;
|
2018-04-22 13:35:37 +00:00
|
|
|
extern crate rocket;
|
|
|
|
extern crate rocket_contrib;
|
2018-04-24 14:52:47 +00:00
|
|
|
extern crate serde;
|
|
|
|
#[macro_use]
|
2018-05-01 11:48:19 +00:00
|
|
|
extern crate serde_derive;
|
|
|
|
#[macro_use]
|
2018-04-23 15:09:05 +00:00
|
|
|
extern crate serde_json;
|
2018-05-01 18:02:29 +00:00
|
|
|
extern crate url;
|
2018-06-11 10:21:34 +00:00
|
|
|
extern crate ammonia;
|
2018-04-22 13:35:37 +00:00
|
|
|
|
2018-05-19 07:39:59 +00:00
|
|
|
use diesel::{pg::PgConnection, r2d2::{ConnectionManager, Pool}};
|
2018-04-22 13:35:37 +00:00
|
|
|
use dotenv::dotenv;
|
|
|
|
use rocket_contrib::Template;
|
2018-04-24 09:21:39 +00:00
|
|
|
use std::env;
|
2018-04-22 13:35:37 +00:00
|
|
|
|
2018-04-23 11:57:14 +00:00
|
|
|
mod activity_pub;
|
2018-04-22 13:35:37 +00:00
|
|
|
mod db_conn;
|
2018-06-15 13:55:14 +00:00
|
|
|
mod i18n;
|
2018-04-22 13:35:37 +00:00
|
|
|
mod models;
|
|
|
|
mod schema;
|
|
|
|
mod routes;
|
2018-04-23 10:54:37 +00:00
|
|
|
mod utils;
|
2018-06-11 09:43:27 +00:00
|
|
|
mod safe_string;
|
2018-04-22 13:35:37 +00:00
|
|
|
|
2018-05-02 11:53:42 +00:00
|
|
|
lazy_static! {
|
|
|
|
pub static ref BASE_URL: String = env::var("BASE_URL")
|
|
|
|
.unwrap_or(format!("127.0.0.1:{}", env::var("ROCKET_PORT").unwrap_or(String::from("8000"))));
|
|
|
|
|
|
|
|
pub static ref DB_URL: String = env::var("DB_URL")
|
2018-05-02 12:47:46 +00:00
|
|
|
.unwrap_or(format!("postgres://plume:plume@localhost/{}", env::var("DB_NAME").unwrap_or(String::from("plume"))));
|
2018-05-02 11:53:42 +00:00
|
|
|
}
|
|
|
|
|
2018-04-22 13:35:37 +00:00
|
|
|
type PgPool = Pool<ConnectionManager<PgConnection>>;
|
|
|
|
|
|
|
|
/// Initializes a database pool.
|
|
|
|
fn init_pool() -> PgPool {
|
|
|
|
dotenv().ok();
|
|
|
|
|
2018-05-02 11:53:42 +00:00
|
|
|
let manager = ConnectionManager::<PgConnection>::new(DB_URL.as_str());
|
|
|
|
Pool::new(manager).expect("DB pool error")
|
2018-04-22 13:35:37 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
fn main() {
|
|
|
|
rocket::ignite()
|
|
|
|
.mount("/", routes![
|
2018-05-13 17:41:49 +00:00
|
|
|
routes::blogs::details,
|
|
|
|
routes::blogs::activity_details,
|
|
|
|
routes::blogs::outbox,
|
|
|
|
routes::blogs::new,
|
2018-06-04 19:57:03 +00:00
|
|
|
routes::blogs::new_auth,
|
2018-05-13 17:41:49 +00:00
|
|
|
routes::blogs::create,
|
2018-05-10 18:01:16 +00:00
|
|
|
|
2018-05-13 17:41:49 +00:00
|
|
|
routes::comments::new,
|
2018-06-04 19:57:03 +00:00
|
|
|
routes::comments::new_auth,
|
2018-05-13 17:41:49 +00:00
|
|
|
routes::comments::create,
|
2018-04-24 08:35:45 +00:00
|
|
|
|
2018-04-29 17:50:46 +00:00
|
|
|
routes::instance::index,
|
2018-04-22 13:35:37 +00:00
|
|
|
routes::instance::configure,
|
2018-04-22 18:13:12 +00:00
|
|
|
routes::instance::post_config,
|
2018-05-13 17:39:18 +00:00
|
|
|
routes::instance::shared_inbox,
|
2018-06-10 19:33:42 +00:00
|
|
|
routes::instance::nodeinfo,
|
2018-04-22 18:13:12 +00:00
|
|
|
|
2018-05-13 17:41:49 +00:00
|
|
|
routes::likes::create,
|
2018-06-04 19:57:03 +00:00
|
|
|
routes::likes::create_auth,
|
2018-05-13 17:41:49 +00:00
|
|
|
|
2018-05-13 13:35:55 +00:00
|
|
|
routes::notifications::notifications,
|
2018-06-04 19:57:03 +00:00
|
|
|
routes::notifications::notifications_auth,
|
2018-05-13 13:35:55 +00:00
|
|
|
|
2018-05-13 17:41:49 +00:00
|
|
|
routes::posts::details,
|
|
|
|
routes::posts::activity_details,
|
|
|
|
routes::posts::new,
|
|
|
|
routes::posts::new_auth,
|
|
|
|
routes::posts::create,
|
|
|
|
|
2018-05-19 09:51:10 +00:00
|
|
|
routes::reshares::create,
|
2018-06-04 19:57:03 +00:00
|
|
|
routes::reshares::create_auth,
|
2018-05-19 09:51:10 +00:00
|
|
|
|
2018-05-13 17:41:49 +00:00
|
|
|
routes::session::new,
|
2018-06-04 18:21:43 +00:00
|
|
|
routes::session::new_message,
|
2018-05-13 17:41:49 +00:00
|
|
|
routes::session::create,
|
|
|
|
routes::session::delete,
|
|
|
|
|
|
|
|
routes::static_files,
|
|
|
|
|
2018-04-23 09:52:44 +00:00
|
|
|
routes::user::me,
|
2018-04-22 18:13:12 +00:00
|
|
|
routes::user::details,
|
2018-06-10 17:55:08 +00:00
|
|
|
routes::user::dashboard,
|
|
|
|
routes::user::dashboard_auth,
|
2018-05-13 11:53:58 +00:00
|
|
|
routes::user::followers,
|
2018-05-12 15:30:14 +00:00
|
|
|
routes::user::edit,
|
2018-06-07 08:39:22 +00:00
|
|
|
routes::user::edit_auth,
|
2018-05-12 15:30:14 +00:00
|
|
|
routes::user::update,
|
2018-05-01 19:57:30 +00:00
|
|
|
routes::user::follow,
|
2018-06-07 08:39:22 +00:00
|
|
|
routes::user::follow_auth,
|
2018-04-24 12:31:02 +00:00
|
|
|
routes::user::activity_details,
|
2018-04-29 18:01:42 +00:00
|
|
|
routes::user::outbox,
|
2018-05-01 14:00:29 +00:00
|
|
|
routes::user::inbox,
|
2018-05-13 11:53:58 +00:00
|
|
|
routes::user::ap_followers,
|
2018-04-22 18:13:12 +00:00
|
|
|
routes::user::new,
|
|
|
|
routes::user::create,
|
2018-04-23 09:52:44 +00:00
|
|
|
|
2018-05-13 17:41:49 +00:00
|
|
|
routes::well_known::host_meta,
|
2018-06-10 19:33:42 +00:00
|
|
|
routes::well_known::nodeinfo,
|
2018-05-13 17:41:49 +00:00
|
|
|
routes::well_known::webfinger
|
2018-04-22 13:35:37 +00:00
|
|
|
])
|
|
|
|
.manage(init_pool())
|
|
|
|
.attach(Template::fairing())
|
2018-06-15 13:55:14 +00:00
|
|
|
.attach(i18n::I18n::new("plume"))
|
2018-04-22 13:35:37 +00:00
|
|
|
.launch();
|
|
|
|
}
|