How to add custom routes outside server.py #10760
-
|
Every time I need to add a new route, I have to modify |
Beta Was this translation helpful? Give feedback.
Answered by
CodingOctocat
Nov 17, 2025
Replies: 1 comment
-
|
I found the answer. 📂 ComfyUI/
└── 📂 custom_nodes/
├── 📝 __init__.py
├── 📝 your_routes1.py
├── 📝 your_routes2.py
└── ...# __init__.py
import os
import importlib
from pathlib import Path
current_dir = Path(__file__).parent
for file in current_dir.glob("*.py"):
if file.name != "__init__.py":
module_name = file.stem
importlib.import_module(f".{module_name}", package=__package__)
NODE_CLASS_MAPPINGS = {}
NODE_DISPLAY_NAME_MAPPINGS = {}# your_routes.py
import os
import asyncio
from aiohttp import web
import folder_paths
import server
import logging
logger = logging.getLogger(__name__)
routes = server.PromptServer.instance.routes
@routes.get("/your_api")
async def your_api(request):
passThen, simply restart ComfyUI. |
Beta Was this translation helpful? Give feedback.
0 replies
Answer selected by
CodingOctocat
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I found the answer.
📂 ComfyUI/ └── 📂 custom_nodes/ ├── 📝 __init__.py ├── 📝 your_routes1.py ├── 📝 your_routes2.py └── ...