aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorChristine Dodrill <me@christine.website>2021-04-01 22:30:45 -0400
committerGitHub <noreply@github.com>2021-04-01 22:30:45 -0400
commit8383914aa5abc232fa56ce437e777d5024eb63e1 (patch)
treebedceacc5a8e1260e73d251a84d44838a3e25acb /src
parent0360c87582e2e5025c06fec2431b867992dc71b0 (diff)
downloadxesite-8383914aa5abc232fa56ce437e777d5024eb63e1.tar.xz
xesite-8383914aa5abc232fa56ce437e777d5024eb63e1.zip
Unix domain socket http server (#352)
* enable ipv6 support Signed-off-by: Christine Dodrill <me@christine.website> * enable unix socket powers Signed-off-by: Christine Dodrill <me@christine.website> * unix domain socket post Signed-off-by: Christine Dodrill <me@christine.website> * bump rust Signed-off-by: Christine Dodrill <me@christine.website>
Diffstat (limited to 'src')
-rw-r--r--src/app/markdown.rs12
-rw-r--r--src/main.rs39
2 files changed, 35 insertions, 16 deletions
diff --git a/src/app/markdown.rs b/src/app/markdown.rs
index fe33a21..1410776 100644
--- a/src/app/markdown.rs
+++ b/src/app/markdown.rs
@@ -1,8 +1,8 @@
+use crate::templates::Html;
use color_eyre::eyre::{Result, WrapErr};
use comrak::nodes::{Ast, AstNode, NodeValue};
-use comrak::{format_html, parse_document, markdown_to_html, Arena, ComrakOptions};
+use comrak::{format_html, markdown_to_html, parse_document, Arena, ComrakOptions};
use std::cell::RefCell;
-use crate::templates::Html;
use url::Url;
pub fn render(inp: &str) -> Result<String> {
@@ -29,6 +29,7 @@ pub fn render(inp: &str) -> Result<String> {
if u.scheme() != "conversation" {
return Ok(());
}
+ let smol = u.query().unwrap_or("").contains("smol");
let parent = node.parent().unwrap();
node.detach();
let mut message = vec![];
@@ -41,10 +42,11 @@ pub fn render(inp: &str) -> Result<String> {
let name = u.host_str().unwrap_or("Mara");
let mut html = vec![];
- crate::templates::mara(&mut html, mood, name, Html(message))?;
+ crate::templates::mara(&mut html, mood, name, Html(message.trim().into()), smol)?;
- let new_node =
- arena.alloc(AstNode::new(RefCell::new(Ast::new(NodeValue::HtmlInline(html)))));
+ let new_node = arena.alloc(AstNode::new(RefCell::new(Ast::new(
+ NodeValue::HtmlInline(html),
+ ))));
parent.append(new_node);
Ok(())
diff --git a/src/main.rs b/src/main.rs
index 7ebfbdf..cac19cf 100644
--- a/src/main.rs
+++ b/src/main.rs
@@ -4,7 +4,11 @@ extern crate tracing;
use color_eyre::eyre::Result;
use hyper::{header::CONTENT_TYPE, Body, Response};
use prometheus::{Encoder, TextEncoder};
+use std::net::IpAddr;
+use std::str::FromStr;
use std::sync::Arc;
+use tokio::net::UnixListener;
+use tokio_stream::wrappers::UnixListenerStream;
use warp::{path, Filter};
pub mod app;
@@ -232,17 +236,30 @@ async fn main() -> Result<()> {
}
}
- warp::serve(site)
- .run((
- [0, 0, 0, 0],
- std::env::var("PORT")
- .unwrap_or("3030".into())
- .parse::<u16>()
- .unwrap(),
- ))
- .await;
-
- Ok(())
+ let server = warp::serve(site);
+
+ match std::env::var("SOCKPATH") {
+ Ok(sockpath) => {
+ let _ = std::fs::remove_file(&sockpath);
+ let listener = UnixListener::bind(sockpath)?;
+ let incoming = UnixListenerStream::new(listener);
+ server.run_incoming(incoming).await;
+
+ Ok(())
+ }
+ Err(_) => {
+ server
+ .run((
+ IpAddr::from_str(&std::env::var("HOST").unwrap_or("::".into()))?,
+ std::env::var("PORT")
+ .unwrap_or("3030".into())
+ .parse::<u16>()?,
+ ))
+ .await;
+
+ Ok(())
+ }
+ }
}
include!(concat!(env!("OUT_DIR"), "/templates.rs"));