62 lines
1.5 KiB
Rust
62 lines
1.5 KiB
Rust
/**
|
|
* This module contains the main entrypoint for Geoffrey
|
|
*/
|
|
#[macro_use]
|
|
extern crate serde_json;
|
|
#[macro_use]
|
|
extern crate lazy_static;
|
|
|
|
use log::*;
|
|
|
|
mod dao;
|
|
mod i18n;
|
|
mod state;
|
|
|
|
#[async_std::main]
|
|
async fn main() -> Result<(), std::io::Error> {
|
|
use crate::state::AppState;
|
|
|
|
dotenv::dotenv().ok();
|
|
pretty_env_logger::init();
|
|
|
|
#[cfg(debug_assertions)]
|
|
{
|
|
info!("Activating DEBUG mode configuration");
|
|
}
|
|
|
|
let state = AppState::new();
|
|
let mut app = tide::with_state(state);
|
|
|
|
app.at("/")
|
|
.get(|req: tide::Request<AppState<'static>>| async move {
|
|
let data = json!({
|
|
"projects" : dao::v1::Project::load_all(),
|
|
});
|
|
let lang = match req.header("Accept-Language") {
|
|
Some(l) => l.as_str(),
|
|
None => "en",
|
|
};
|
|
let langs = crate::i18n::parse_languages(lang);
|
|
info!("Lang: {:?}", langs);
|
|
|
|
req.state().render("index", &langs, Some(data)).await
|
|
});
|
|
|
|
if let Some(fd) = std::env::var("LISTEN_FD")
|
|
.ok()
|
|
.and_then(|fd| fd.parse().ok())
|
|
{
|
|
/*
|
|
* Allow the use of catflag for local development
|
|
* <https://github.com/passcod/catflap>
|
|
*/
|
|
use std::net::TcpListener;
|
|
use std::os::unix::io::FromRawFd;
|
|
app.listen(unsafe { TcpListener::from_raw_fd(fd) }).await?;
|
|
} else {
|
|
app.listen("0.0.0.0:8000").await?;
|
|
}
|
|
|
|
Ok(())
|
|
}
|