MCPcopy Create free account
hub / github.com/codename-co/stack / init

Function init

packages/app/src-tauri/src/api.rs:63–123  ·  view source on GitHub ↗
(tauri: AppHandle)

Source from the content-addressed store, hash-verified

61
62#[actix_web::main]
63pub async fn init(tauri: AppHandle) -> std::io::Result<()> {
64 log::info!("Initializing API");
65
66 let app_data = web::Data::new(AppState {
67 tauri: tauri.clone(),
68 });
69
70 // Load SSL keys
71 let mut builder = SslAcceptor::mozilla_intermediate(SslMethod::tls()).unwrap();
72
73 let key_path = tauri
74 .app_handle()
75 .path()
76 .resolve("certs/key.pem", BaseDirectory::Resource)
77 .unwrap();
78 builder
79 .set_private_key_file(&key_path, SslFiletype::PEM)
80 .map_err(|e| {
81 log::error!("Failed to set private key file: {}", e);
82 std::io::Error::new(std::io::ErrorKind::Other, e)
83 })?;
84 log::debug!("Private key file set successfully");
85
86 let cert_path = tauri
87 .app_handle()
88 .path()
89 .resolve("certs/cert.pem", BaseDirectory::Resource)
90 .unwrap();
91 builder.set_certificate_chain_file(cert_path).map_err(|e| {
92 log::error!("Failed to set certificate chain file: {}", e);
93 std::io::Error::new(std::io::ErrorKind::Other, e)
94 })?;
95 log::debug!("Certificate chain file set successfully");
96
97 let http_server = HttpServer::new(move || {
98 let cors = Cors::default()
99 .allowed_origin_fn(|origin, _req_head| {
100 origin.to_str().map_or(false, |orig| {
101 debug!("Origin: {:?}", orig);
102 ["https://stack.lol", "https://exodus.stack.lol", "http://localhost:4321"].contains(&orig)
103 })
104 })
105 // .allow_any_origin()
106 .allow_any_method()
107 .allow_any_header()
108 .max_age(3600);
109 App::new()
110 .app_data(app_data.clone())
111 .wrap(cors)
112 .service(index)
113 .service(health)
114 .service(run)
115 })
116 .bind_openssl("0.0.0.0:57404", builder)?
117 .run();
118
119 log::info!("Server started at https://0.0.0.0:57404");
120 println!("Server started at https://0.0.0.0:57404");

Callers 1

runFunction · 0.70

Calls

no outgoing calls

Tested by

no test coverage detected