Web-based Calendar Aggregator
https://ticker.c3d2.de/
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
51 lines
1.2 KiB
51 lines
1.2 KiB
#![recursion_limit="1024"] |
|
|
|
#[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::*, |
|
}; |
|
use diesel::{Connection, pg::PgConnection}; |
|
|
|
use libticker::config::Config; |
|
mod index; |
|
|
|
#[derive(Clone, StateData)] |
|
pub struct AppState { |
|
pub db: Arc<Mutex<PgConnection>>, |
|
pub config: Config, |
|
} |
|
|
|
fn main() { |
|
let config = Config::read_yaml_file("config.yaml"); |
|
let db = PgConnection::establish(&config.db_url) |
|
.expect("DB"); |
|
|
|
let state = AppState { |
|
db: Arc::new(Mutex::new(db)), |
|
config, |
|
}; |
|
let (chain, pipelines) = single_pipeline( |
|
single_middleware( |
|
StateMiddleware::new(state) |
|
) |
|
); |
|
let router = build_router(chain, pipelines, |route| { |
|
route.get("/").to(index::index); |
|
route.get("static/*").to_dir( |
|
FileOptions::new(&"static") |
|
// TODO: |
|
.with_cache_control("no-cache") |
|
.with_gzip(true) |
|
.build() |
|
); |
|
}); |
|
gotham::start("0.0.0.0:8400", router) |
|
}
|
|
|