@ezetgalaxy/titan 25.14.7 → 25.14.8

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ezetgalaxy/titan",
3
- "version": "25.14.7",
3
+ "version": "25.14.8",
4
4
  "description": "JavaScript backend framework that compiles your JS into a Rust + Axum server.",
5
5
  "license": "ISC",
6
6
  "author": "ezetgalaxy",
@@ -1,21 +1,21 @@
1
1
  // server/src/main.rs
2
- use std::{collections::HashMap, env, fs, path::Path, path::PathBuf, sync::Arc};
2
+ use std::{collections::HashMap, env, fs, path::PathBuf, sync::Arc, path::Path};
3
3
 
4
4
  use anyhow::Result;
5
5
  use axum::{
6
- Router,
7
- body::{Body, to_bytes},
6
+ body::{to_bytes, Body},
8
7
  extract::State,
9
8
  http::{Request, StatusCode},
10
9
  response::{IntoResponse, Json},
11
10
  routing::any,
11
+ Router,
12
12
  };
13
13
 
14
- use boa_engine::{Context, JsValue, Source, object::ObjectInitializer};
14
+ use boa_engine::{object::ObjectInitializer, Context, JsValue, Source};
15
15
  use boa_engine::{js_string, native_function::NativeFunction, property::Attribute};
16
16
 
17
- use reqwest::blocking::Client;
18
17
  use reqwest::header::{HeaderMap, HeaderName, HeaderValue};
18
+ use reqwest::blocking::Client;
19
19
 
20
20
  use serde::Deserialize;
21
21
  use serde_json::Value;
@@ -152,10 +152,9 @@ fn inject_t_fetch(ctx: &mut Context) {
152
152
  if !header_pairs.is_empty() {
153
153
  let mut headers = HeaderMap::new();
154
154
  for (k, v) in header_pairs.into_iter() {
155
- if let (Ok(name), Ok(val)) = (
156
- HeaderName::from_bytes(k.as_bytes()),
157
- HeaderValue::from_str(&v),
158
- ) {
155
+ if let (Ok(name), Ok(val)) =
156
+ (HeaderName::from_bytes(k.as_bytes()), HeaderValue::from_str(&v))
157
+ {
159
158
  headers.insert(name, val);
160
159
  }
161
160
  }
@@ -231,8 +230,7 @@ async fn dynamic_handler_inner(
231
230
  "action" => {
232
231
  let action_name = route.value.as_str().unwrap_or("").trim();
233
232
  if action_name.is_empty() {
234
- return (StatusCode::INTERNAL_SERVER_ERROR, "Invalid action name")
235
- .into_response();
233
+ return (StatusCode::INTERNAL_SERVER_ERROR, "Invalid action name").into_response();
236
234
  }
237
235
 
238
236
  // Resolve actions directory: prefer resolve_actions_dir(), fall back to heuristic find_actions_dir
@@ -274,56 +272,30 @@ async fn dynamic_handler_inner(
274
272
  };
275
273
 
276
274
  // Build env object
277
- let mut env_map: serde_json::Map<String, Value> = serde_json::Map::new();
275
+ let mut env_map = serde_json::Map::new();
278
276
  for (k, v) in std::env::vars() {
279
277
  env_map.insert(k, Value::String(v));
280
278
  }
281
- let env_json: Value = Value::Object(env_map);
282
-
283
- // Ensure body_str is valid JS: we will embed it as a JS expression.
284
- // If body_str is a JSON object string, embedding it directly is fine.
285
- // But to be safe, we create a quoted JS string and parse it in JS if necessary.
286
- let safe_body_literal: String =
287
- serde_json::to_string(&body_str).unwrap_or_else(|_| "null".to_string());
279
+ let env_json = Value::Object(env_map);
288
280
 
289
- // Injected script: sets process.env, __titan_env, __titan_req and invokes action function.
290
- let injected: String = format!(
281
+ // Injected script: sets process.env and __titan_req and invokes action function.
282
+ let injected = format!(
291
283
  r#"
292
- // Runtime env injected by Titan
293
- globalThis.process = {{ env: {} }};
294
- globalThis.__titan_env = {};
295
- // quick debug so prod logs show whether API key is present
296
- try {{
297
- console.log('TITAN: runtime API_KEY =', (process && process.env && process.env.API_KEY) || (typeof __titan_env !== 'undefined' && __titan_env.API_KEY) || null);
298
- }} catch(e) {{ /* ignore */ }}
299
-
300
- // Parse the incoming request body. If it's a JSON string we parse it into an object.
301
- const __titan_req_body_literal = {};
302
- let __titan_req;
303
- try {{
304
- // it's a quoted JSON string in Rust, so first unquote via JSON.parse
305
- __titan_req = JSON.parse(__titan_req_body_literal);
306
- }} catch (e) {{
307
- // if parse fails, fall back to empty object
308
- __titan_req = {{}};
309
- }}
310
-
311
- // Action code (bundled JS)
312
- {};
313
- // call exported action function
314
- {}(__titan_req);
315
- "#,
316
- env_json.to_string(), // inserted JSON object for process.env
317
- env_json.to_string(), // inserted also as __titan_env
318
- safe_body_literal, // quoted JSON string literal of request body
319
- js_code, // code from the .jsbundle
320
- action_name // call function
284
+ globalThis.process = {{ env: {} }};
285
+ const __titan_req = {};
286
+ {};
287
+ {}(__titan_req);
288
+ "#,
289
+ env_json.to_string(),
290
+ body_str,
291
+ js_code,
292
+ action_name
321
293
  );
322
294
 
323
- let mut ctx: Context = Context::default();
295
+ let mut ctx = Context::default();
324
296
  inject_t_fetch(&mut ctx);
325
297
 
326
- let result: JsValue = match ctx.eval(Source::from_bytes(&injected)) {
298
+ let result = match ctx.eval(Source::from_bytes(&injected)) {
327
299
  Ok(v) => v,
328
300
  Err(e) => return Json(json_error(e.to_string())).into_response(),
329
301
  };
@@ -389,10 +361,7 @@ async fn main() -> Result<()> {
389
361
  println!(" ██║ ██║ ██║ ██╔══██║██║╚██╗██║");
390
362
  println!(" ██║ ██║ ██║ ██║ ██║██║ ╚████║");
391
363
  println!(" ╚═╝ ╚═╝ ╚═╝ ╚═╝ ╚═╝╚═╝ ╚═══╝\x1b[0m\n");
392
- println!(
393
- "\x1b[38;5;39mTitan server running at:\x1b[0m http://localhost:{}",
394
- port
395
- );
364
+ println!("\x1b[38;5;39mTitan server running at:\x1b[0m http://localhost:{}", port);
396
365
 
397
366
  axum::serve(listener, app).await?;
398
367
  Ok(())