-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathquick-start.js
More file actions
115 lines (89 loc) · 2.93 KB
/
Copy pathquick-start.js
File metadata and controls
115 lines (89 loc) · 2.93 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
#!/usr/bin/env node
const { spawn } = require('child_process');
const fs = require('fs');
const path = require('path');
console.log('🚀 OpenCap Quick Start Script');
console.log('==============================\n');
// Check if we're in the right directory
const projectRoot = '/Volumes/Cody/projects/opencap-clean';
const frontendDir = path.join(projectRoot, 'frontend');
// Check if directories exist
if (!fs.existsSync(projectRoot)) {
console.error('❌ Project root directory not found:', projectRoot);
process.exit(1);
}
if (!fs.existsSync(frontendDir)) {
console.error('❌ Frontend directory not found:', frontendDir);
process.exit(1);
}
console.log('✅ Project directories found');
console.log('📂 Project root:', projectRoot);
console.log('📂 Frontend dir:', frontendDir);
// Function to start backend
function startBackend() {
console.log('\n🔧 Starting Backend Server...');
const backend = spawn('/opt/homebrew/bin/node', ['app.js'], {
cwd: projectRoot,
stdio: ['inherit', 'pipe', 'pipe'],
env: { ...process.env, NODE_ENV: 'development' }
});
backend.stdout.on('data', (data) => {
console.log('BACKEND:', data.toString().trim());
});
backend.stderr.on('data', (data) => {
console.error('BACKEND ERROR:', data.toString().trim());
});
backend.on('error', (error) => {
console.error('❌ Backend failed to start:', error.message);
});
return backend;
}
// Function to start frontend
function startFrontend() {
console.log('\n🎨 Starting Frontend Server...');
const frontend = spawn('/opt/homebrew/bin/npm', ['run', 'dev'], {
cwd: frontendDir,
stdio: ['inherit', 'pipe', 'pipe'],
env: { ...process.env, PATH: '/opt/homebrew/bin:' + process.env.PATH }
});
frontend.stdout.on('data', (data) => {
console.log('FRONTEND:', data.toString().trim());
});
frontend.stderr.on('data', (data) => {
console.error('FRONTEND ERROR:', data.toString().trim());
});
frontend.on('error', (error) => {
console.error('❌ Frontend failed to start:', error.message);
});
return frontend;
}
// Start both servers
const backendProcess = startBackend();
const frontendProcess = startFrontend();
// Handle shutdown
function shutdown() {
console.log('\n🛑 Shutting down servers...');
if (backendProcess) {
backendProcess.kill('SIGTERM');
}
if (frontendProcess) {
frontendProcess.kill('SIGTERM');
}
setTimeout(() => {
process.exit(0);
}, 2000);
}
process.on('SIGINT', shutdown);
process.on('SIGTERM', shutdown);
// Wait a moment then show URLs
setTimeout(() => {
console.log('\n🌐 Servers should be starting...');
console.log('📍 Backend API: http://localhost:5000');
console.log('📍 Frontend App: http://localhost:5173');
console.log('📚 API Docs: http://localhost:5000/api-docs');
console.log('\n💡 Press Ctrl+C to stop both servers');
}, 3000);
// Keep the script running
setInterval(() => {
// Just keep alive
}, 1000);