2021-05-26 20:46:26 +02:00
|
|
|
#![recursion_limit="2048"]
|
2019-10-26 01:14:49 +02:00
|
|
|
|
2020-10-26 16:20:11 +01:00
|
|
|
#[macro_use]
|
|
|
|
extern crate gotham_derive;
|
|
|
|
|
|
|
|
use std::sync::{Arc, Mutex};
|
|
|
|
use gotham::{
|
|
|
|
handler::assets::FileOptions,
|
|
|
|
router::builder::{DefineSingleRoute, DrawRoutes},
|
|
|
|
middleware::state::StateMiddleware,
|
|
|
|
pipeline::single::single_pipeline,
|
|
|
|
pipeline::single_middleware,
|
|
|
|
router::builder::*,
|
|
|
|
};
|
2020-10-26 16:51:25 +01:00
|
|
|
use diesel::{Connection, pg::PgConnection};
|
2020-10-26 16:20:11 +01:00
|
|
|
|
2020-10-26 16:51:25 +01:00
|
|
|
use libticker::config::Config;
|
|
|
|
mod index;
|
2019-10-26 02:19:33 +02:00
|
|
|
|
2020-10-26 16:20:11 +01:00
|
|
|
#[derive(Clone, StateData)]
|
2020-10-26 16:51:25 +01:00
|
|
|
pub struct AppState {
|
|
|
|
pub db: Arc<Mutex<PgConnection>>,
|
2020-10-26 19:48:17 +01:00
|
|
|
pub config: Config,
|
2019-10-26 01:14:49 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
fn main() {
|
2020-10-27 19:20:34 +01:00
|
|
|
let config = Config::read_yaml_file("config.yaml");
|
2019-10-26 01:14:49 +02:00
|
|
|
let db = PgConnection::establish(&config.db_url)
|
|
|
|
.expect("DB");
|
|
|
|
|
2020-10-26 16:20:11 +01:00
|
|
|
let state = AppState {
|
2020-10-26 19:48:17 +01:00
|
|
|
db: Arc::new(Mutex::new(db)),
|
|
|
|
config,
|
2020-10-26 16:20:11 +01:00
|
|
|
};
|
|
|
|
let (chain, pipelines) = single_pipeline(
|
|
|
|
single_middleware(
|
|
|
|
StateMiddleware::new(state)
|
|
|
|
)
|
|
|
|
);
|
|
|
|
let router = build_router(chain, pipelines, |route| {
|
2020-10-26 16:51:25 +01:00
|
|
|
route.get("/").to(index::index);
|
2020-10-26 16:20:11 +01:00
|
|
|
route.get("static/*").to_dir(
|
|
|
|
FileOptions::new(&"static")
|
|
|
|
// TODO:
|
|
|
|
.with_cache_control("no-cache")
|
|
|
|
.with_gzip(true)
|
|
|
|
.build()
|
|
|
|
);
|
|
|
|
});
|
2020-10-27 19:20:34 +01:00
|
|
|
gotham::start("0.0.0.0:8400", router)
|
2019-10-26 01:14:49 +02:00
|
|
|
}
|