include const time host info for reqwest endpoint

This commit is contained in:
2024-12-23 20:24:50 -06:00
parent 0ab8ad9660
commit c288c52517
2 changed files with 10 additions and 3 deletions

View File

@@ -3,7 +3,7 @@ FROM rust:latest AS builder-demo
WORKDIR /build/demo WORKDIR /build/demo
RUN apt update && apt install -y g++-mingw-w64-x86-64 RUN apt update && apt install -y g++-mingw-w64-x86-64
ARG RAILWAY_PUBLIC_DOMAIN
RUN rustup target add x86_64-pc-windows-gnu RUN rustup target add x86_64-pc-windows-gnu
RUN rustup target add x86_64-unknown-linux-gnu RUN rustup target add x86_64-unknown-linux-gnu

View File

@@ -10,10 +10,17 @@ struct KeyData<'a> {
} }
static KEY: &'static str = include_str!(concat!(env!("OUT_DIR"), "/key.json")); static KEY: &'static str = include_str!(concat!(env!("OUT_DIR"), "/key.json"));
const HOST_INFO: (&'static str, &'static str) = match option_env!("RAILWAY_PUBLIC_DOMAIN") {
Some(domain) => ("https", domain),
None => ("http", "localhost"),
};
fn main() { fn main() {
let key_data: KeyData = serde_json::from_str(KEY).unwrap(); let key_data: KeyData = serde_json::from_str(KEY).unwrap();
let (protocol, domain) = HOST_INFO;
println!("Protocol: {}, Domain: {}", protocol, domain);
// Print the key data // Print the key data
let args: Vec<String> = std::env::args().collect(); let args: Vec<String> = std::env::args().collect();
if args.contains(&"--help".to_string()) { if args.contains(&"--help".to_string()) {
@@ -38,8 +45,8 @@ fn main() {
let client = reqwest::blocking::Client::new(); let client = reqwest::blocking::Client::new();
let response = client let response = client
.post(&format!( .post(&format!(
"http://localhost:5800/notify?key={}", "{}://{}/notify?key={}",
key_data.value HOST_INFO.0, HOST_INFO.1, key_data.value
)) ))
.send(); .send();