Buffy commited on
Commit
71ea0d0
·
1 Parent(s): ba9ed6e

Ship Next.js standalone backend bundle (6MB xz) for userspace Node runtime

Browse files

node_runtime.py now extracts backend-bundle/respite-backend.tar.xz before
launching server.js. Provider keys set as Space secrets via Hub API.

backend-bundle/respite-backend.tar.xz ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:71ec3b6e07d58ca02886cd78a53d7e93d34a81069246ea17bb988e0b6c2edfec
3
+ size 6204324
node_runtime.py CHANGED
@@ -71,14 +71,29 @@ def _wait_ready(proc: subprocess.Popen, timeout: float = 90.0) -> bool:
71
  return False
72
 
73
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
74
  def start_node_backend() -> bool:
75
  """Launch the Next.js standalone server. Safe to call once at startup."""
76
  global _node_proc
77
  if os.environ.get("NODE_PROXY_OFF") == "1":
78
  _log("disabled via NODE_PROXY_OFF")
79
  return False
80
- if not os.path.isdir(BACKEND_DIR):
81
- _log(f"backend dir missing: {BACKEND_DIR}")
82
  return False
83
  with _node_lock:
84
  if _node_proc and _node_proc.poll() is None:
 
71
  return False
72
 
73
 
74
+ def _ensure_backend_extracted() -> bool:
75
+ """Extract backend-bundle/respite-backend.tar.xz if the backend dir is absent."""
76
+ if os.path.isdir(BACKEND_DIR) and os.path.exists(os.path.join(BACKEND_DIR, "server.js")):
77
+ return True
78
+ bundle = os.path.join(os.path.dirname(os.path.abspath(__file__)), "backend-bundle", "respite-backend.tar.xz")
79
+ if not os.path.exists(bundle):
80
+ _log(f"no bundle at {bundle}")
81
+ return False
82
+ _log(f"extracting {bundle} -> {BACKEND_DIR}")
83
+ os.makedirs(BACKEND_DIR, exist_ok=True)
84
+ with tarfile.open(bundle, "r:xz") as tf:
85
+ tf.extractall(BACKEND_DIR)
86
+ _log("backend extracted")
87
+ return True
88
+
89
+
90
  def start_node_backend() -> bool:
91
  """Launch the Next.js standalone server. Safe to call once at startup."""
92
  global _node_proc
93
  if os.environ.get("NODE_PROXY_OFF") == "1":
94
  _log("disabled via NODE_PROXY_OFF")
95
  return False
96
+ if not _ensure_backend_extracted():
 
97
  return False
98
  with _node_lock:
99
  if _node_proc and _node_proc.poll() is None: