Skip to content

Commit

Permalink
use relative paths for all web connections
Browse files Browse the repository at this point in the history
This enables local reverse-proxies to host ComfyUI on a path, eg "http://example.com/ComfyUI/" in such a way that at least everything I tested works. Without this patch, proxying ComfyUI in this way will yield errors.
  • Loading branch information
mcmonkey4eva committed Jul 10, 2023
1 parent af15add commit 5797ff8
Show file tree
Hide file tree
Showing 17 changed files with 42 additions and 42 deletions.
6 changes: 3 additions & 3 deletions web/extensions/core/clipspace.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { app } from "/scripts/app.js";
import { ComfyDialog, $el } from "/scripts/ui.js";
import { ComfyApp } from "/scripts/app.js";
import { app } from "../../scripts/app.js";
import { ComfyDialog, $el } from "../../scripts/ui.js";
import { ComfyApp } from "../../scripts/app.js";

export class ClipspaceDialog extends ComfyDialog {
static items = [];
Expand Down
4 changes: 2 additions & 2 deletions web/extensions/core/colorPalette.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import {app} from "/scripts/app.js";
import {$el} from "/scripts/ui.js";
import {app} from "../../scripts/app.js";
import {$el} from "../../scripts/ui.js";

// Manage color palettes

Expand Down
2 changes: 1 addition & 1 deletion web/extensions/core/editAttention.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { app } from "/scripts/app.js";
import { app } from "../../scripts/app.js";

// Allows you to edit the attention weight by holding ctrl (or cmd) and using the up/down arrow keys

Expand Down
2 changes: 1 addition & 1 deletion web/extensions/core/invertMenuScrolling.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { app } from "/scripts/app.js";
import { app } from "../../scripts/app.js";

// Inverts the scrolling of context menus

Expand Down
2 changes: 1 addition & 1 deletion web/extensions/core/keybinds.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import {app} from "/scripts/app.js";
import {app} from "../../scripts/app.js";

app.registerExtension({
name: "Comfy.Keybinds",
Expand Down
12 changes: 6 additions & 6 deletions web/extensions/core/maskeditor.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { app } from "/scripts/app.js";
import { ComfyDialog, $el } from "/scripts/ui.js";
import { ComfyApp } from "/scripts/app.js";
import { ClipspaceDialog } from "/extensions/core/clipspace.js";
import { app } from "../../scripts/app.js";
import { ComfyDialog, $el } from "../../scripts/ui.js";
import { ComfyApp } from "../../scripts/app.js";
import { ClipspaceDialog } from "../../extensions/core/clipspace.js";

// Helper function to convert a data URL to a Blob object
function dataURLToBlob(dataURL) {
Expand Down Expand Up @@ -33,15 +33,15 @@ function loadedImageToBlob(image) {
}

async function uploadMask(filepath, formData) {
await fetch('/upload/mask', {
await fetch('./upload/mask', {
method: 'POST',
body: formData
}).then(response => {}).catch(error => {
console.error('Error:', error);
});

ComfyApp.clipspace.imgs[ComfyApp.clipspace['selectedIndex']] = new Image();
ComfyApp.clipspace.imgs[ComfyApp.clipspace['selectedIndex']].src = "/view?" + new URLSearchParams(filepath).toString() + app.getPreviewFormatParam();
ComfyApp.clipspace.imgs[ComfyApp.clipspace['selectedIndex']].src = "./view?" + new URLSearchParams(filepath).toString() + app.getPreviewFormatParam();

if(ComfyApp.clipspace.images)
ComfyApp.clipspace.images[ComfyApp.clipspace['selectedIndex']] = filepath;
Expand Down
4 changes: 2 additions & 2 deletions web/extensions/core/nodeTemplates.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { app } from "/scripts/app.js";
import { ComfyDialog, $el } from "/scripts/ui.js";
import { app } from "../../scripts/app.js";
import { ComfyDialog, $el } from "../../scripts/ui.js";

// Adds the ability to save and add multiple nodes as a template
// To save:
Expand Down
2 changes: 1 addition & 1 deletion web/extensions/core/saveImageExtraOutput.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { app } from "/scripts/app.js";
import { app } from "../../scripts/app.js";

// Use widget values and dates in output filenames

Expand Down
4 changes: 2 additions & 2 deletions web/extensions/core/slotDefaults.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { app } from "/scripts/app.js";
import { ComfyWidgets } from "/scripts/widgets.js";
import { app } from "../../scripts/app.js";
import { ComfyWidgets } from "../../scripts/widgets.js";
// Adds defaults for quickly adding nodes with middle click on the input/output

app.registerExtension({
Expand Down
2 changes: 1 addition & 1 deletion web/extensions/core/snapToGrid.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { app } from "/scripts/app.js";
import { app } from "../../scripts/app.js";

// Shift + drag/resize to snap to grid

Expand Down
2 changes: 1 addition & 1 deletion web/extensions/core/uploadImage.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { app } from "/scripts/app.js";
import { app } from "../../scripts/app.js";

// Adds an upload button to the nodes

Expand Down
4 changes: 2 additions & 2 deletions web/extensions/core/widgetInputs.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { ComfyWidgets, addValueControlWidget } from "/scripts/widgets.js";
import { app } from "/scripts/app.js";
import { ComfyWidgets, addValueControlWidget } from "../../scripts/widgets.js";
import { app } from "../../scripts/app.js";

const CONVERTED_TYPE = "converted-widget";
const VALID_TYPES = ["STRING", "combo", "number"];
Expand Down
10 changes: 5 additions & 5 deletions web/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,12 @@
<meta charset="UTF-8">
<title>ComfyUI</title>
<meta name="viewport" content="width=device-width, initial-scale=1.0, user-scalable=no">
<link rel="stylesheet" type="text/css" href="lib/litegraph.css" />
<link rel="stylesheet" type="text/css" href="style.css" />
<script type="text/javascript" src="lib/litegraph.core.js"></script>
<script type="text/javascript" src="lib/litegraph.extensions.js" defer></script>
<link rel="stylesheet" type="text/css" href="./lib/litegraph.css" />
<link rel="stylesheet" type="text/css" href="./style.css" />
<script type="text/javascript" src="./lib/litegraph.core.js"></script>
<script type="text/javascript" src="./lib/litegraph.extensions.js" defer></script>
<script type="module">
import { app } from "/scripts/app.js";
import { app } from "./scripts/app.js";
await app.setup();
window.app = app;
window.graph = app.graph;
Expand Down
18 changes: 9 additions & 9 deletions web/scripts/api.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ class ComfyApi extends EventTarget {
#pollQueue() {
setInterval(async () => {
try {
const resp = await fetch("/prompt");
const resp = await fetch("./prompt");
const status = await resp.json();
this.dispatchEvent(new CustomEvent("status", { detail: status }));
} catch (error) {
Expand All @@ -40,7 +40,7 @@ class ComfyApi extends EventTarget {
existingSession = "?clientId=" + existingSession;
}
this.socket = new WebSocket(
`ws${window.location.protocol === "https:" ? "s" : ""}://${location.host}/ws${existingSession}`
`ws${window.location.protocol === "https:" ? "s" : ""}://${location.host}${location.pathname}ws${existingSession}`
);
this.socket.binaryType = "arraybuffer";

Expand Down Expand Up @@ -149,7 +149,7 @@ class ComfyApi extends EventTarget {
* @returns An array of script urls to import
*/
async getExtensions() {
const resp = await fetch("/extensions", { cache: "no-store" });
const resp = await fetch("./extensions", { cache: "no-store" });
return await resp.json();
}

Expand All @@ -158,7 +158,7 @@ class ComfyApi extends EventTarget {
* @returns An array of script urls to import
*/
async getEmbeddings() {
const resp = await fetch("/embeddings", { cache: "no-store" });
const resp = await fetch("./embeddings", { cache: "no-store" });
return await resp.json();
}

Expand All @@ -167,7 +167,7 @@ class ComfyApi extends EventTarget {
* @returns The node definitions
*/
async getNodeDefs() {
const resp = await fetch("object_info", { cache: "no-store" });
const resp = await fetch("./object_info", { cache: "no-store" });
return await resp.json();
}

Expand All @@ -189,7 +189,7 @@ class ComfyApi extends EventTarget {
body.number = number;
}

const res = await fetch("/prompt", {
const res = await fetch("./prompt", {
method: "POST",
headers: {
"Content-Type": "application/json",
Expand Down Expand Up @@ -222,7 +222,7 @@ class ComfyApi extends EventTarget {
*/
async getQueue() {
try {
const res = await fetch("/queue");
const res = await fetch("./queue");
const data = await res.json();
return {
// Running action uses a different endpoint for cancelling
Expand All @@ -244,7 +244,7 @@ class ComfyApi extends EventTarget {
*/
async getHistory() {
try {
const res = await fetch("/history");
const res = await fetch("./history");
return { History: Object.values(await res.json()) };
} catch (error) {
console.error(error);
Expand All @@ -259,7 +259,7 @@ class ComfyApi extends EventTarget {
*/
async #postItem(type, body) {
try {
await fetch("/" + type, {
await fetch("./" + type, {
method: "POST",
headers: {
"Content-Type": "application/json",
Expand Down
4 changes: 2 additions & 2 deletions web/scripts/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -404,7 +404,7 @@ export class ComfyApp {
this.images = output.images;
imagesChanged = true;
imgURLs = imgURLs.concat(output.images.map(params => {
return "/view?" + new URLSearchParams(params).toString() + app.getPreviewFormatParam();
return "./view?" + new URLSearchParams(params).toString() + app.getPreviewFormatParam();
}))
}
}
Expand Down Expand Up @@ -1005,7 +1005,7 @@ export class ComfyApp {
const extensions = await api.getExtensions();
for (const ext of extensions) {
try {
await import(ext);
await import(".." + ext);
} catch (error) {
console.error("Error loading extension", ext, error);
}
Expand Down
4 changes: 2 additions & 2 deletions web/scripts/widgets.js
Original file line number Diff line number Diff line change
Expand Up @@ -305,7 +305,7 @@ export const ComfyWidgets = {
subfolder = name.substring(0, folder_separator);
name = name.substring(folder_separator + 1);
}
img.src = `/view?filename=${name}&type=input&subfolder=${subfolder}${app.getPreviewFormatParam()}`;
img.src = `./view?filename=${name}&type=input&subfolder=${subfolder}${app.getPreviewFormatParam()}`;
node.setSizeForImage?.();
}

Expand Down Expand Up @@ -362,7 +362,7 @@ export const ComfyWidgets = {
// Wrap file in formdata so it includes filename
const body = new FormData();
body.append("image", file);
const resp = await fetch("/upload/image", {
const resp = await fetch("./upload/image", {
method: "POST",
body,
});
Expand Down
2 changes: 1 addition & 1 deletion web/types/comfy.d.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { LGraphNode, IWidget } from "./litegraph";
import { ComfyApp } from "/scripts/app";
import { ComfyApp } from "../../scripts/app";

export interface ComfyExtension {
/**
Expand Down

0 comments on commit 5797ff8

Please sign in to comment.