allow setting IP

This commit is contained in:
SpikeHD 2022-05-16 22:19:19 -07:00
parent e7287673f5
commit b55767b276
3 changed files with 22 additions and 2 deletions

View File

@ -19,6 +19,7 @@ fn main() {
.invoke_handler(tauri::generate_handler![
connect,
disconnect,
proxy::set_proxy_addr,
run_program,
run_jar,
unzip::unzip,

View File

@ -3,6 +3,9 @@
* https://github.com/omjadas/hudsucker/blob/main/examples/log.rs
*/
use lazy_static::lazy_static;
use std::sync::Mutex;
use hudsucker::{
async_trait::async_trait,
certificate_authority::RcgenAuthority,
@ -21,9 +24,22 @@ async unsafe fn shutdown_signal() {
.expect("Failed to install CTRL+C signal handler");
}
// Global ver for getting server address
lazy_static!{
static ref SERVER: Mutex<String> = {
let m = "localhost:443".to_string();
Mutex::new(m)
};
}
#[derive(Clone)]
struct ProxyHandler;
#[tauri::command]
pub fn set_proxy_addr(addr: String){
*SERVER.lock().unwrap() = addr;
}
#[async_trait]
impl HttpHandler for ProxyHandler {
async fn handle_request(&mut self,
@ -39,8 +55,8 @@ impl HttpHandler for ProxyHandler {
// Check URI against constraints.
if path.contains("hoyoverse.com") || path.contains("mihoyo.com") || path.contains("yuanshen.com") {
println!("uri path: {}", uri.path());
uri = format!("https://127.0.0.1:443{}", uri.path()).parse::<Uri>().unwrap();
println!("uri path: {}{}", *SERVER.lock().unwrap(), uri.path());
uri = format!("https://{}{}", *SERVER.lock().unwrap(), uri.path()).parse::<Uri>().unwrap();
}
let builder = Request::builder()

View File

@ -82,6 +82,9 @@ export default class ServerLaunchSection extends React.Component<IProps, IState>
await setConfigOption('last_ip', this.state.ip)
await setConfigOption('last_port', this.state.port)
// Set IP
await invoke('set_proxy_addr', { addr: this.state.ip + ':' + this.state.port })
// Connect to proxy
await invoke('connect', { port: 8365 })
}