diff --git a/README.md b/README.md index 3644eb7..cc8e103 100644 --- a/README.md +++ b/README.md @@ -3,10 +3,10 @@ original by zatzou # how to use? -- change the port in the code, I've set it to 8081 -- build using `cargo build --release` (install Rust lang) +- change the port in the code, I've set it to 8080 by default +- build using `cargo build --release` (install Rust lang to get cargo) - setup on server as a service - get a reverse proxy e.g. nginx or haproxy - point to your domain and subdomain - add dns record for it -- find it at (subdomain).(domain).(topleveldomain)/ip.png +- find it at (subdomain).(domain).(topleveldomain)/ip.png diff --git a/src/main.rs b/src/main.rs index e746b64..90dc9dc 100644 --- a/src/main.rs +++ b/src/main.rs @@ -11,10 +11,10 @@ ///////////////////////////////////// const IPADDRESS: &str = "0.0.0.0"; -const PORT: &str = "8080"; -const FONTFILENAME: &str = "Roboto-Regular.ttf" +const PORT: &str = "8081"; +const FONTFILENAME: &str = "Roboto-Regular.ttf"; -use std::{io::Cursor, net::SocketAddr}; +use std::{io::Cursor, net::SocketAddr, fs}; use ab_glyph::FontRef; use axum::{extract::State, http::header, response::IntoResponse, routing::get, Router}; @@ -22,12 +22,14 @@ use axum_client_ip::InsecureClientIp; use image::Rgba; use imageproc::drawing::{self, text_size}; + #[tokio::main] async fn main() { let networkaddress = format!("{IPADDRESS}:{PORT}"); - let fontname2 = format!("../{FONTFILENAME}") + let fontname2 = format!("./{FONTFILENAME}"); - let fontfile = include_bytes!(fontname2); + let fontfile = Box::new(fs::read(fontname2).unwrap()); + let fontfile: &mut [u8] = fontfile.leak(); let font = FontRef::try_from_slice(fontfile).unwrap(); let app = Router::new().route("/ip.png", get(ip_png)).with_state(font);