Support ComfyUI hosted on relative URLs Closes #3208

5739efc59b2233374d2fbb7ac7be242f1cad0b22

Cohee <18619528+Cohee1207@users.noreply.github.com>

2 files changed, +11 -10Showing whitespace changes
public/scripts/extensions/stable-diffusion/index.js+2 -1
@@ -1111,7 +1111,8 @@ function onHrSecondPassStepsInput() {
1111}1111}
11121112
1113function onComfyUrlInput() {1113function onComfyUrlInput() {
1114 extension_settings.sd.comfy_url = $('#sd_comfy_url').val();1114 // Remove trailing slashes
1115 extension_settings.sd.comfy_url = String($('#sd_comfy_url').val() ?? '').replace(/\/$/, '');
1115 saveSettingsDebounced();1116 saveSettingsDebounced();
1116}1117}
11171118
src/endpoints/stable-diffusion.js+9 -9
@@ -365,7 +365,7 @@ const comfy = express.Router();
365comfy.post('/ping', jsonParser, async (request, response) => {365comfy.post('/ping', jsonParser, async (request, response) => {
366 try {366 try {
367 const url = new URL(request.body.url);367 const url = new URL(request.body.url);
368 url.pathname = '/system_stats';368 url.pathname += '/system_stats';
369369
370 const result = await fetch(url);370 const result = await fetch(url);
371 if (!result.ok) {371 if (!result.ok) {
@@ -382,7 +382,7 @@ comfy.post('/ping', jsonParser, async (request, response) => {
382comfy.post('/samplers', jsonParser, async (request, response) => {382comfy.post('/samplers', jsonParser, async (request, response) => {
383 try {383 try {
384 const url = new URL(request.body.url);384 const url = new URL(request.body.url);
385 url.pathname = '/object_info';385 url.pathname += '/object_info';
386386
387 const result = await fetch(url);387 const result = await fetch(url);
388 if (!result.ok) {388 if (!result.ok) {
@@ -401,7 +401,7 @@ comfy.post('/samplers', jsonParser, async (request, response) => {
401comfy.post('/models', jsonParser, async (request, response) => {401comfy.post('/models', jsonParser, async (request, response) => {
402 try {402 try {
403 const url = new URL(request.body.url);403 const url = new URL(request.body.url);
404 url.pathname = '/object_info';404 url.pathname += '/object_info';
405405
406 const result = await fetch(url);406 const result = await fetch(url);
407 if (!result.ok) {407 if (!result.ok) {
@@ -430,7 +430,7 @@ comfy.post('/models', jsonParser, async (request, response) => {
430comfy.post('/schedulers', jsonParser, async (request, response) => {430comfy.post('/schedulers', jsonParser, async (request, response) => {
431 try {431 try {
432 const url = new URL(request.body.url);432 const url = new URL(request.body.url);
433 url.pathname = '/object_info';433 url.pathname += '/object_info';
434434
435 const result = await fetch(url);435 const result = await fetch(url);
436 if (!result.ok) {436 if (!result.ok) {
@@ -449,7 +449,7 @@ comfy.post('/schedulers', jsonParser, async (request, response) => {
449comfy.post('/vaes', jsonParser, async (request, response) => {449comfy.post('/vaes', jsonParser, async (request, response) => {
450 try {450 try {
451 const url = new URL(request.body.url);451 const url = new URL(request.body.url);
452 url.pathname = '/object_info';452 url.pathname += '/object_info';
453453
454 const result = await fetch(url);454 const result = await fetch(url);
455 if (!result.ok) {455 if (!result.ok) {
@@ -517,14 +517,14 @@ comfy.post('/delete-workflow', jsonParser, async (request, response) => {
517comfy.post('/generate', jsonParser, async (request, response) => {517comfy.post('/generate', jsonParser, async (request, response) => {
518 try {518 try {
519 const url = new URL(request.body.url);519 const url = new URL(request.body.url);
520 url.pathname = '/prompt';520 url.pathname += '/prompt';
521521
522 const controller = new AbortController();522 const controller = new AbortController();
523 request.socket.removeAllListeners('close');523 request.socket.removeAllListeners('close');
524 request.socket.on('close', function () {524 request.socket.on('close', function () {
525 if (!response.writableEnded && !item) {525 if (!response.writableEnded && !item) {
526 const interruptUrl = new URL(request.body.url);526 const interruptUrl = new URL(request.body.url);
527 interruptUrl.pathname = '/interrupt';527 interruptUrl.pathname += '/interrupt';
528 fetch(interruptUrl, { method: 'POST', headers: { 'Authorization': getBasicAuthHeader(request.body.auth) } });528 fetch(interruptUrl, { method: 'POST', headers: { 'Authorization': getBasicAuthHeader(request.body.auth) } });
529 }529 }
530 controller.abort();530 controller.abort();
@@ -544,7 +544,7 @@ comfy.post('/generate', jsonParser, async (request, response) => {
544 const id = data.prompt_id;544 const id = data.prompt_id;
545 let item;545 let item;
546 const historyUrl = new URL(request.body.url);546 const historyUrl = new URL(request.body.url);
547 historyUrl.pathname = '/history';547 historyUrl.pathname += '/history';
548 while (true) {548 while (true) {
549 const result = await fetch(historyUrl);549 const result = await fetch(historyUrl);
550 if (!result.ok) {550 if (!result.ok) {
@@ -569,7 +569,7 @@ comfy.post('/generate', jsonParser, async (request, response) => {
569 }569 }
570 const imgInfo = Object.keys(item.outputs).map(it => item.outputs[it].images).flat()[0];570 const imgInfo = Object.keys(item.outputs).map(it => item.outputs[it].images).flat()[0];
571 const imgUrl = new URL(request.body.url);571 const imgUrl = new URL(request.body.url);
572 imgUrl.pathname = '/view';572 imgUrl.pathname += '/view';
573 imgUrl.search = `?filename=${imgInfo.filename}&subfolder=${imgInfo.subfolder}&type=${imgInfo.type}`;573 imgUrl.search = `?filename=${imgInfo.filename}&subfolder=${imgInfo.subfolder}&type=${imgInfo.type}`;
574 const imgResponse = await fetch(imgUrl);574 const imgResponse = await fetch(imgUrl);
575 if (!imgResponse.ok) {575 if (!imgResponse.ok) {