Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

File endpoints: use query parameters for NGINX/Caddy compatibility #6376

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

bigcat88
Copy link
Contributor

@bigcat88 bigcat88 commented Jan 7, 2025

PR Description

When deploying ComfyUI behind NGINX, we encountered issues with file-related endpoints due to the use of path parameters for file paths. Proxy servers may modify the encoding of URLs, leading to inconsistent behavior. For example:

  • The server may receive:
    http://127.0.0.1:8188/api/userdata/workflows%2Fphoto_stickers2.json?overwrite=false&full_info=true
  • But proxies like NGINX may decode it to:
    http://127.0.0.1:8188/api/userdata/workflows/photo_stickers2.json?overwrite=false&full_info=true

This inconsistency caused the ComfyUI server to respond with a 405 Method Not Allowed status.

Changes Made:

  • Updated the file-related endpoints (getuserdata, post_userdata, delete_userdata, and move_userdata) to use query parameters instead of path parameters for file paths. This ensures compatibility with proxy servers by avoiding reliance on URL path encoding.
  • For the move_userdata endpoint, both the source and destination paths are now passed as query parameters (source and dest).

Notes:

  • The FrontEnd must be updated to reflect these changes, as the file paths have been moved from path parameters to query parameters.
  • Old endpoints were not touched, compatibility with old frontends will not be broken.

This PR replaces old PR #6363 which was only a workaround which we applied on server to temporary make ComfyUI work.

Resolves: #5629

Partially fixes problem from #4534

@bigcat88 bigcat88 changed the title File endpoints: use query parameters for proxy compatibility File endpoints: use query parameters for NGINX/Caddy compatibility Jan 12, 2025
@bigcat88
Copy link
Contributor Author

If necessary, I can theoretically write a test for this, but I'm not sure that the design of endpoint should be covered by tests.

I can describe in more detail why these changes are needed, but in the linked issues that were not created by me, everything seems clear.

@asagi4
Copy link
Contributor

asagi4 commented Jan 16, 2025

This PR might be easier to merge if you supported both types of endpoint, so that people who have an older or alternative frontend don't just break since the frontend can be installed separately from the backend and isn't guaranteed to be in sync.

For nginx specifically, it seems it urlencodes the path if your proxy_pass directive contains a url path component. So

proxy_pass http://127.0.0.1:8188;

works properly, but

proxy_pass http://127.0.0.1:8188/;

or anything specifying a subpath does not

@bigcat88 bigcat88 force-pushed the fix/user_manager/file-endpoints branch from 7e1ae9b to 720b03e Compare January 16, 2025 12:40
@bigcat88
Copy link
Contributor Author

Thank you very much for the correct and accurate remark, - re-pushed the commit.

After your remark:

  1. All old endpoints remain in place and are not touched.
  2. The same endpoints are added but with the /v1 prefix in the path - they use query parameters.
  3. Tests use new endpoints.
  4. Old endpoints can be removed after some time.

Is there anything else that is missing?

@lupsin
Copy link

lupsin commented Jan 22, 2025

May I ask about the approximate date when this or a similar PR that corrects this situation might be merged?

@vojtajina
Copy link

+1 for solving this problem, would be nice to be able to run caddy in front of Comfy (to get HTTPS).

@AIConquistador
Copy link

+1 to this, using Traefik for HTTPS

@bigcat88
Copy link
Contributor Author

bigcat88 commented Feb 7, 2025

@comfyanonymous hello. sorry to bother you, but can you ask @huchenlei or @robinjhuang to take a look at this PR/problem when they have some free time.

Thanks in advance

Copy link
Collaborator

@webfiltered webfiltered left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not in a position to review this properly right now, but here are some quick suggestions to make it easier to review / test the PR.

app/user_manager.py Outdated Show resolved Hide resolved
@bigcat88 bigcat88 force-pushed the fix/user_manager/file-endpoints branch from 720b03e to 0895b86 Compare February 8, 2025 06:19
…parameters for proxy compatibility

Signed-off-by: bigcat88 <[email protected]>
@bigcat88 bigcat88 force-pushed the fix/user_manager/file-endpoints branch from 0895b86 to 0c2067a Compare February 8, 2025 06:21
@bigcat88 bigcat88 requested a review from webfiltered February 8, 2025 16:10
@chenFe-1
Copy link

chenFe-1 commented Feb 10, 2025

I have updated comfyui to the latest version, why does this problem still occur? Description When deploying ComfyUI behind NGINX, we encountered issues with file-related endpoints due to the use of path parameters for file paths. Proxy servers may modify the encoding of URLs, leading to inconsistent behavior. For example: I can not store my workflow the request and response
image

my comfyui info by start log (comfyui) /mnt/workspace/ComfyUI> python main.py [START] Security scan [DONE] Security scan

ComfyUI-Manager: installing dependencies done.

** ComfyUI startup time: 2025-02-10 17:12:46.975 ** Platform: Linux ** Python version: 3.12.5 | packaged by Anaconda, Inc. | (main, Sep 12 2024, 18:27:27) [GCC 11.2.0] ** Python executable: /home/pai/envs/comfyui/bin/python ** ComfyUI Path: /mnt/workspace/ComfyUI ** User directory: /mnt/workspace/ComfyUI/user ** ComfyUI-Manager config path: /mnt/workspace/ComfyUI/user/default/ComfyUI-Manager/config.ini ** Log path: /mnt/workspace/ComfyUI/user/comfyui.log

Prestartup times for custom nodes: 1.5 seconds: /mnt/workspace/ComfyUI/custom_nodes/ComfyUI-Manager

Checkpoint files will always be loaded safely. Total VRAM 22516 MB, total RAM 65536 MB pytorch version: 2.5.1 Set vram state to: NORMAL_VRAM Device: cuda:0 NVIDIA A10 : cudaMallocAsync Using pytorch attention ComfyUI version: 0.3.14 [Prompt Server] web root: /mnt/workspace/ComfyUI/web

Loading: ComfyUI-Manager (V3.7.4)

ComfyUI Version: v0.3.14-12-g4027466c | Released on '2025-02-10'

[comfyui_controlnet_aux] | INFO -> Using ckpts path: /mnt/workspace/ComfyUI/custom_nodes/comfyui_controlnet_aux/ckpts [comfyui_controlnet_aux] | INFO -> Using symlinks: False [comfyui_controlnet_aux] | INFO -> Using ort providers: ['CUDAExecutionProvider', 'DirectMLExecutionProvider', 'OpenVINOExecutionProvider', 'ROCMExecutionProvider', 'CPUExecutionProvider', 'CoreMLExecutionProvider'] [ComfyUI-Manager] default cache updated: https://raw.githubusercontent.com/ltdrdata/ComfyUI-Manager/main/model-list.json [ComfyUI-Manager] default cache updated: https://raw.githubusercontent.com/ltdrdata/ComfyUI-Manager/main/custom-node-list.json [ComfyUI-Manager] default cache updated: https://raw.githubusercontent.com/ltdrdata/ComfyUI-Manager/main/alter-list.json [ComfyUI-Manager] default cache updated: https://raw.githubusercontent.com/ltdrdata/ComfyUI-Manager/main/extension-node-map.json [ComfyUI-Manager] default cache updated: https://raw.githubusercontent.com/ltdrdata/ComfyUI-Manager/main/github-stats.json FETCH DATA from: /mnt/workspace/ComfyUI/user/default/ComfyUI-Manager/cache/2233941102_nodes_page_1_limit_1000.json [DONE] /mnt/workspace/ComfyUI/custom_nodes/comfyui_controlnet_aux/node_wrappers/dwpose.py:26: UserWarning: DWPose: Onnxruntime not found or doesn't come with acceleration providers, switch to OpenCV with CPU device. DWPose might run very slowly warnings.warn("DWPose: Onnxruntime not found or doesn't come with acceleration providers, switch to OpenCV with CPU device. DWPose might run very slowly") nightly_channel: https://raw.githubusercontent.com/ltdrdata/ComfyUI-Manager/main/cache FETCH DATA from: /mnt/workspace/ComfyUI/user/default/ComfyUI-Manager/cache/1514988643_custom-node-list.json [DONE]

Import times for custom nodes: 0.0 seconds: /mnt/workspace/ComfyUI/custom_nodes/websocket_image_save.py 0.1 seconds: /mnt/workspace/ComfyUI/custom_nodes/ComfyUI-Custom-Scripts 0.2 seconds: /mnt/workspace/ComfyUI/custom_nodes/ComfyUI-Manager 0.7 seconds: /mnt/workspace/ComfyUI/custom_nodes/comfyui_controlnet_aux

Starting server

To see the GUI go to: http://127.0.0.1:8188

my nginx config
image

@bigcat88
Copy link
Contributor Author

I have updated comfyui to the latest version

For this PR to work, you need to switch to it, and also rebuild the frontend (which is in another repository) with the linked PR.

Or just wait until someone from the Comfy organization finds time to review this PR for merge.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

api/userdata/workflows 405
7 participants