mirror of
https://github.com/comfyanonymous/ComfyUI.git
synced 2026-04-17 05:01:08 +02:00
Add deploy environment header to partner node API calls
Read a .comfy_environment file from the ComfyUI base directory to determine the deployment environment (e.g. standalone, portable, desktop). Defaults to 'local_git' when the file is absent. The value is sent as an X-Comfy-Deploy-Env header on all requests to api.comfy.org, allowing the API to differentiate between environment types. The .comfy_environment file is gitignored so launchers/installers can write it without affecting the repository. Co-authored-by: Amp <amp@ampcode.com> Amp-Thread-ID: https://ampcode.com/threads/T-019d939e-6b4d-738b-8d1a-ac7cbf6736a4
This commit is contained in:
parent
1de83f91c3
commit
e7fbb3c2db
1
.gitignore
vendored
1
.gitignore
vendored
@ -24,3 +24,4 @@ web_custom_versions/
|
||||
openapi.yaml
|
||||
filtered-openapi.yaml
|
||||
uv.lock
|
||||
.comfy_environment
|
||||
|
||||
33
comfy/deploy_environment.py
Normal file
33
comfy/deploy_environment.py
Normal file
@ -0,0 +1,33 @@
|
||||
import logging
|
||||
import os
|
||||
|
||||
import folder_paths
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
_DEFAULT_DEPLOY_ENV = "local_git"
|
||||
_ENV_FILENAME = ".comfy_environment"
|
||||
|
||||
_cached_value: str | None = None
|
||||
|
||||
|
||||
def get_deploy_environment() -> str:
|
||||
global _cached_value
|
||||
if _cached_value is not None:
|
||||
return _cached_value
|
||||
|
||||
env_file = os.path.join(folder_paths.base_path, _ENV_FILENAME)
|
||||
try:
|
||||
with open(env_file, encoding="utf-8") as f:
|
||||
first_line = f.readline().strip()
|
||||
value = "".join(c for c in first_line if 32 <= ord(c) < 127)
|
||||
if value:
|
||||
_cached_value = value
|
||||
return _cached_value
|
||||
except FileNotFoundError:
|
||||
pass
|
||||
except Exception as e:
|
||||
logger.warning("Failed to read %s: %s", env_file, e)
|
||||
|
||||
_cached_value = _DEFAULT_DEPLOY_ENV
|
||||
return _cached_value
|
||||
@ -19,6 +19,8 @@ from comfy import utils
|
||||
from comfy_api.latest import IO
|
||||
from server import PromptServer
|
||||
|
||||
from comfy.deploy_environment import get_deploy_environment
|
||||
|
||||
from . import request_logger
|
||||
from ._helpers import (
|
||||
default_base_url,
|
||||
@ -617,6 +619,7 @@ async def _request_base(cfg: _RequestConfig, expect_binary: bool):
|
||||
payload_headers = {"Accept": "*/*"} if expect_binary else {"Accept": "application/json"}
|
||||
if not parsed_url.scheme and not parsed_url.netloc: # is URL relative?
|
||||
payload_headers.update(get_auth_header(cfg.node_cls))
|
||||
payload_headers["X-Comfy-Env"] = get_deploy_environment()
|
||||
if cfg.endpoint.headers:
|
||||
payload_headers.update(cfg.endpoint.headers)
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user