2018-04-22 15:35:37 +02:00
|
|
|
#![feature(plugin, custom_derive)]
|
|
|
|
#![plugin(rocket_codegen)]
|
|
|
|
|
|
|
|
#[macro_use]
|
|
|
|
extern crate diesel;
|
|
|
|
extern crate dotenv;
|
|
|
|
extern crate rocket;
|
|
|
|
extern crate rocket_contrib;
|
2018-04-22 20:13:12 +02:00
|
|
|
extern crate bcrypt;
|
2018-04-23 12:54:37 +02:00
|
|
|
extern crate heck;
|
2018-04-23 17:09:05 +02:00
|
|
|
#[macro_use]
|
|
|
|
extern crate serde_json;
|
2018-04-22 15:35:37 +02:00
|
|
|
|
|
|
|
use diesel::pg::PgConnection;
|
|
|
|
use diesel::r2d2::{ConnectionManager, Pool};
|
|
|
|
use dotenv::dotenv;
|
|
|
|
use std::env;
|
|
|
|
use rocket_contrib::Template;
|
|
|
|
|
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
|
|
|
|
|
|
|
use db_conn::DbConn;
|
|
|
|
use models::instance::*;
|
|
|
|
|
|
|
|
type PgPool = Pool<ConnectionManager<PgConnection>>;
|
|
|
|
|
|
|
|
/// Initializes a database pool.
|
|
|
|
fn init_pool() -> PgPool {
|
|
|
|
dotenv().ok();
|
|
|
|
|
|
|
|
let database_url = env::var("DATABASE_URL").expect("DATABASE_URL must be set");
|
|
|
|
let manager = ConnectionManager::<PgConnection>::new(database_url);
|
|
|
|
Pool::new(manager).expect("db pool")
|
|
|
|
}
|
|
|
|
|
|
|
|
#[get("/")]
|
|
|
|
fn index(conn: DbConn) -> String {
|
|
|
|
match Instance::get_local(&*conn) {
|
|
|
|
Some(inst) => {
|
|
|
|
format!("Welcome on {}", inst.name)
|
|
|
|
}
|
|
|
|
None => {
|
|
|
|
String::from("Not initialized")
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
fn main() {
|
|
|
|
rocket::ignite()
|
|
|
|
.mount("/", routes![
|
2018-04-24 10:35:45 +02:00
|
|
|
routes::well_known::host_meta,
|
|
|
|
routes::well_known::webfinger_json,
|
|
|
|
routes::well_known::webfinger_xml,
|
|
|
|
|
2018-04-22 15:35:37 +02:00
|
|
|
routes::instance::configure,
|
2018-04-22 20:13:12 +02:00
|
|
|
routes::instance::post_config,
|
|
|
|
|
2018-04-23 11:52:44 +02:00
|
|
|
routes::user::me,
|
2018-04-22 20:13:12 +02:00
|
|
|
routes::user::details,
|
2018-04-23 17:09:05 +02:00
|
|
|
routes::user::activity,
|
2018-04-22 20:13:12 +02:00
|
|
|
routes::user::new,
|
|
|
|
routes::user::create,
|
2018-04-23 11:52:44 +02:00
|
|
|
|
|
|
|
routes::session::new,
|
2018-04-23 12:54:37 +02:00
|
|
|
routes::session::create,
|
2018-04-23 13:13:49 +02:00
|
|
|
routes::session::delete,
|
2018-04-23 12:54:37 +02:00
|
|
|
|
|
|
|
routes::blogs::details,
|
2018-04-23 17:09:05 +02:00
|
|
|
routes::blogs::activity,
|
2018-04-23 12:54:37 +02:00
|
|
|
routes::blogs::new,
|
|
|
|
routes::blogs::create,
|
2018-04-23 16:25:39 +02:00
|
|
|
|
|
|
|
routes::posts::details,
|
|
|
|
routes::posts::new,
|
|
|
|
routes::posts::new_auth,
|
|
|
|
routes::posts::create
|
2018-04-22 15:35:37 +02:00
|
|
|
])
|
|
|
|
.manage(init_pool())
|
|
|
|
.attach(Template::fairing())
|
|
|
|
.launch();
|
|
|
|
}
|