Add WIP web frontend
Signed-off-by: Ben Aaron Goldberg <ben@benaaron.dev>
This commit is contained in:
parent
ceace8ebb4
commit
2dfa2c2f92
|
@ -20,3 +20,8 @@ features = ["derive"]
|
|||
[dependencies.time]
|
||||
version = "0.3"
|
||||
features = ["local-offset"]
|
||||
|
||||
[workspace]
|
||||
members = [
|
||||
"web"
|
||||
]
|
||||
|
|
12
web/Cargo.toml
Normal file
12
web/Cargo.toml
Normal file
|
@ -0,0 +1,12 @@
|
|||
[package]
|
||||
name = "pronouns_today_web"
|
||||
version = "0.1.0"
|
||||
edition = "2021"
|
||||
|
||||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||
|
||||
[dependencies]
|
||||
pronouns_today = {path = ".."}
|
||||
actix-web = "3"
|
||||
log = "0.4.14"
|
||||
env_logger = "0.9.0"
|
48
web/src/main.rs
Normal file
48
web/src/main.rs
Normal file
|
@ -0,0 +1,48 @@
|
|||
use actix_web::error::ErrorBadRequest;
|
||||
use actix_web::middleware::Logger;
|
||||
use actix_web::{App, HttpServer, Responder, get, web, Result};
|
||||
use pronouns_today::InstanceSettings;
|
||||
|
||||
#[get("/")]
|
||||
async fn default(settings: web::Data<InstanceSettings>) -> Result<impl Responder> {
|
||||
eprintln!("default");
|
||||
let pronouns = settings.select_pronouns(None, None).map_err(ErrorBadRequest)?;
|
||||
Ok(format!(include_str!("../static/pronouns.html"), pronouns.render_threeform()))
|
||||
}
|
||||
|
||||
#[get("/{prefs}")]
|
||||
async fn only_prefs(
|
||||
web::Path(prefs): web::Path<String>,
|
||||
settings: web::Data<InstanceSettings>,
|
||||
) -> Result<impl Responder> {
|
||||
eprintln!("prefs");
|
||||
let pronouns = settings.select_pronouns(None, Some(&prefs)).map_err(ErrorBadRequest)?;
|
||||
Ok(format!(include_str!("../static/pronouns.html"), pronouns.render_threeform()))
|
||||
}
|
||||
|
||||
#[get("/{name}/{prefs}")]
|
||||
async fn prefs_and_name(
|
||||
web::Path((name, prefs)): web::Path<(String, String)>,
|
||||
settings: web::Data<InstanceSettings>,
|
||||
) -> Result<impl Responder> {
|
||||
eprintln!("prefs+name");
|
||||
let pronouns = settings.select_pronouns(Some(&name), Some(&prefs)).map_err(ErrorBadRequest)?;
|
||||
Ok(format!(include_str!("../static/pronouns.html"), pronouns.render_threeform()))
|
||||
}
|
||||
|
||||
#[actix_web::main]
|
||||
async fn main() -> std::io::Result<()> {
|
||||
env_logger::init();
|
||||
HttpServer::new(|| {
|
||||
let logger = Logger::default();
|
||||
App::new()
|
||||
.data(InstanceSettings::default())
|
||||
.wrap(logger)
|
||||
.service(prefs_and_name)
|
||||
.service(only_prefs)
|
||||
.service(default)
|
||||
})
|
||||
.bind("127.0.0.1:8080")?
|
||||
.run()
|
||||
.await
|
||||
}
|
8
web/static/pronouns.html
Normal file
8
web/static/pronouns.html
Normal file
|
@ -0,0 +1,8 @@
|
|||
<html>
|
||||
<head>
|
||||
<title>My Pronouns Today</title>
|
||||
</head>
|
||||
<body>
|
||||
<h1>My pronouns today are: {}</h1>
|
||||
</body>
|
||||
</html>
|
Loading…
Reference in a new issue