Get tp server and ui dev server to talk to each other
This commit is contained in:
parent
328922bd7b
commit
1cb07fb126
5 changed files with 46 additions and 29 deletions
27
meta/dev-thermal-printer
Executable file
27
meta/dev-thermal-printer
Executable 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
4
meta/dev-thermal-printer-ui
Executable file
|
|
@ -0,0 +1,4 @@
|
||||||
|
#!/usr/bin/env fish
|
||||||
|
|
||||||
|
pushd showbits-thermal-printer-ui
|
||||||
|
pnpm dev
|
||||||
|
|
@ -9,4 +9,7 @@ export default defineConfig({
|
||||||
resolve: {
|
resolve: {
|
||||||
alias: { "@": fileURLToPath(new URL("./src", import.meta.url)) },
|
alias: { "@": fileURLToPath(new URL("./src", import.meta.url)) },
|
||||||
},
|
},
|
||||||
|
server: {
|
||||||
|
proxy: { "/api": "http://localhost:8080" },
|
||||||
|
},
|
||||||
});
|
});
|
||||||
|
|
|
||||||
|
|
@ -15,12 +15,13 @@ use self::{drawer::Drawer, persistent_printer::PersistentPrinter};
|
||||||
|
|
||||||
#[derive(Parser)]
|
#[derive(Parser)]
|
||||||
struct Args {
|
struct Args {
|
||||||
/// Address the web server will listen at.
|
|
||||||
addr: String,
|
|
||||||
|
|
||||||
/// Path to the queue directory.
|
/// Path to the queue directory.
|
||||||
queue: PathBuf,
|
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.
|
/// Path to the printer's USB device file.
|
||||||
///
|
///
|
||||||
/// Usually, this is located at `/dev/usb/lp0` or a similar location.
|
/// 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 mut drawer = Drawer::new(rx, printer);
|
||||||
|
|
||||||
let runtime = Runtime::new()?;
|
let runtime = Runtime::new()?;
|
||||||
runtime.spawn(server::run(tx.clone(), args.addr));
|
runtime.spawn(server::run(tx.clone(), args.address));
|
||||||
runtime.spawn(async move {
|
runtime.spawn(async move {
|
||||||
loop {
|
loop {
|
||||||
let _ = tx.send(Command::Backlog).await;
|
let _ = tx.send(Command::Backlog).await;
|
||||||
|
|
|
||||||
|
|
@ -27,31 +27,13 @@ impl Server {
|
||||||
|
|
||||||
pub async fn run(tx: mpsc::Sender<Command>, addr: String) -> anyhow::Result<()> {
|
pub async fn run(tx: mpsc::Sender<Command>, addr: String) -> anyhow::Result<()> {
|
||||||
let app = Router::new()
|
let app = Router::new()
|
||||||
.route(
|
.route("/api/calendar", post(documents::calendar::post))
|
||||||
"/calendar",
|
.route("/api/cells", post(documents::cells::post))
|
||||||
post(documents::calendar::post).fallback(get_static_file),
|
.route("/api/chat", post(documents::chat::post))
|
||||||
)
|
.route("/api/egg", post(documents::egg::post))
|
||||||
.route(
|
.route("/api/image", post(documents::image::post))
|
||||||
"/cells",
|
.route("/api/text", post(documents::text::post))
|
||||||
post(documents::cells::post).fallback(get_static_file),
|
.route("/api/tictactoe", post(documents::tictactoe::post))
|
||||||
)
|
|
||||||
.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),
|
|
||||||
)
|
|
||||||
.fallback(get(get_static_file))
|
.fallback(get(get_static_file))
|
||||||
.layer(DefaultBodyLimit::max(32 * 1024 * 1024)) // 32 MiB
|
.layer(DefaultBodyLimit::max(32 * 1024 * 1024)) // 32 MiB
|
||||||
.with_state(Server { tx });
|
.with_state(Server { tx });
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue