filename const fix
This commit is contained in:
parent
6601686581
commit
c38a5b634c
2 changed files with 10 additions and 8 deletions
|
@ -3,10 +3,10 @@
|
||||||
original by zatzou
|
original by zatzou
|
||||||
|
|
||||||
# how to use?
|
# how to use?
|
||||||
- change the port in the code, I've set it to 8081
|
- change the port in the code, I've set it to 8080 by default
|
||||||
- build using `cargo build --release` (install Rust lang)
|
- build using `cargo build --release` (install Rust lang to get cargo)
|
||||||
- setup on server as a service
|
- setup on server as a service
|
||||||
- get a reverse proxy e.g. nginx or haproxy
|
- get a reverse proxy e.g. nginx or haproxy
|
||||||
- point to your domain and subdomain
|
- point to your domain and subdomain
|
||||||
- add dns record for it
|
- add dns record for it
|
||||||
- find it at (subdomain).(domain).(topleveldomain)/ip.png
|
- find it at (subdomain).(domain).(topleveldomain)/ip.png
|
||||||
|
|
12
src/main.rs
12
src/main.rs
|
@ -11,10 +11,10 @@
|
||||||
/////////////////////////////////////
|
/////////////////////////////////////
|
||||||
|
|
||||||
const IPADDRESS: &str = "0.0.0.0";
|
const IPADDRESS: &str = "0.0.0.0";
|
||||||
const PORT: &str = "8080";
|
const PORT: &str = "8081";
|
||||||
const FONTFILENAME: &str = "Roboto-Regular.ttf"
|
const FONTFILENAME: &str = "Roboto-Regular.ttf";
|
||||||
|
|
||||||
use std::{io::Cursor, net::SocketAddr};
|
use std::{io::Cursor, net::SocketAddr, fs};
|
||||||
|
|
||||||
use ab_glyph::FontRef;
|
use ab_glyph::FontRef;
|
||||||
use axum::{extract::State, http::header, response::IntoResponse, routing::get, Router};
|
use axum::{extract::State, http::header, response::IntoResponse, routing::get, Router};
|
||||||
|
@ -22,12 +22,14 @@ use axum_client_ip::InsecureClientIp;
|
||||||
use image::Rgba;
|
use image::Rgba;
|
||||||
use imageproc::drawing::{self, text_size};
|
use imageproc::drawing::{self, text_size};
|
||||||
|
|
||||||
|
|
||||||
#[tokio::main]
|
#[tokio::main]
|
||||||
async fn main() {
|
async fn main() {
|
||||||
let networkaddress = format!("{IPADDRESS}:{PORT}");
|
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 font = FontRef::try_from_slice(fontfile).unwrap();
|
||||||
|
|
||||||
let app = Router::new().route("/ip.png", get(ip_png)).with_state(font);
|
let app = Router::new().route("/ip.png", get(ip_png)).with_state(font);
|
||||||
|
|
Loading…
Reference in a new issue