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