2020-07-12 18:42:09 +00:00
|
|
|
use anyhow::Result;
|
2020-07-12 23:26:53 +00:00
|
|
|
use std::sync::Arc;
|
2020-07-12 22:39:50 +00:00
|
|
|
use warp::{path, Filter};
|
2020-07-12 18:42:09 +00:00
|
|
|
|
|
|
|
pub mod app;
|
2020-07-12 22:39:50 +00:00
|
|
|
pub mod handlers;
|
2020-07-13 01:50:45 +00:00
|
|
|
pub mod post;
|
2020-07-12 18:42:09 +00:00
|
|
|
pub mod signalboost;
|
|
|
|
|
2020-07-12 23:26:53 +00:00
|
|
|
use app::State;
|
|
|
|
|
2020-07-12 18:42:09 +00:00
|
|
|
const APPLICATION_NAME: &str = concat!(env!("CARGO_PKG_NAME"), "/", env!("CARGO_PKG_VERSION"));
|
|
|
|
|
2020-07-12 23:26:53 +00:00
|
|
|
fn with_state(
|
|
|
|
state: Arc<State>,
|
|
|
|
) -> impl Filter<Extract = (Arc<State>,), Error = std::convert::Infallible> + Clone {
|
|
|
|
warp::any().map(move || state.clone())
|
|
|
|
}
|
|
|
|
|
2020-07-12 18:42:09 +00:00
|
|
|
#[tokio::main]
|
|
|
|
async fn main() -> Result<()> {
|
|
|
|
pretty_env_logger::init();
|
|
|
|
|
2020-07-13 00:11:26 +00:00
|
|
|
let state = Arc::new(app::init(
|
|
|
|
std::env::var("CONFIG_FNAME")
|
|
|
|
.unwrap_or("./config.dhall".into())
|
|
|
|
.as_str()
|
|
|
|
.into(),
|
|
|
|
)?);
|
2020-07-12 18:42:09 +00:00
|
|
|
|
2020-07-13 00:51:58 +00:00
|
|
|
let healthcheck = warp::get().and(warp::path(".within").and(warp::path("health")).map(|| "OK"));
|
|
|
|
|
2020-07-12 22:58:38 +00:00
|
|
|
let routes = warp::get()
|
|
|
|
.and(path::end().and_then(handlers::index))
|
|
|
|
.or(warp::path!("contact").and_then(handlers::contact))
|
2020-07-12 23:26:53 +00:00
|
|
|
.or(warp::path!("feeds").and_then(handlers::feeds))
|
|
|
|
.or(warp::path!("resume")
|
|
|
|
.and(with_state(state.clone()))
|
2020-07-12 23:37:01 +00:00
|
|
|
.and_then(handlers::resume))
|
|
|
|
.or(warp::path!("signalboost")
|
|
|
|
.and(with_state(state.clone()))
|
|
|
|
.and_then(handlers::signalboost));
|
2020-07-12 18:42:09 +00:00
|
|
|
|
2020-07-12 22:39:50 +00:00
|
|
|
let files = warp::path("static")
|
|
|
|
.and(warp::fs::dir("./static"))
|
2020-07-13 00:51:58 +00:00
|
|
|
.or(warp::path("css").and(warp::fs::dir("./css")))
|
|
|
|
.or(warp::path("sw.js").and(warp::fs::file("./static/js/sw.js")))
|
|
|
|
.or(warp::path("robots.txt").and(warp::fs::file("./static/robots.txt")));
|
2020-07-12 22:39:50 +00:00
|
|
|
|
2020-07-13 00:51:58 +00:00
|
|
|
let site = routes
|
|
|
|
.or(files)
|
|
|
|
.map(|reply| {
|
|
|
|
warp::reply::with_header(
|
|
|
|
reply,
|
|
|
|
"X-Hacker",
|
|
|
|
"If you are reading this, check out /signalboost to find people for your team",
|
|
|
|
)
|
|
|
|
})
|
|
|
|
.or(healthcheck)
|
|
|
|
.with(warp::log(APPLICATION_NAME));
|
2020-07-12 22:39:50 +00:00
|
|
|
|
|
|
|
warp::serve(site).run(([127, 0, 0, 1], 3030)).await;
|
2020-07-12 18:42:09 +00:00
|
|
|
|
|
|
|
Ok(())
|
2020-07-12 16:54:33 +00:00
|
|
|
}
|
2020-07-12 22:39:50 +00:00
|
|
|
|
|
|
|
include!(concat!(env!("OUT_DIR"), "/templates.rs"));
|