Get tp server and ui dev server to talk to each other

This commit is contained in:
Joscha 2025-03-03 00:26:47 +01:00
parent 328922bd7b
commit 1cb07fb126
5 changed files with 46 additions and 29 deletions

27
meta/dev-thermal-printer Executable file
View file

@ -0,0 +1,27 @@
#!/usr/bin/env fish
argparse h/help p/print r/release -- $argv
and not set -ql _flag_help
or begin
echo "Usage:" (status filename) "[OPTIONS]"
echo
echo "Options:"
echo " -h, --help Show this help"
echo " -p, --print Attach to printer at /dev/usb/lp0"
echo " -r, --release Use 'cargo run --release'"
return
end
set -l arg_release
if set -ql _flag_release
set arg_release --release
end
set -l arg_print
if set -ql _flag_print
set arg_print -p /dev/usb/lp0
end
cargo run $arg_release \
--package showbits-thermal-printer \
-- target/queue -e target/image.png $arg_print

4
meta/dev-thermal-printer-ui Executable file
View file

@ -0,0 +1,4 @@
#!/usr/bin/env fish
pushd showbits-thermal-printer-ui
pnpm dev

View file

@ -9,4 +9,7 @@ export default defineConfig({
resolve: {
alias: { "@": fileURLToPath(new URL("./src", import.meta.url)) },
},
server: {
proxy: { "/api": "http://localhost:8080" },
},
});

View file

@ -15,12 +15,13 @@ use self::{drawer::Drawer, persistent_printer::PersistentPrinter};
#[derive(Parser)]
struct Args {
/// Address the web server will listen at.
addr: String,
/// Path to the queue directory.
queue: PathBuf,
/// Address the web server will listen at.
#[arg(long, short, default_value = "localhost:8080")]
address: String,
/// Path to the printer's USB device file.
///
/// Usually, this is located at `/dev/usb/lp0` or a similar location.
@ -41,7 +42,7 @@ fn main() -> anyhow::Result<()> {
let mut drawer = Drawer::new(rx, printer);
let runtime = Runtime::new()?;
runtime.spawn(server::run(tx.clone(), args.addr));
runtime.spawn(server::run(tx.clone(), args.address));
runtime.spawn(async move {
loop {
let _ = tx.send(Command::Backlog).await;

View file

@ -27,31 +27,13 @@ impl Server {
pub async fn run(tx: mpsc::Sender<Command>, addr: String) -> anyhow::Result<()> {
let app = Router::new()
.route(
"/calendar",
post(documents::calendar::post).fallback(get_static_file),
)
.route(
"/cells",
post(documents::cells::post).fallback(get_static_file),
)
.route(
"/chat",
post(documents::chat::post).fallback(get_static_file),
)
.route("/egg", post(documents::egg::post).fallback(get_static_file))
.route(
"/image",
post(documents::image::post).fallback(get_static_file),
)
.route(
"/text",
post(documents::text::post).fallback(get_static_file),
)
.route(
"/tictactoe",
post(documents::tictactoe::post).fallback(get_static_file),
)
.route("/api/calendar", post(documents::calendar::post))
.route("/api/cells", post(documents::cells::post))
.route("/api/chat", post(documents::chat::post))
.route("/api/egg", post(documents::egg::post))
.route("/api/image", post(documents::image::post))
.route("/api/text", post(documents::text::post))
.route("/api/tictactoe", post(documents::tictactoe::post))
.fallback(get(get_static_file))
.layer(DefaultBodyLimit::max(32 * 1024 * 1024)) // 32 MiB
.with_state(Server { tx });