Skip to content

Self-hosted, Self-Improving, Federated Everything App — dev management, agent orchestration, persistent mind, digital twin, second brain, and creative pipeline from a single dashboard over Tailscale to port the user into the OS

fix(apps): label Vite dev ports as devUi when API process coexists

Adam Eivy4fed50c8266c
diff --git a/server/routes/apps.js b/server/routes/apps.js
index 777ad60c59..1ddddf8dda 100644
--- a/server/routes/apps.js
+++ b/server/routes/apps.js
@@ -97,6 +97,11 @@ router.get('/', asyncHandler(async (req, res) => {
const devUiProc = processes.find(p => p.ports?.devUi);
if (devUiProc) devUiPort = devUiProc.ports.devUi;
}
+ // When app has API + Vite dev processes but no dedicated UI port,
+ // the prod UI is served by the API server
+ if (!uiPort && apiPort && devUiPort) {
+ uiPort = apiPort;
+ }
return {
...app,
@@ -149,6 +154,11 @@ router.get('/:id', loadApp, asyncHandler(async (req, res) => {
const devUiProc = processes.find(p => p.ports?.devUi);
if (devUiProc) devUiPort = devUiProc.ports.devUi;
}
+ // When app has API + Vite dev processes but no dedicated UI port,
+ // the prod UI is served by the API server
+ if (!uiPort && apiPort && devUiPort) {
+ uiPort = apiPort;
+ }
// Read version from app's package.json if available
let appVersion = null;
diff --git a/server/routes/apps.test.js b/server/routes/apps.test.js
index 6693146dcd..217910bf38 100644
--- a/server/routes/apps.test.js
+++ b/server/routes/apps.test.js
@@ -310,6 +310,28 @@ describe('Apps Routes', () => {
expect(response.body[0].devUiPort).toBe(5554);
});
+ it('should derive uiPort from apiPort when app has devUi but no ui process', async () => {
+ const mockApps = [{
+ id: 'app-001',
+ name: 'Test App',
+ pm2ProcessNames: ['test-api', 'test-ui'],
+ repoPath: '/tmp/test',
+ processes: [
+ { name: 'test-api', ports: { api: 5551 } },
+ { name: 'test-ui', ports: { devUi: 5550 } }
+ ]
+ }];
+ appsService.getAllApps.mockResolvedValue(mockApps);
+ pm2Service.listProcesses.mockResolvedValue([]);
+
+ const response = await request(app).get('/api/apps');
+
+ expect(response.status).toBe(200);
+ expect(response.body[0].uiPort).toBe(5551);
+ expect(response.body[0].devUiPort).toBe(5550);
+ expect(response.body[0].apiPort).toBe(5551);
+ });
+
it('should use explicit devUiPort over derived value', async () => {
const mockApps = [{
id: 'app-001',
diff --git a/server/services/pm2Standardizer.js b/server/services/pm2Standardizer.js
index 377f5b2f0c..904b8acae7 100644
--- a/server/services/pm2Standardizer.js
+++ b/server/services/pm2Standardizer.js
@@ -121,6 +121,7 @@ ${context.viteConfigs.map(f => `#### ${f.name}\n\`\`\`javascript\n${f.content}\n
5. **Vite processes**: Use \`npx vite --host --port XXXX\` in args, disable watch (Vite has HMR)
6. **Set cwd** for each process pointing to its directory
7. **Include NODE_ENV** in all env blocks
+8. **UI vs Dev UI ports**: When the API server serves the production build of the frontend (Express static files), the production UI port equals the API port. The Vite dev server port is a separate "dev UI" port only used during development. Label Vite dev ports as WEB/DEV_UI in the PORTS object, not as UI.
## Output Format
@@ -497,7 +498,14 @@ export function getStandardTemplate() {
return `// PM2 Ecosystem Configuration Template
// All ports should be defined here, not in .env or vite.config
+// Port definitions as single source of truth
+const PORTS = {
+ API: 3001, // Express API server (also serves prod UI build)
+ WEB: 3000 // Vite dev server (development only)
+};
+
module.exports = {
+ PORTS,
apps: [
{
name: 'myapp-server',
@@ -508,18 +516,18 @@ module.exports = {
ignore_watch: ['node_modules', 'data', '*.log'],
env: {
NODE_ENV: 'development',
- PORT: 3001
+ PORT: PORTS.API
}
},
{
name: 'myapp-client',
cwd: './client',
script: 'npx',
- args: 'vite --host --port 3000',
+ args: 'vite --host --port ' + PORTS.WEB,
watch: false,
env: {
NODE_ENV: 'development',
- PORT: 3000
+ VITE_PORT: PORTS.WEB
}
}
]
diff --git a/server/services/streamingDetect.js b/server/services/streamingDetect.js
index 394839a2ea..16ed4dd3d7 100644
--- a/server/services/streamingDetect.js
+++ b/server/services/streamingDetect.js
@@ -275,10 +275,25 @@ export function parseEcosystemConfig(content) {
// Check if this process uses vite (need to check vite.config in cwd)
const usesVite = /\bvite\b/i.test(appBlock);
- processes.push({ name: processName, port, ports, cwd, usesVite });
+ processes.push({ name: processName, port, ports, cwd, usesVite, isViteProcess: usesVite });
lastIndex = endPos;
}
+ // Post-process: when an app has both an API process and Vite dev processes,
+ // relabel Vite ports from 'ui' to 'devUi' since the prod UI is served by the API.
+ const hasApiProcess = processes.some(p => p.ports?.api);
+ if (hasApiProcess) {
+ for (const proc of processes) {
+ if (proc.isViteProcess && proc.ports?.ui && !proc.ports?.devUi) {
+ proc.ports.devUi = proc.ports.ui;
+ delete proc.ports.ui;
+ // Update primary port reference
+ const portValues = Object.values(proc.ports);
+ proc.port = portValues.length > 0 ? portValues[0] : null;
+ }
+ }
+ }
+
return { processes, pm2Home };
}
@@ -321,6 +336,7 @@ export async function parseEcosystemFromPath(dirPath) {
// Clean up internal properties before returning
delete proc.cwd;
delete proc.usesVite;
+ delete proc.isViteProcess;
}
return { processes, pm2Home };
@@ -341,6 +357,7 @@ export async function streamDetection(socket, dirPath) {
name: '',
description: '',
uiPort: null,
+ devUiPort: null,
apiPort: null,
startCommands: [],
pm2ProcessNames: [],
@@ -471,15 +488,29 @@ export async function streamDetection(socket, dirPath) {
// Clean up internal properties
delete proc.cwd;
delete proc.usesVite;
+ delete proc.isViteProcess;
}
result.processes = parsedProcesses;
result.pm2ProcessNames = parsedProcesses.map(p => p.name);
- // Set apiPort from first process with a port (usually the main server)
- const processWithPort = parsedProcesses.find(p => p.port);
- if (processWithPort && !result.apiPort) {
- result.apiPort = processWithPort.port;
+ // Derive ports from parsed processes
+ const apiProc = parsedProcesses.find(p => p.ports?.api);
+ if (apiProc && !result.apiPort) {
+ result.apiPort = apiProc.ports.api;
+ }
+ const uiProc = parsedProcesses.find(p => p.ports?.ui);
+ if (uiProc && !result.uiPort) {
+ result.uiPort = uiProc.ports.ui;
+ }
+ const devUiProc = parsedProcesses.find(p => p.ports?.devUi);
+ if (devUiProc && !result.devUiPort) {
+ result.devUiPort = devUiProc.ports.devUi;
+ }
+ // When app has API + Vite dev but no dedicated UI port,
+ // the prod UI is served by the API server
+ if (!result.uiPort && result.apiPort && result.devUiPort) {
+ result.uiPort = result.apiPort;
}
}
@@ -497,6 +528,7 @@ export async function streamDetection(socket, dirPath) {
emit('config', 'done', {
message: configFiles.length ? `Found: ${configFiles.join(', ')}` : 'No config files found',
uiPort: result.uiPort,
+ devUiPort: result.devUiPort,
apiPort: result.apiPort,
pm2ProcessNames: result.pm2ProcessNames.length > 0 ? result.pm2ProcessNames : undefined,
processes: result.processes.length > 0 ? result.processes : undefined,