diff --git a/nodes.py b/nodes.py index bdea7564b..e475b9b17 100644 --- a/nodes.py +++ b/nodes.py @@ -2033,6 +2033,9 @@ NODE_DISPLAY_NAME_MAPPINGS = { EXTENSION_WEB_DIRS = {} +# Dictionary of successfully loaded module names and associated directories. +LOADED_MODULE_DIRS = {} + def get_module_name(module_path: str) -> str: """ @@ -2074,6 +2077,8 @@ def load_custom_node(module_path: str, ignore=set(), module_parent="custom_nodes sys.modules[module_name] = module module_spec.loader.exec_module(module) + LOADED_MODULE_DIRS[module_name] = os.path.abspath(module_dir) + if hasattr(module, "WEB_DIRECTORY") and getattr(module, "WEB_DIRECTORY") is not None: web_dir = os.path.abspath(os.path.join(module_dir, getattr(module, "WEB_DIRECTORY"))) if os.path.isdir(web_dir): diff --git a/server.py b/server.py index d0238f618..c868dffab 100644 --- a/server.py +++ b/server.py @@ -723,6 +723,13 @@ class PromptServer(): self.app.add_routes(api_routes) self.app.add_routes(self.routes) + # Add routes for workflow templates in custom nodes. + for module_name, module_dir in nodes.LOADED_MODULE_DIRS.items(): + workflows_dir = os.path.join(module_dir, 'example_workflows') + if os.path.exists(workflows_dir): + self.app.add_routes([web.static('/workflow_templates/' + module_name, workflows_dir)]) + + # Add routes from web extensions. for name, dir in nodes.EXTENSION_WEB_DIRS.items(): self.app.add_routes([web.static('/extensions/' + name, dir)])