Skip to content

Commit 3225d7c

Browse files
authored
Make dev server ready for use (#43)
* basic dev server * nit * Return empty extensions list for dev server * Update readme
1 parent 3fca50b commit 3225d7c

File tree

5 files changed

+27
-11
lines changed

5 files changed

+27
-11
lines changed

README.md

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,6 @@ in ComfyUI's front-end code.
1818

1919
## Development
2020

21-
Currently the dev server does not work as the ws runs on root path '/', and all api endpoints are all defined on '/'. There might need to be some API changes before dev server can work.
22-
2321
- Run `npm install` to install the necessary packages
2422
- Start local ComfyUI backend at `localhost:8188`
2523
- Run `npm run dev` to start the dev server

src/scripts/api.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,11 @@ class ComfyApi extends EventTarget {
3131
this.initialClientId = sessionStorage.getItem("clientId");
3232
}
3333

34-
apiURL(route) {
34+
apiURL(route: string): string {
35+
return this.api_base + "/api" + route;
36+
}
37+
38+
fileURL(route: string): string {
3539
return this.api_base + route;
3640
}
3741

src/scripts/app.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1510,7 +1510,7 @@ export class ComfyApp {
15101510
.filter(extension => !extension.includes("extensions/core"))
15111511
.map(async ext => {
15121512
try {
1513-
await import(/* @vite-ignore */api.apiURL(ext));
1513+
await import(/* @vite-ignore */api.fileURL(ext));
15141514
} catch (error) {
15151515
console.error("Error loading extension", ext, error);
15161516
}

tests-ui/utils/setup.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,8 @@ export interface APIConfig {
2626
*/
2727

2828
/**
29-
* @param {{
30-
* mockExtensions?: string[],
29+
* @param {{
30+
* mockExtensions?: string[],
3131
* mockNodeDefs?: Record<string, ComfyObjectInfo>,
3232
* settings?: Record<string, string>
3333
* userConfig?: {storage: "server" | "browser", users?: Record<string, any>, migrated?: boolean },
@@ -59,6 +59,7 @@ export function mockApi(config: APIConfig = {}) {
5959
getNodeDefs: jest.fn(() => mockNodeDefs),
6060
init: jest.fn(),
6161
apiURL: jest.fn((x) => "src/" + x),
62+
fileURL: jest.fn((x) => "src/" + x),
6263
createUser: jest.fn((username) => {
6364
// @ts-ignore
6465
if(username in userConfig.users) {

vite.config.mts

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import { defineConfig, Plugin } from 'vite';
22
import { viteStaticCopy } from 'vite-plugin-static-copy'
33
import path from 'path';
44

5+
const IS_DEV = process.env.NODE_ENV === 'development';
56

67
interface ShimResult {
78
code: string;
@@ -12,6 +13,9 @@ function comfyAPIPlugin(): Plugin {
1213
return {
1314
name: 'comfy-api-plugin',
1415
transform(code: string, id: string) {
16+
if (IS_DEV)
17+
return null;
18+
1519
// TODO: Remove second condition after all js files are converted to ts
1620
if (id.endsWith('.ts') || (id.endsWith('.js') && id.includes("extensions/core"))) {
1721
const result = transformExports(code, id);
@@ -74,20 +78,29 @@ function getModuleName(id: string): string {
7478

7579
export default defineConfig({
7680
server: {
77-
open: true,
7881
proxy: {
79-
// Proxy websocket requests to the server
80-
'/': {
82+
'/api': {
83+
target: 'http://127.0.0.1:8188',
84+
// Return empty array for extensions API as these modules
85+
// are not on vite's dev server.
86+
bypass: (req, res, options) => {
87+
if (req.url === '/api/extensions') {
88+
res.end(JSON.stringify([]));
89+
}
90+
return null;
91+
},
92+
},
93+
'/ws': {
8194
target: 'ws://127.0.0.1:8188',
8295
ws: true,
83-
}
96+
},
8497
}
8598
},
8699
plugins: [
87100
comfyAPIPlugin(),
88101
viteStaticCopy({
89102
targets: [
90-
{src: "src/lib/*", dest: "lib/"},
103+
{ src: "src/lib/*", dest: "lib/" },
91104
],
92105
}),
93106
],

0 commit comments

Comments
 (0)