morethantext-web/src/main.rs

59 lines
1.6 KiB
Rust

use tide::{http::StatusCode, Request, Response};
mod settings;
use settings::Settings;
#[async_std::main]
async fn main() -> tide::Result<()> {
//let settings = Config::builder()
// .set_default("address", "127.0.0.1")?
// .set_default("port", 9090)?
// .add_source(
// config::Environment::with_prefix("MTT")
// .try_parsing(true)
// .separator("_")
// .list_separator(" "),
// )
// .build()
// .unwrap();
let sett = Settings::new().unwrap();
let app = app_setup().await;
app.listen(format!("{}:{}", sett.address, sett.port))
.await?;
Ok(())
}
async fn app_setup() -> tide::Server<()> {
let mut app = tide::new();
app.at("/").get(home);
return app;
}
async fn home(_req: Request<()>) -> tide::Result {
let mut res = Response::new(StatusCode::Ok);
res.set_body("<!DOCTYPE html>
<html>
<body>
<h1>Welcome to BaskinPrattle.</h1>
<p>The code for the site is <a href=\"https://gitea.baskinprattle.com/jbaskin/morethantext-web\">here</a>.</p>
<p>And the latest x86_64 Linux build is <a href=\"https://jenkins.baskinprattle.com/job/morethantext-web/\">here</a>.</p>
</body>
</html>");
res.append_header("Content-Type", "text/html; charset=UTF-8");
Ok(res)
}
#[cfg(test)]
mod server_app {
use super::*;
use tide_testing::TideTestingExt;
#[async_std::test]
async fn home_page_available() {
let app = app_setup().await;
let response = app.get("/").await.unwrap();
assert_eq!(response.status(), StatusCode::Ok);
}
}