api - chrisgoringe/Comfy-Custom-Node-How-To GitHub Wiki

How to add a route to the server api

In your custom node python file...

from server import PromptServer
from aiohttp import web
routes = PromptServer.instance.routes
@routes.post('/a_new_path')
async def my_hander_method(request):
    post = await request.post()
    x = post.get("something")
    return web.json_response({})

In the javascript, the code is something like:

function send_message(message) {
    const body = new FormData();
    body.append('something',message);
    api.fetchApi("/a_new_path", { method: "POST", body, });
}