Cleanup: Remove old modes, add Svelte 5 reference library, update orchestrator
- Delete Mode1Test, Mode2Test, Mode3Test, Mode5Test (keep only Mode6Test) - Delete old documentation, Docker files, and k8s configs - Add comprehensive Svelte 5 reference library (svelte-reference/) - Update ModeSwitch orchestrator: - Fix port to 3005 (never use 3000/3001) - Add API endpoints for mode switching - Add bun-types and proper tsconfig - Clean up mode folder mappings
This commit is contained in:
@@ -1,23 +1,19 @@
|
||||
import { Hono } from 'hono';
|
||||
import { serveStatic } from 'hono/bun';
|
||||
import { spawn } from 'bun';
|
||||
import fs from 'fs';
|
||||
import { cors } from 'hono/cors';
|
||||
import * as fs from 'node:fs';
|
||||
|
||||
// Configuration
|
||||
const MODES_DIR = '/home/admin/Job-Info-Test';
|
||||
const MODE_CONFIG_FILE = `${MODES_DIR}/ModeSwitch/activeMode.txt`;
|
||||
const SHARED_PORT = 3005;
|
||||
const ORCHESTRATOR_PORT = 3006;
|
||||
const SHARED_PORT = 3005; // Mode services run here - NEVER use 3000 or 3001
|
||||
const ORCHESTRATOR_PORT = 3006; // Orchestrator API runs here
|
||||
|
||||
// Mode folder mappings
|
||||
// Mode folder mappings - only Mode6Test exists currently
|
||||
const MODE_FOLDERS: Record<string, string> = {
|
||||
'Mode1Test': 'Mode1Test',
|
||||
'Mode2Test': 'Mode2Test',
|
||||
'Mode3Test': 'Mode3Test',
|
||||
'Mode5Test': 'Mode5Test',
|
||||
'Mode6Test': 'Mode6Test',
|
||||
};
|
||||
|
||||
let currentMode: string = 'Mode1Test';
|
||||
let currentMode: string = 'Mode6Test';
|
||||
let currentProcess: any = null;
|
||||
|
||||
// Helper: Read active mode from config file
|
||||
@@ -25,12 +21,14 @@ function readActiveMode(): string {
|
||||
try {
|
||||
if (fs.existsSync(MODE_CONFIG_FILE)) {
|
||||
const content = fs.readFileSync(MODE_CONFIG_FILE, 'utf-8').trim();
|
||||
return content || 'Test1Mode';
|
||||
if (content && MODE_FOLDERS[content]) {
|
||||
return content;
|
||||
}
|
||||
}
|
||||
} catch (err) {
|
||||
console.error('Failed to read mode config:', err);
|
||||
}
|
||||
return 'Mode1Test';
|
||||
return 'Mode6Test';
|
||||
}
|
||||
|
||||
// Helper: Write active mode to config file
|
||||
@@ -82,13 +80,8 @@ async function startMode(mode: string): Promise<boolean> {
|
||||
|
||||
console.log(`[ModeSwitch] Starting ${mode} (${folderName}/) on port ${SHARED_PORT}...`);
|
||||
|
||||
// Determine server path based on mode
|
||||
// Mode2Test uses AuthAndToken/backend/server.ts
|
||||
// Mode1Test and Mode3Test use backend/server.ts
|
||||
let serverPath = 'backend/server.ts';
|
||||
if (mode === 'Mode2Test') {
|
||||
serverPath = 'AuthAndToken/backend/server.ts';
|
||||
}
|
||||
// Determine server path - all modes use backend/server.ts
|
||||
const serverPath = 'backend/server.ts';
|
||||
|
||||
// Start the mode's backend server
|
||||
currentProcess = Bun.spawn({
|
||||
@@ -128,6 +121,74 @@ async function startMode(mode: string): Promise<boolean> {
|
||||
// Initialize app
|
||||
const app = new Hono();
|
||||
|
||||
// Enable CORS
|
||||
app.use('*', cors());
|
||||
|
||||
// API: Get current mode status
|
||||
app.get('/status', (c) => {
|
||||
return c.json({
|
||||
currentMode,
|
||||
availableModes: Object.keys(MODE_FOLDERS),
|
||||
sharedPort: SHARED_PORT,
|
||||
orchestratorPort: ORCHESTRATOR_PORT,
|
||||
});
|
||||
});
|
||||
|
||||
// API: Switch to a different mode
|
||||
app.post('/switch/:mode', async (c) => {
|
||||
const mode = c.req.param('mode');
|
||||
|
||||
if (!MODE_FOLDERS[mode]) {
|
||||
return c.json({
|
||||
success: false,
|
||||
error: `Unknown mode: ${mode}. Available: ${Object.keys(MODE_FOLDERS).join(', ')}`
|
||||
}, 400);
|
||||
}
|
||||
|
||||
if (mode === currentMode) {
|
||||
return c.json({
|
||||
success: true,
|
||||
message: `Already running ${mode}`,
|
||||
currentMode
|
||||
});
|
||||
}
|
||||
|
||||
const success = await startMode(mode);
|
||||
|
||||
if (success) {
|
||||
return c.json({
|
||||
success: true,
|
||||
message: `Switched to ${mode}`,
|
||||
currentMode: mode
|
||||
});
|
||||
} else {
|
||||
return c.json({
|
||||
success: false,
|
||||
error: `Failed to start ${mode}`
|
||||
}, 500);
|
||||
}
|
||||
});
|
||||
|
||||
// API: Restart current mode
|
||||
app.post('/restart', async (c) => {
|
||||
console.log(`[ModeSwitch] Restarting ${currentMode}...`);
|
||||
const success = await startMode(currentMode);
|
||||
|
||||
return c.json({
|
||||
success,
|
||||
message: success ? `Restarted ${currentMode}` : `Failed to restart ${currentMode}`,
|
||||
currentMode
|
||||
});
|
||||
});
|
||||
|
||||
// API: List available modes
|
||||
app.get('/modes', (c) => {
|
||||
return c.json({
|
||||
modes: Object.keys(MODE_FOLDERS),
|
||||
currentMode
|
||||
});
|
||||
});
|
||||
|
||||
// Startup message
|
||||
console.log(`
|
||||
================================================================================
|
||||
|
||||
Reference in New Issue
Block a user