2022-06-24 15:36:05 -04:00
|
|
|
use morethantext::Database;
|
2022-06-22 12:03:17 -04:00
|
|
|
use tide::{
|
|
|
|
http::StatusCode,
|
|
|
|
sessions::{MemoryStore, SessionMiddleware},
|
|
|
|
Request, Response,
|
|
|
|
};
|
2022-02-26 11:18:08 -05:00
|
|
|
|
2022-06-18 21:24:11 -04:00
|
|
|
mod settings;
|
|
|
|
|
|
|
|
use settings::Settings;
|
|
|
|
|
2022-02-26 11:18:08 -05:00
|
|
|
#[async_std::main]
|
|
|
|
async fn main() -> tide::Result<()> {
|
2022-06-18 21:24:11 -04:00
|
|
|
let sett = Settings::new().unwrap();
|
2022-02-26 11:18:08 -05:00
|
|
|
let app = app_setup().await;
|
2022-06-18 21:24:11 -04:00
|
|
|
app.listen(format!("{}:{}", sett.address, sett.port))
|
|
|
|
.await?;
|
2022-02-26 11:18:08 -05:00
|
|
|
Ok(())
|
|
|
|
}
|
|
|
|
|
2022-06-24 15:36:05 -04:00
|
|
|
async fn app_setup() -> tide::Server<Database> {
|
|
|
|
let db = Database::new();
|
|
|
|
let mut app = tide::with_state(db);
|
2022-02-26 11:18:08 -05:00
|
|
|
app.at("/").get(home);
|
2022-06-24 08:22:17 -04:00
|
|
|
app.with(
|
|
|
|
SessionMiddleware::new(MemoryStore::new(), b"361f953f-56ba-45e6-86ab-9efbf61b745d")
|
|
|
|
.with_cookie_name("morethantext.sid"),
|
|
|
|
);
|
2022-02-26 11:18:08 -05:00
|
|
|
return app;
|
|
|
|
}
|
|
|
|
|
2022-06-24 15:36:05 -04:00
|
|
|
async fn home(_req: Request<Database>) -> tide::Result {
|
2022-06-02 13:14:14 -04:00
|
|
|
let mut res = Response::new(StatusCode::Ok);
|
2022-02-26 11:18:08 -05:00
|
|
|
res.set_body("<!DOCTYPE html>
|
|
|
|
<html>
|
|
|
|
<body>
|
|
|
|
<h1>Welcome to BaskinPrattle.</h1>
|
2022-03-21 14:15:51 -04:00
|
|
|
<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>
|
2022-06-20 19:47:38 -04:00
|
|
|
<p>There is also an ansible role for installation <a href=\"https://gitea.baskinprattle.com/jbaskin/role-morethantext.git\">here</a>.</p>
|
2022-02-26 11:18:08 -05:00
|
|
|
</body>
|
|
|
|
</html>");
|
|
|
|
res.append_header("Content-Type", "text/html; charset=UTF-8");
|
|
|
|
Ok(res)
|
|
|
|
}
|
|
|
|
|
|
|
|
#[cfg(test)]
|
2022-06-18 21:24:11 -04:00
|
|
|
mod server_app {
|
2022-02-26 11:18:08 -05:00
|
|
|
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();
|
2022-06-02 13:14:14 -04:00
|
|
|
assert_eq!(response.status(), StatusCode::Ok);
|
2022-02-26 11:18:08 -05:00
|
|
|
}
|
|
|
|
}
|