2020-11-02 18:06:50 +00:00
|
|
|
#![feature(proc_macro_hygiene, decl_macro)]
|
|
|
|
|
2020-09-13 16:07:06 +00:00
|
|
|
#[macro_use]
|
|
|
|
extern crate diesel;
|
2020-11-02 18:06:50 +00:00
|
|
|
#[macro_use]
|
|
|
|
extern crate rocket;
|
|
|
|
#[macro_use]
|
|
|
|
extern crate rocket_contrib;
|
|
|
|
#[macro_use]
|
|
|
|
extern crate tracing;
|
2020-09-13 16:07:06 +00:00
|
|
|
|
2020-09-13 15:23:53 +00:00
|
|
|
use color_eyre::eyre::Result;
|
2020-09-13 16:07:06 +00:00
|
|
|
use diesel::sqlite::SqliteConnection;
|
2020-11-02 18:06:50 +00:00
|
|
|
use rocket_contrib::helmet::SpaceHelmet;
|
|
|
|
use rocket_prometheus::PrometheusMetrics;
|
2020-09-13 15:23:53 +00:00
|
|
|
|
|
|
|
const APPLICATION_NAME: &str = concat!(env!("CARGO_PKG_NAME"), "/", env!("CARGO_PKG_VERSION"));
|
2020-09-13 16:07:06 +00:00
|
|
|
|
2020-11-02 18:06:50 +00:00
|
|
|
pub mod api;
|
2020-09-13 16:07:06 +00:00
|
|
|
pub mod models;
|
2020-09-13 16:55:29 +00:00
|
|
|
pub mod schema;
|
2020-11-02 20:54:23 +00:00
|
|
|
pub mod web;
|
2020-09-13 15:23:53 +00:00
|
|
|
|
2020-11-02 18:06:50 +00:00
|
|
|
#[database("main_data")]
|
|
|
|
pub struct MainDatabase(SqliteConnection);
|
|
|
|
|
|
|
|
fn main() -> Result<()> {
|
2020-09-13 15:23:53 +00:00
|
|
|
let _ = kankyo::init();
|
|
|
|
color_eyre::install()?;
|
2020-11-02 18:06:50 +00:00
|
|
|
tracing_subscriber::fmt::init();
|
|
|
|
|
|
|
|
info!("{} starting up", APPLICATION_NAME);
|
|
|
|
|
|
|
|
let prometheus = PrometheusMetrics::with_registry(prometheus::default_registry().clone());
|
|
|
|
rocket::ignite()
|
|
|
|
.attach(prometheus.clone())
|
|
|
|
.attach(MainDatabase::fairing())
|
|
|
|
.attach(SpaceHelmet::default())
|
2020-11-02 22:31:55 +00:00
|
|
|
.attach(web::pluralkit::Client::fairing())
|
2020-11-02 20:54:23 +00:00
|
|
|
.attach(web::switchcounter::Client::fairing())
|
2020-11-02 18:06:50 +00:00
|
|
|
.mount("/metrics", prometheus)
|
|
|
|
.mount(
|
2020-11-02 19:03:32 +00:00
|
|
|
"/",
|
2020-11-02 18:06:50 +00:00
|
|
|
routes![
|
|
|
|
api::get_members,
|
|
|
|
api::get_switches,
|
2020-11-02 19:16:35 +00:00
|
|
|
api::get_switch,
|
2020-11-02 18:06:50 +00:00
|
|
|
api::get_current_front,
|
|
|
|
api::make_switch
|
|
|
|
],
|
|
|
|
)
|
|
|
|
.launch();
|
2020-09-13 15:23:53 +00:00
|
|
|
|
|
|
|
Ok(())
|
|
|
|
}
|