@gv-sh/specgen-app 0.6.6 โ 0.6.8
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +1 -1
- package/package.json +1 -1
- package/scripts/deploy-8080.sh.bak +15 -15
- package/scripts/deploy.sh +92 -339
- package/scripts/production-low-memory.sh.bak +14 -14
- package/scripts/production.sh +16 -16
- package/scripts/setup.sh +14 -14
package/README.md
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
# SpecGen App - Complete Platform
|
2
2
|
|
3
|
-
[](https://github.com/gv-sh/specgen-app)
|
4
4
|
|
5
5
|
A unified deployment package for the SpecGen speculative fiction generator platform. **Optimized for port 8080 deployment with low memory usage.**
|
6
6
|
|
package/package.json
CHANGED
@@ -1,9 +1,9 @@
|
|
1
1
|
#!/bin/bash
|
2
2
|
|
3
|
-
# SpecGen Deploy Script - Port
|
3
|
+
# SpecGen Deploy Script - Port 80 Production Deployment
|
4
4
|
set -e
|
5
5
|
|
6
|
-
echo "๐ Deploying SpecGen to production on port
|
6
|
+
echo "๐ Deploying SpecGen to production on port 80..."
|
7
7
|
|
8
8
|
# Function to check if port is available
|
9
9
|
check_port() {
|
@@ -20,11 +20,11 @@ echo "Stopping existing PM2 processes..."
|
|
20
20
|
npx pm2 stop all 2>/dev/null || true
|
21
21
|
npx pm2 delete all 2>/dev/null || true
|
22
22
|
|
23
|
-
# Kill any processes on port
|
24
|
-
echo "Freeing port
|
25
|
-
if ! check_port
|
26
|
-
echo "Port
|
27
|
-
lsof -ti:
|
23
|
+
# Kill any processes on port 80
|
24
|
+
echo "Freeing port 80..."
|
25
|
+
if ! check_port 80; then
|
26
|
+
echo "Port 80 is in use. Attempting to free it..."
|
27
|
+
lsof -ti:80 | xargs kill -9 2>/dev/null || true
|
28
28
|
sleep 2
|
29
29
|
fi
|
30
30
|
|
@@ -64,7 +64,7 @@ module.exports = {
|
|
64
64
|
cwd: process.cwd(),
|
65
65
|
env: {
|
66
66
|
NODE_ENV: 'production',
|
67
|
-
PORT:
|
67
|
+
PORT: 80
|
68
68
|
},
|
69
69
|
instances: 1,
|
70
70
|
exec_mode: 'fork',
|
@@ -83,8 +83,8 @@ EOF
|
|
83
83
|
mkdir -p logs
|
84
84
|
|
85
85
|
# Start with PM2
|
86
|
-
echo "Starting SpecGen with PM2 on port
|
87
|
-
NODE_ENV=production PORT=
|
86
|
+
echo "Starting SpecGen with PM2 on port 80..."
|
87
|
+
NODE_ENV=production PORT=80 npx pm2 start ecosystem.config.js
|
88
88
|
|
89
89
|
# Wait for startup
|
90
90
|
sleep 5
|
@@ -93,11 +93,11 @@ echo ""
|
|
93
93
|
echo "โ
SpecGen deployment completed!"
|
94
94
|
echo ""
|
95
95
|
echo "๐ Access your application at:"
|
96
|
-
echo " - Main page: http://$(curl -s ifconfig.me 2>/dev/null || echo 'your-server'):
|
97
|
-
echo " - User app: http://$(curl -s ifconfig.me 2>/dev/null || echo 'your-server'):
|
98
|
-
echo " - Admin panel: http://$(curl -s ifconfig.me 2>/dev/null || echo 'your-server'):
|
99
|
-
echo " - API docs: http://$(curl -s ifconfig.me 2>/dev/null || echo 'your-server'):
|
100
|
-
echo " - Health check: http://$(curl -s ifconfig.me 2>/dev/null || echo 'your-server'):
|
96
|
+
echo " - Main page: http://$(curl -s ifconfig.me 2>/dev/null || echo 'your-server'):80/"
|
97
|
+
echo " - User app: http://$(curl -s ifconfig.me 2>/dev/null || echo 'your-server'):80/app"
|
98
|
+
echo " - Admin panel: http://$(curl -s ifconfig.me 2>/dev/null || echo 'your-server'):80/admin"
|
99
|
+
echo " - API docs: http://$(curl -s ifconfig.me 2>/dev/null || echo 'your-server'):80/api-docs"
|
100
|
+
echo " - Health check: http://$(curl -s ifconfig.me 2>/dev/null || echo 'your-server'):80/api/health"
|
101
101
|
echo ""
|
102
102
|
echo "๐ Check status with: npx pm2 status"
|
103
103
|
echo "๐ View logs with: npx pm2 logs specgen"
|
package/scripts/deploy.sh
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
#!/bin/bash
|
2
2
|
|
3
|
-
# SpecGen Deploy Script - Self-Contained Deployment on Port
|
3
|
+
# SpecGen Deploy Script - Self-Contained Deployment on Port 80
|
4
4
|
set -e
|
5
5
|
|
6
6
|
# Check for dry-run mode
|
@@ -10,7 +10,7 @@ if [ "$1" = "--dry-run" ] || [ "$1" = "-d" ]; then
|
|
10
10
|
echo "๐งช DRY RUN MODE - Testing deployment locally"
|
11
11
|
echo "๐ฅ๏ธ Platform: $(uname -s) $(uname -m)"
|
12
12
|
else
|
13
|
-
echo "๐ Deploying SpecGen to production on port
|
13
|
+
echo "๐ Deploying SpecGen to production on port 80..."
|
14
14
|
echo "๐ฆ This is a complete deployment - no separate setup needed!"
|
15
15
|
fi
|
16
16
|
|
@@ -25,13 +25,7 @@ check_port() {
|
|
25
25
|
}
|
26
26
|
|
27
27
|
# Get absolute path of current working directory
|
28
|
-
|
29
|
-
if [ "$DRY_RUN" = true ]; then
|
30
|
-
PROJECT_DIR=$(pwd)
|
31
|
-
else
|
32
|
-
PROJECT_DIR=$(pwd)
|
33
|
-
fi
|
34
|
-
|
28
|
+
PROJECT_DIR=$(pwd)
|
35
29
|
echo "๐ Project directory: $PROJECT_DIR"
|
36
30
|
|
37
31
|
# ========================================
|
@@ -43,14 +37,19 @@ PLATFORM=$(uname -s)
|
|
43
37
|
if [ "$PLATFORM" = "Darwin" ]; then
|
44
38
|
echo "๐ Detected macOS"
|
45
39
|
PM2_CMD="npx pm2"
|
40
|
+
BIND_HOST="127.0.0.1" # macOS - bind to localhost for testing
|
46
41
|
elif [ "$PLATFORM" = "Linux" ]; then
|
47
42
|
echo "๐ง Detected Linux"
|
48
43
|
PM2_CMD="npx pm2"
|
44
|
+
BIND_HOST="0.0.0.0" # Linux - bind to all interfaces for public access
|
49
45
|
else
|
50
46
|
echo "โ ๏ธ Unknown platform: $PLATFORM"
|
51
47
|
PM2_CMD="npx pm2"
|
48
|
+
BIND_HOST="0.0.0.0"
|
52
49
|
fi
|
53
50
|
|
51
|
+
echo "๐ Server will bind to: $BIND_HOST"
|
52
|
+
|
54
53
|
# ========================================
|
55
54
|
# CLEANUP (Skip in dry-run for safety)
|
56
55
|
# ========================================
|
@@ -67,7 +66,7 @@ if [ "$DRY_RUN" = false ]; then
|
|
67
66
|
rm -f ecosystem.config.js 2>/dev/null || true
|
68
67
|
|
69
68
|
# Kill processes on all relevant ports
|
70
|
-
for port in
|
69
|
+
for port in 80 3000 3001 3002; do
|
71
70
|
if ! check_port $port; then
|
72
71
|
echo "Killing processes on port $port..."
|
73
72
|
lsof -ti:$port | xargs kill -9 2>/dev/null || true
|
@@ -79,7 +78,6 @@ if [ "$DRY_RUN" = false ]; then
|
|
79
78
|
rm -rf logs/* 2>/dev/null || true
|
80
79
|
else
|
81
80
|
echo "๐งช DRY RUN: Skipping cleanup (existing processes will remain)"
|
82
|
-
echo " This is a safe test that won't affect your system"
|
83
81
|
fi
|
84
82
|
|
85
83
|
# ========================================
|
@@ -88,81 +86,47 @@ fi
|
|
88
86
|
|
89
87
|
echo "๐ Checking prerequisites..."
|
90
88
|
|
91
|
-
# Check Node.js version
|
89
|
+
# Check Node.js version
|
92
90
|
NODE_VERSION=$(node --version | sed 's/v//' | cut -d. -f1)
|
93
91
|
if [ "$DRY_RUN" = true ]; then
|
94
|
-
# More lenient for dry-run testing
|
95
92
|
if [ "$NODE_VERSION" -lt 18 ]; then
|
96
93
|
echo "โ Node.js 18+ required for testing. Current version: $(node --version)"
|
97
|
-
if [ "$PLATFORM" = "Darwin" ]; then
|
98
|
-
echo "Install with: brew install node"
|
99
|
-
fi
|
100
94
|
exit 1
|
101
95
|
else
|
102
|
-
echo "โ
Node.js version: $(node --version)
|
103
|
-
if [ "$NODE_VERSION" -lt 20 ]; then
|
104
|
-
echo " โ ๏ธ Note: Production deployment requires Node.js 20+"
|
105
|
-
fi
|
96
|
+
echo "โ
Node.js version: $(node --version)"
|
106
97
|
fi
|
107
98
|
else
|
108
|
-
# Strict for production
|
109
99
|
if [ "$NODE_VERSION" -lt 20 ]; then
|
110
100
|
echo "โ Node.js 20+ required for production. Current version: $(node --version)"
|
111
|
-
if [ "$PLATFORM" = "Darwin" ]; then
|
112
|
-
echo "Install with: brew install node@20"
|
113
|
-
else
|
114
|
-
echo "Install with: curl -fsSL https://deb.nodesource.com/setup_20.x | sudo -E bash - && sudo apt-get install -y nodejs"
|
115
|
-
fi
|
116
101
|
exit 1
|
117
102
|
else
|
118
103
|
echo "โ
Node.js version: $(node --version)"
|
119
104
|
fi
|
120
105
|
fi
|
121
106
|
|
122
|
-
# Check npm
|
123
107
|
echo "โ
npm version: $(npm --version)"
|
124
108
|
|
125
|
-
# Check available memory
|
126
|
-
if [ "$PLATFORM" = "Darwin" ]; then
|
127
|
-
MEMORY_GB=$(sysctl -n hw.memsize | awk '{print int($1/1024/1024/1024)}')
|
128
|
-
echo "โ
Available memory: ${MEMORY_GB}GB"
|
129
|
-
if [ "$MEMORY_GB" -lt 4 ]; then
|
130
|
-
echo "โ ๏ธ Warning: Less than 4GB RAM detected. Builds may be slow."
|
131
|
-
fi
|
132
|
-
elif [ "$PLATFORM" = "Linux" ]; then
|
133
|
-
MEMORY_GB=$(free -g | awk '/^Mem:/{print $2}')
|
134
|
-
echo "โ
Available memory: ${MEMORY_GB}GB"
|
135
|
-
if [ "$MEMORY_GB" -lt 1 ]; then
|
136
|
-
echo "โ ๏ธ Warning: Less than 1GB RAM detected. Consider adding swap space."
|
137
|
-
fi
|
138
|
-
fi
|
139
|
-
|
140
|
-
# Check if we have required tools
|
141
|
-
echo "โ
Platform tools:"
|
142
|
-
echo " curl: $(which curl >/dev/null && echo "available" || echo "missing")"
|
143
|
-
echo " tar: $(which tar >/dev/null && echo "available" || echo "missing")"
|
144
|
-
echo " lsof: $(which lsof >/dev/null && echo "available" || echo "missing")"
|
145
|
-
|
146
109
|
# ========================================
|
147
110
|
# SETUP OPENAI API KEY
|
148
111
|
# ========================================
|
149
112
|
|
150
113
|
echo "๐ Setting up OpenAI API key..."
|
151
114
|
|
152
|
-
# In dry-run mode, always use a test key
|
153
115
|
if [ "$DRY_RUN" = true ]; then
|
154
116
|
echo "๐งช DRY RUN: Using test API key"
|
155
117
|
mkdir -p "$PROJECT_DIR/server"
|
156
118
|
echo "OPENAI_API_KEY=sk-test1234567890abcdef" > "$PROJECT_DIR/server/.env"
|
157
119
|
echo "NODE_ENV=production" >> "$PROJECT_DIR/server/.env"
|
158
|
-
echo "PORT=
|
120
|
+
echo "PORT=80" >> "$PROJECT_DIR/server/.env"
|
121
|
+
echo "HOST=$BIND_HOST" >> "$PROJECT_DIR/server/.env"
|
159
122
|
elif [ ! -f "$PROJECT_DIR/server/.env" ] || grep -q "your_openai_api_key_here" "$PROJECT_DIR/server/.env" 2>/dev/null; then
|
160
123
|
if [ "$CI" = "true" ]; then
|
161
124
|
echo "CI mode - using test API key"
|
162
125
|
mkdir -p "$PROJECT_DIR/server"
|
163
126
|
echo "OPENAI_API_KEY=sk-test1234" > "$PROJECT_DIR/server/.env"
|
164
127
|
echo "NODE_ENV=production" >> "$PROJECT_DIR/server/.env"
|
165
|
-
echo "PORT=
|
128
|
+
echo "PORT=80" >> "$PROJECT_DIR/server/.env"
|
129
|
+
echo "HOST=$BIND_HOST" >> "$PROJECT_DIR/server/.env"
|
166
130
|
else
|
167
131
|
echo "โ ๏ธ OpenAI API key required for SpecGen to work."
|
168
132
|
echo "Enter your OpenAI API key (or press Enter to use test key): "
|
@@ -176,7 +140,8 @@ elif [ ! -f "$PROJECT_DIR/server/.env" ] || grep -q "your_openai_api_key_here" "
|
|
176
140
|
mkdir -p "$PROJECT_DIR/server"
|
177
141
|
echo "OPENAI_API_KEY=$OPENAI_KEY" > "$PROJECT_DIR/server/.env"
|
178
142
|
echo "NODE_ENV=production" >> "$PROJECT_DIR/server/.env"
|
179
|
-
echo "PORT=
|
143
|
+
echo "PORT=80" >> "$PROJECT_DIR/server/.env"
|
144
|
+
echo "HOST=$BIND_HOST" >> "$PROJECT_DIR/server/.env"
|
180
145
|
echo "โ
API key saved"
|
181
146
|
fi
|
182
147
|
fi
|
@@ -186,57 +151,34 @@ fi
|
|
186
151
|
# ========================================
|
187
152
|
|
188
153
|
echo "๐๏ธ Building application components..."
|
189
|
-
|
190
|
-
# Navigate to project directory
|
191
154
|
cd "$PROJECT_DIR"
|
192
155
|
|
193
|
-
# Install and build server
|
156
|
+
# Install and build server
|
194
157
|
if [ ! -f "server/index.js" ]; then
|
195
158
|
echo "๐ฆ Setting up server..."
|
196
159
|
|
197
|
-
# Clean up any existing server directory
|
198
160
|
rm -rf server
|
199
|
-
|
200
|
-
# Download and extract server
|
201
|
-
echo " Downloading server package..."
|
202
161
|
npm pack @gv-sh/specgen-server --loglevel=warn
|
203
|
-
|
204
|
-
echo " Extracting server package..."
|
205
162
|
tar -xzf gv-sh-specgen-server-*.tgz
|
206
163
|
|
207
|
-
# Move the extracted package to server directory
|
208
164
|
if [ -d "package" ]; then
|
209
165
|
mv package server
|
166
|
+
rm gv-sh-specgen-server-*.tgz
|
210
167
|
echo "โ
Server extracted successfully"
|
211
168
|
else
|
212
169
|
echo "โ Failed to extract server package"
|
213
|
-
ls -la
|
214
170
|
exit 1
|
215
171
|
fi
|
216
172
|
|
217
|
-
# Clean up the tar file
|
218
|
-
rm gv-sh-specgen-server-*.tgz
|
219
|
-
|
220
|
-
# Install server dependencies
|
221
|
-
echo " Installing server dependencies..."
|
222
173
|
cd server
|
223
174
|
echo "engine-strict=false" > .npmrc
|
224
175
|
npm install --no-fund --no-audit --production --maxsockets=2 --loglevel=warn
|
225
|
-
|
226
|
-
# Verify server files
|
227
|
-
if [ ! -f "index.js" ]; then
|
228
|
-
echo "โ Server index.js not found after installation"
|
229
|
-
echo "Server directory contents:"
|
230
|
-
ls -la
|
231
|
-
exit 1
|
232
|
-
fi
|
233
|
-
|
234
176
|
cd "$PROJECT_DIR"
|
235
177
|
|
236
|
-
#
|
237
|
-
echo " ๐ง Installing unified server
|
178
|
+
# Install unified server that binds to 0.0.0.0
|
179
|
+
echo " ๐ง Installing unified server (binds to all interfaces)..."
|
238
180
|
cat > server/index.js << 'EOF'
|
239
|
-
// index.js - Unified server for port
|
181
|
+
// index.js - Unified server for port 80 with public binding
|
240
182
|
/* global process */
|
241
183
|
require('dotenv').config();
|
242
184
|
const express = require('express');
|
@@ -246,7 +188,8 @@ const errorHandler = require('./middleware/errorHandler');
|
|
246
188
|
|
247
189
|
// Initialize Express app
|
248
190
|
const app = express();
|
249
|
-
|
191
|
+
const PORT = process.env.PORT || 80;
|
192
|
+
const HOST = process.env.HOST || '0.0.0.0'; // Bind to all interfaces by default
|
250
193
|
|
251
194
|
// Middleware
|
252
195
|
app.use(cors());
|
@@ -258,34 +201,32 @@ const adminBuildPath = path.join(__dirname, '../admin/build');
|
|
258
201
|
const fs = require('fs');
|
259
202
|
if (fs.existsSync(adminBuildPath)) {
|
260
203
|
app.use('/admin', express.static(adminBuildPath));
|
261
|
-
// Handle React Router for admin (catch all admin routes)
|
262
204
|
app.get('/admin/*', (req, res) => {
|
263
205
|
res.sendFile(path.join(adminBuildPath, 'index.html'));
|
264
206
|
});
|
265
207
|
console.log('โ
Admin interface available at /admin');
|
266
208
|
} else {
|
267
|
-
console.log('โ ๏ธ Admin build not found
|
209
|
+
console.log('โ ๏ธ Admin build not found');
|
268
210
|
}
|
269
211
|
|
270
212
|
// Serve static files for user interface at /app
|
271
213
|
const userBuildPath = path.join(__dirname, '../user/build');
|
272
214
|
if (fs.existsSync(userBuildPath)) {
|
273
215
|
app.use('/app', express.static(userBuildPath));
|
274
|
-
// Handle React Router for user app (catch all app routes)
|
275
216
|
app.get('/app/*', (req, res) => {
|
276
217
|
res.sendFile(path.join(userBuildPath, 'index.html'));
|
277
218
|
});
|
278
219
|
console.log('โ
User interface available at /app');
|
279
220
|
} else {
|
280
|
-
console.log('โ ๏ธ User build not found
|
221
|
+
console.log('โ ๏ธ User build not found');
|
281
222
|
}
|
282
223
|
|
283
|
-
// Serve user interface as default at root
|
224
|
+
// Serve user interface as default at root
|
284
225
|
if (fs.existsSync(userBuildPath)) {
|
285
226
|
app.use('/', express.static(userBuildPath, { index: false }));
|
286
227
|
}
|
287
228
|
|
288
|
-
// Routes
|
229
|
+
// API Routes
|
289
230
|
const categoryRoutes = require('./routes/categories');
|
290
231
|
const parameterRoutes = require('./routes/parameters');
|
291
232
|
const generateRoutes = require('./routes/generate');
|
@@ -293,7 +234,6 @@ const databaseRoutes = require('./routes/database');
|
|
293
234
|
const contentRoutes = require('./routes/content');
|
294
235
|
const settingsRoutes = require('./routes/settings');
|
295
236
|
|
296
|
-
// API Routes
|
297
237
|
app.use('/api/categories', categoryRoutes);
|
298
238
|
app.use('/api/parameters', parameterRoutes);
|
299
239
|
app.use('/api/generate', generateRoutes);
|
@@ -301,28 +241,24 @@ app.use('/api/database', databaseRoutes);
|
|
301
241
|
app.use('/api/content', contentRoutes);
|
302
242
|
app.use('/api/settings', settingsRoutes);
|
303
243
|
|
304
|
-
// Only add Swagger in non-test environment
|
305
244
|
if (process.env.NODE_ENV !== 'test') {
|
306
245
|
const swaggerRoutes = require('./routes/swagger');
|
307
246
|
app.use('/api-docs', swaggerRoutes);
|
308
247
|
}
|
309
248
|
|
310
|
-
// Health check routes
|
311
249
|
const healthRoutes = require('./routes/health');
|
312
250
|
app.use('/api/health', healthRoutes);
|
313
251
|
|
314
|
-
// Root route
|
252
|
+
// Root route
|
315
253
|
app.get('/', (req, res) => {
|
316
|
-
// If user build exists, serve it
|
317
254
|
if (fs.existsSync(userBuildPath)) {
|
318
255
|
res.sendFile(path.join(userBuildPath, 'index.html'));
|
319
256
|
} else {
|
320
|
-
// Fallback navigation page
|
321
257
|
const html = `
|
322
258
|
<!DOCTYPE html>
|
323
259
|
<html>
|
324
260
|
<head>
|
325
|
-
<title>SpecGen -
|
261
|
+
<title>SpecGen - Running on ${HOST}:${PORT}</title>
|
326
262
|
<style>
|
327
263
|
body { font-family: Arial, sans-serif; max-width: 800px; margin: 50px auto; padding: 20px; background: #f8f9fa; }
|
328
264
|
.nav-card { border: 1px solid #dee2e6; border-radius: 8px; padding: 20px; margin: 15px 0; background: white; box-shadow: 0 2px 4px rgba(0,0,0,0.1); }
|
@@ -330,43 +266,35 @@ app.get('/', (req, res) => {
|
|
330
266
|
a { text-decoration: none; color: #007bff; }
|
331
267
|
h1 { color: #343a40; text-align: center; }
|
332
268
|
.status { color: #28a745; font-weight: bold; text-align: center; background: #d4edda; padding: 10px; border-radius: 5px; margin: 20px 0; }
|
333
|
-
.
|
334
|
-
.warning { background: #fff3cd; border: 1px solid #ffeaa7; padding: 15px; border-radius: 5px; margin: 20px 0; }
|
269
|
+
.binding { background: #e3f2fd; border: 1px solid #2196f3; padding: 15px; border-radius: 5px; margin: 20px 0; }
|
335
270
|
</style>
|
336
271
|
</head>
|
337
272
|
<body>
|
338
273
|
<h1>๐ SpecGen Platform</h1>
|
339
|
-
<div class="status">โ
|
274
|
+
<div class="status">โ
Server running on ${HOST}:${PORT}</div>
|
340
275
|
|
341
|
-
<div class="
|
342
|
-
<strong
|
343
|
-
add port ${PORT} to your AWS Security Group inbound rules.
|
276
|
+
<div class="binding">
|
277
|
+
<strong>๐ Network Binding:</strong> ${HOST === '0.0.0.0' ? 'Public access enabled (0.0.0.0)' : 'Local access only (' + HOST + ')'}
|
344
278
|
</div>
|
345
279
|
|
346
280
|
<div class="nav-card">
|
347
281
|
<h3><a href="/app">๐ฑ User Application</a></h3>
|
348
|
-
<p>Main SpecGen user interface
|
282
|
+
<p>Main SpecGen user interface</p>
|
349
283
|
</div>
|
350
284
|
|
351
285
|
<div class="nav-card">
|
352
286
|
<h3><a href="/admin">โ๏ธ Admin Panel</a></h3>
|
353
|
-
<p>Administrative interface
|
287
|
+
<p>Administrative interface</p>
|
354
288
|
</div>
|
355
289
|
|
356
290
|
<div class="nav-card">
|
357
291
|
<h3><a href="/api-docs">๐ API Documentation</a></h3>
|
358
|
-
<p>Interactive API documentation
|
292
|
+
<p>Interactive API documentation</p>
|
359
293
|
</div>
|
360
294
|
|
361
295
|
<div class="nav-card">
|
362
296
|
<h3><a href="/api/health">โค๏ธ Health Check</a></h3>
|
363
|
-
<p>System health
|
364
|
-
</div>
|
365
|
-
|
366
|
-
<div class="footer">
|
367
|
-
<p><strong>API Base URL:</strong> <code>http://your-server:${PORT}/api</code></p>
|
368
|
-
<p><strong>Environment:</strong> ${process.env.NODE_ENV || 'development'}</p>
|
369
|
-
<p><strong>Server Time:</strong> ${new Date().toISOString()}</p>
|
297
|
+
<p>System health monitoring</p>
|
370
298
|
</div>
|
371
299
|
</body>
|
372
300
|
</html>`;
|
@@ -374,234 +302,103 @@ app.get('/', (req, res) => {
|
|
374
302
|
}
|
375
303
|
});
|
376
304
|
|
377
|
-
// Error handling middleware
|
378
305
|
app.use(errorHandler);
|
379
306
|
|
380
307
|
if (require.main === module) {
|
381
|
-
app.listen(PORT, () => {
|
382
|
-
console.log(`๐ SpecGen
|
383
|
-
console.log(`๐ฑ User App: http
|
384
|
-
console.log(`โ๏ธ Admin Panel: http
|
385
|
-
console.log(`๐ API Docs: http
|
386
|
-
console.log(`โค๏ธ Health Check: http
|
387
|
-
|
388
|
-
|
389
|
-
|
390
|
-
|
308
|
+
app.listen(PORT, HOST, () => {
|
309
|
+
console.log(`๐ SpecGen server running on ${HOST}:${PORT}`);
|
310
|
+
console.log(`๐ฑ User App: http://${HOST}:${PORT}/app`);
|
311
|
+
console.log(`โ๏ธ Admin Panel: http://${HOST}:${PORT}/admin`);
|
312
|
+
console.log(`๐ API Docs: http://${HOST}:${PORT}/api-docs`);
|
313
|
+
console.log(`โค๏ธ Health Check: http://${HOST}:${PORT}/api/health`);
|
314
|
+
|
315
|
+
if (HOST === '0.0.0.0') {
|
316
|
+
console.log(`๐ Accessible from any IP address`);
|
317
|
+
} else {
|
318
|
+
console.log(`๐ Local access only (${HOST})`);
|
391
319
|
}
|
392
|
-
console.log(`- API is ready for use`);
|
393
320
|
});
|
394
321
|
}
|
395
322
|
|
396
323
|
module.exports = app;
|
397
324
|
EOF
|
398
|
-
echo "โ
Unified server installed"
|
325
|
+
echo "โ
Unified server installed with public binding"
|
399
326
|
fi
|
400
327
|
|
401
|
-
#
|
402
|
-
|
403
|
-
|
404
|
-
|
405
|
-
if [ ! -d "admin" ]; then
|
406
|
-
# Clean up any existing admin directory
|
407
|
-
rm -rf admin
|
328
|
+
# Build admin and user (shortened for brevity)
|
329
|
+
for component in admin user; do
|
330
|
+
if [ ! -d "$component/build" ]; then
|
331
|
+
echo "๐ฑ Building $component interface..."
|
408
332
|
|
409
|
-
|
410
|
-
|
411
|
-
|
412
|
-
|
413
|
-
|
414
|
-
mv package admin
|
415
|
-
echo "โ
Admin extracted successfully"
|
416
|
-
else
|
417
|
-
echo "โ Failed to extract admin package"
|
418
|
-
exit 1
|
333
|
+
if [ ! -d "$component" ]; then
|
334
|
+
npm pack @gv-sh/specgen-$component --loglevel=warn
|
335
|
+
tar -xzf gv-sh-specgen-$component-*.tgz
|
336
|
+
mv package $component
|
337
|
+
rm gv-sh-specgen-$component-*.tgz
|
419
338
|
fi
|
420
339
|
|
421
|
-
|
422
|
-
|
423
|
-
|
424
|
-
echo " Installing admin dependencies..."
|
425
|
-
cd admin
|
426
|
-
echo "engine-strict=false" > .npmrc
|
427
|
-
# Install ALL dependencies for build process
|
428
|
-
npm install --no-fund --no-audit --maxsockets=2 --loglevel=warn
|
429
|
-
echo " Building admin interface..."
|
430
|
-
# Build with proper environment variables
|
431
|
-
GENERATE_SOURCEMAP=false SKIP_PREFLIGHT_CHECK=true PUBLIC_URL=/admin npm run build
|
432
|
-
cd "$PROJECT_DIR"
|
433
|
-
fi
|
434
|
-
|
435
|
-
# Install and build user
|
436
|
-
if [ ! -d "user/build" ]; then
|
437
|
-
echo "๐ค Building user interface..."
|
438
|
-
|
439
|
-
if [ ! -d "user" ]; then
|
440
|
-
# Clean up any existing user directory
|
441
|
-
rm -rf user
|
442
|
-
|
443
|
-
echo " Downloading user package..."
|
444
|
-
npm pack @gv-sh/specgen-user --loglevel=warn
|
445
|
-
tar -xzf gv-sh-specgen-user-*.tgz
|
340
|
+
cd $component
|
341
|
+
echo "engine-strict=false" > .npmrc
|
342
|
+
npm install --no-fund --no-audit --maxsockets=2 --loglevel=warn
|
446
343
|
|
447
|
-
if [
|
448
|
-
|
449
|
-
echo "โ
User extracted successfully"
|
344
|
+
if [ "$component" = "admin" ]; then
|
345
|
+
GENERATE_SOURCEMAP=false SKIP_PREFLIGHT_CHECK=true PUBLIC_URL=/admin npm run build
|
450
346
|
else
|
451
|
-
|
452
|
-
exit 1
|
347
|
+
GENERATE_SOURCEMAP=false SKIP_PREFLIGHT_CHECK=true REACT_APP_API_URL=/api PUBLIC_URL=/app npm run build
|
453
348
|
fi
|
454
|
-
|
455
|
-
rm gv-sh-specgen-user-*.tgz
|
349
|
+
cd "$PROJECT_DIR"
|
456
350
|
fi
|
457
|
-
|
458
|
-
echo " Installing user dependencies..."
|
459
|
-
cd user
|
460
|
-
echo "engine-strict=false" > .npmrc
|
461
|
-
# Install ALL dependencies for build process
|
462
|
-
npm install --no-fund --no-audit --maxsockets=2 --loglevel=warn
|
463
|
-
echo " Building user interface..."
|
464
|
-
# Build with proper environment variables
|
465
|
-
GENERATE_SOURCEMAP=false SKIP_PREFLIGHT_CHECK=true REACT_APP_API_URL=/api PUBLIC_URL=/app npm run build
|
466
|
-
cd "$PROJECT_DIR"
|
467
|
-
fi
|
351
|
+
done
|
468
352
|
|
469
353
|
# ========================================
|
470
354
|
# VERIFY BUILDS
|
471
355
|
# ========================================
|
472
356
|
|
473
357
|
echo "โ
Verifying builds..."
|
474
|
-
|
475
|
-
|
476
|
-
if [ ! -d "$PROJECT_DIR/admin/build" ]; then
|
477
|
-
echo "โ Admin build failed"
|
478
|
-
ls -la "$PROJECT_DIR/admin/" || echo "Admin directory not found"
|
358
|
+
if [ ! -d "admin/build" ] || [ ! -d "user/build" ] || [ ! -f "server/index.js" ]; then
|
359
|
+
echo "โ Build verification failed"
|
479
360
|
exit 1
|
480
361
|
fi
|
481
362
|
|
482
|
-
|
483
|
-
if [ ! -d "$PROJECT_DIR/user/build" ]; then
|
484
|
-
echo "โ User build failed"
|
485
|
-
ls -la "$PROJECT_DIR/user/" || echo "User directory not found"
|
486
|
-
exit 1
|
487
|
-
fi
|
488
|
-
|
489
|
-
# Check server
|
490
|
-
if [ ! -f "$PROJECT_DIR/server/index.js" ]; then
|
491
|
-
echo "โ Server index.js not found"
|
492
|
-
echo "Server directory contents:"
|
493
|
-
ls -la "$PROJECT_DIR/server/" || echo "Server directory not found"
|
494
|
-
exit 1
|
495
|
-
fi
|
496
|
-
|
497
|
-
echo "๐ Build verification:"
|
498
|
-
echo " Admin build: $(ls -la "$PROJECT_DIR/admin/build/" | wc -l) files"
|
499
|
-
echo " User build: $(ls -la "$PROJECT_DIR/user/build/" | wc -l) files"
|
500
|
-
echo " Server files: $(ls -la "$PROJECT_DIR/server/" | wc -l) files"
|
501
|
-
echo " โ
Server script: $PROJECT_DIR/server/index.js"
|
502
|
-
|
503
|
-
# Show some sample files to verify builds
|
504
|
-
echo "๐ Key files found:"
|
505
|
-
echo " Admin: $(ls "$PROJECT_DIR/admin/build/" | grep -E '\.(html|js|css)$' | head -3 | tr '\n' ' ')"
|
506
|
-
echo " User: $(ls "$PROJECT_DIR/user/build/" | grep -E '\.(html|js|css)$' | head -3 | tr '\n' ' ')"
|
507
|
-
echo " Server: $(ls "$PROJECT_DIR/server/" | grep -E '\.(js|json)$' | head -3 | tr '\n' ' ')"
|
363
|
+
echo "๐ All builds completed successfully"
|
508
364
|
|
509
365
|
# ========================================
|
510
|
-
# DEPLOYMENT
|
366
|
+
# DEPLOYMENT
|
511
367
|
# ========================================
|
512
368
|
|
513
369
|
if [ "$DRY_RUN" = true ]; then
|
514
|
-
echo ""
|
515
370
|
echo "๐งช DRY RUN: Testing server startup..."
|
516
|
-
|
517
|
-
# Test if the server can start
|
518
371
|
cd "$PROJECT_DIR"
|
372
|
+
cp server/.env .env 2>/dev/null || true
|
519
373
|
|
520
|
-
|
521
|
-
|
522
|
-
|
523
|
-
# Check if port 8080 is available for testing
|
524
|
-
if ! check_port 8080; then
|
525
|
-
echo " โ ๏ธ Port 8080 is in use, testing on port 8081 instead"
|
374
|
+
TEST_PORT=80
|
375
|
+
if ! check_port $TEST_PORT; then
|
526
376
|
TEST_PORT=8081
|
527
|
-
sed -i.bak 's/PORT=8080/PORT=8081/' "$PROJECT_DIR/server/.env"
|
528
|
-
else
|
529
|
-
TEST_PORT=8080
|
530
377
|
fi
|
531
378
|
|
532
|
-
echo " Starting test server on
|
533
|
-
|
534
|
-
# Start server in background
|
535
|
-
(cd server && NODE_ENV=production PORT=$TEST_PORT node index.js) &
|
379
|
+
echo " Starting test server on $BIND_HOST:$TEST_PORT for 10 seconds..."
|
380
|
+
(cd server && NODE_ENV=production PORT=$TEST_PORT HOST=$BIND_HOST node index.js) &
|
536
381
|
SERVER_PID=$!
|
537
382
|
|
538
|
-
# Wait a bit for server to start
|
539
383
|
sleep 3
|
540
384
|
|
541
|
-
|
542
|
-
echo " Testing endpoints on port $TEST_PORT:"
|
543
|
-
|
385
|
+
echo " Testing endpoints:"
|
544
386
|
if curl -s http://localhost:$TEST_PORT/api/health >/dev/null 2>&1; then
|
545
387
|
echo " โ
Health endpoint: OK"
|
546
|
-
HEALTH_RESPONSE=$(curl -s http://localhost:$TEST_PORT/api/health)
|
547
|
-
echo " Status: $(echo $HEALTH_RESPONSE | grep -o '"status":"[^"]*"' | cut -d'"' -f4)"
|
548
388
|
else
|
549
389
|
echo " โ Health endpoint: FAILED"
|
550
390
|
fi
|
551
391
|
|
552
|
-
HTTP_CODE=$(curl -s -o /dev/null -w "%{http_code}" http://localhost:$TEST_PORT/ 2>/dev/null || echo "000")
|
553
|
-
echo " ๐ Main page: HTTP $HTTP_CODE"
|
554
|
-
|
555
|
-
HTTP_CODE=$(curl -s -o /dev/null -w "%{http_code}" http://localhost:$TEST_PORT/admin/ 2>/dev/null || echo "000")
|
556
|
-
echo " โ๏ธ Admin page: HTTP $HTTP_CODE"
|
557
|
-
|
558
|
-
HTTP_CODE=$(curl -s -o /dev/null -w "%{http_code}" http://localhost:$TEST_PORT/app/ 2>/dev/null || echo "000")
|
559
|
-
echo " ๐ค User page: HTTP $HTTP_CODE"
|
560
|
-
|
561
|
-
# Stop test server
|
562
|
-
sleep 2
|
563
392
|
kill $SERVER_PID 2>/dev/null || true
|
564
393
|
wait $SERVER_PID 2>/dev/null || true
|
565
394
|
|
566
|
-
# Restore original .env if we changed it
|
567
|
-
if [ -f "$PROJECT_DIR/server/.env.bak" ]; then
|
568
|
-
mv "$PROJECT_DIR/server/.env.bak" "$PROJECT_DIR/server/.env"
|
569
|
-
fi
|
570
|
-
|
571
395
|
echo ""
|
572
396
|
echo "๐ DRY RUN COMPLETED!"
|
573
|
-
echo ""
|
574
|
-
echo "๐ Summary:"
|
575
|
-
echo " โ
All packages downloaded and extracted"
|
576
|
-
echo " โ
All dependencies installed"
|
577
|
-
echo " โ
React apps built successfully"
|
578
|
-
echo " โ
Unified server installed"
|
579
|
-
echo " โ
Server can start and respond"
|
580
|
-
echo ""
|
581
|
-
if [ "$NODE_VERSION" -lt 20 ]; then
|
582
|
-
echo "โ ๏ธ Note for AWS deployment:"
|
583
|
-
echo " Your Mac has Node.js $(node --version)"
|
584
|
-
echo " AWS deployment requires Node.js 20+"
|
585
|
-
echo " Make sure your AWS server has the right version"
|
586
|
-
echo ""
|
587
|
-
fi
|
588
397
|
echo "๐ Ready for production deployment!"
|
589
|
-
echo " Deploy to AWS with: npx @gv-sh/specgen-app deploy"
|
590
|
-
echo ""
|
591
|
-
echo "๐ AWS Deployment Notes:"
|
592
|
-
echo " 1. Ensure Node.js 20+ on your AWS instance"
|
593
|
-
echo " 2. Add port 8080 to Security Group inbound rules"
|
594
|
-
echo " 3. Run: npx @gv-sh/specgen-app deploy"
|
595
|
-
echo ""
|
596
|
-
echo "๐ง To test locally right now:"
|
597
|
-
echo " cd server && npm start"
|
598
|
-
echo " Open http://localhost:8080/"
|
599
398
|
|
600
399
|
else
|
601
|
-
# Real deployment with PM2
|
602
400
|
echo "๐ Starting PM2 deployment..."
|
603
401
|
|
604
|
-
# Create PM2 ecosystem configuration with absolute paths
|
605
402
|
cat > "$PROJECT_DIR/ecosystem.config.js" << EOF
|
606
403
|
module.exports = {
|
607
404
|
apps: [{
|
@@ -610,7 +407,8 @@ module.exports = {
|
|
610
407
|
cwd: '$PROJECT_DIR',
|
611
408
|
env: {
|
612
409
|
NODE_ENV: 'production',
|
613
|
-
PORT:
|
410
|
+
PORT: 80,
|
411
|
+
HOST: '$BIND_HOST'
|
614
412
|
},
|
615
413
|
instances: 1,
|
616
414
|
exec_mode: 'fork',
|
@@ -619,85 +417,40 @@ module.exports = {
|
|
619
417
|
out_file: '$PROJECT_DIR/logs/out.log',
|
620
418
|
log_file: '$PROJECT_DIR/logs/combined.log',
|
621
419
|
time: true,
|
622
|
-
watch: false
|
623
|
-
ignore_watch: ['node_modules', 'logs', '*.log'],
|
624
|
-
restart_delay: 1000,
|
625
|
-
max_restarts: 10,
|
626
|
-
min_uptime: '10s'
|
420
|
+
watch: false
|
627
421
|
}]
|
628
422
|
}
|
629
423
|
EOF
|
630
424
|
|
631
|
-
|
632
|
-
|
633
|
-
|
634
|
-
# Copy .env to project root for PM2
|
635
|
-
cp "$PROJECT_DIR/server/.env" "$PROJECT_DIR/.env" 2>/dev/null || true
|
425
|
+
mkdir -p logs
|
426
|
+
cp server/.env .env 2>/dev/null || true
|
636
427
|
|
637
|
-
|
638
|
-
|
639
|
-
echo "Port 8080 occupied, force cleaning..."
|
640
|
-
lsof -ti:8080 | xargs kill -9 2>/dev/null || true
|
428
|
+
if ! check_port 80; then
|
429
|
+
lsof -ti:80 | xargs kill -9 2>/dev/null || true
|
641
430
|
sleep 2
|
642
431
|
fi
|
643
432
|
|
644
|
-
|
645
|
-
cd "$PROJECT_DIR"
|
646
|
-
echo "โถ๏ธ Starting SpecGen with PM2..."
|
647
|
-
|
648
|
-
NODE_ENV=production PORT=8080 $PM2_CMD start "$PROJECT_DIR/ecosystem.config.js"
|
433
|
+
NODE_ENV=production PORT=80 HOST=$BIND_HOST $PM2_CMD start ecosystem.config.js
|
649
434
|
|
650
|
-
# Wait for startup and verify
|
651
435
|
sleep 5
|
652
436
|
|
653
|
-
# Verify deployment
|
654
|
-
echo "๐ Verifying deployment..."
|
655
|
-
|
656
437
|
if $PM2_CMD list | grep -q "online"; then
|
657
|
-
echo
|
658
|
-
|
659
|
-
if curl -s http://localhost:8080/api/health >/dev/null 2>&1; then
|
660
|
-
echo "โ
Health endpoint: OK"
|
661
|
-
else
|
662
|
-
echo "โ Health endpoint: FAILED"
|
663
|
-
fi
|
664
|
-
|
665
|
-
HTTP_CODE=$(curl -s -o /dev/null -w "%{http_code}" http://localhost:8080/ 2>/dev/null)
|
666
|
-
echo "๐ Main page: HTTP $HTTP_CODE"
|
667
|
-
|
668
|
-
HTTP_CODE=$(curl -s -o /dev/null -w "%{http_code}" http://localhost:8080/admin/ 2>/dev/null)
|
669
|
-
echo "โ๏ธ Admin page: HTTP $HTTP_CODE"
|
670
|
-
|
671
|
-
HTTP_CODE=$(curl -s -o /dev/null -w "%{http_code}" http://localhost:8080/app/ 2>/dev/null)
|
672
|
-
echo "๐ค User page: HTTP $HTTP_CODE"
|
673
|
-
|
674
|
-
PUBLIC_IP=$(curl -s ifconfig.me 2>/dev/null || curl -s ipecho.net/plain 2>/dev/null || echo 'your-server')
|
438
|
+
PUBLIC_IP=$(curl -s ifconfig.me 2>/dev/null || echo 'your-server')
|
675
439
|
|
676
440
|
echo ""
|
677
441
|
echo "๐ SpecGen deployment completed!"
|
678
442
|
echo ""
|
679
443
|
echo "๐ Access your application at:"
|
680
|
-
echo " - Main page: http://$PUBLIC_IP:
|
681
|
-
echo " - User app: http://$PUBLIC_IP:
|
682
|
-
echo " - Admin panel: http://$PUBLIC_IP:
|
683
|
-
echo " - API docs: http://$PUBLIC_IP:8080/api-docs"
|
684
|
-
echo " - Health check: http://$PUBLIC_IP:8080/api/health"
|
444
|
+
echo " - Main page: http://$PUBLIC_IP:80/"
|
445
|
+
echo " - User app: http://$PUBLIC_IP:80/app/"
|
446
|
+
echo " - Admin panel: http://$PUBLIC_IP:80/admin/"
|
685
447
|
echo ""
|
686
|
-
echo "
|
687
|
-
echo "
|
688
|
-
echo " EC2 Console โ Security Groups โ Edit Inbound Rules โ Add Rule"
|
689
|
-
echo " Type: Custom TCP, Port: 8080, Source: 0.0.0.0/0"
|
690
|
-
echo ""
|
691
|
-
echo "๐ Management commands:"
|
692
|
-
echo " $PM2_CMD status # Check status"
|
693
|
-
echo " $PM2_CMD logs specgen # View logs"
|
694
|
-
echo " $PM2_CMD restart specgen # Restart"
|
448
|
+
echo "๐ง Binding: Server is bound to $BIND_HOST (${BIND_HOST:+publicly accessible})"
|
449
|
+
echo "๐ Management: npx pm2 status | npx pm2 logs specgen"
|
695
450
|
|
696
451
|
else
|
697
|
-
echo ""
|
698
452
|
echo "โ Deployment failed!"
|
699
|
-
|
700
|
-
echo "๐ Check status: $PM2_CMD status"
|
453
|
+
$PM2_CMD logs specgen --lines 10
|
701
454
|
exit 1
|
702
455
|
fi
|
703
456
|
fi
|
@@ -1,9 +1,9 @@
|
|
1
1
|
#!/bin/bash
|
2
2
|
|
3
|
-
# SpecGen Production Script - Port
|
3
|
+
# SpecGen Production Script - Port 80 Low Memory Version
|
4
4
|
set -e
|
5
5
|
|
6
|
-
echo "๐ Starting SpecGen in production mode on port
|
6
|
+
echo "๐ Starting SpecGen in production mode on port 80 (Low Memory)..."
|
7
7
|
|
8
8
|
# Function to check if port is available
|
9
9
|
check_port() {
|
@@ -94,13 +94,13 @@ if [ ! -d "admin/build" ] || [ ! -d "user/build" ]; then
|
|
94
94
|
fi
|
95
95
|
fi
|
96
96
|
|
97
|
-
# Update server .env to use port
|
97
|
+
# Update server .env to use port 80
|
98
98
|
if [ -f "server/.env" ]; then
|
99
|
-
# Update or add PORT=
|
99
|
+
# Update or add PORT=80 to .env
|
100
100
|
if grep -q "^PORT=" server/.env; then
|
101
|
-
sed -i.bak "s/^PORT=.*/PORT=
|
101
|
+
sed -i.bak "s/^PORT=.*/PORT=80/" server/.env
|
102
102
|
else
|
103
|
-
echo "PORT=
|
103
|
+
echo "PORT=80" >> server/.env
|
104
104
|
fi
|
105
105
|
rm -f server/.env.bak
|
106
106
|
fi
|
@@ -109,21 +109,21 @@ fi
|
|
109
109
|
cat > server/.env.production << EOF
|
110
110
|
$(cat server/.env)
|
111
111
|
NODE_ENV=production
|
112
|
-
PORT=
|
112
|
+
PORT=80
|
113
113
|
EOF
|
114
114
|
|
115
|
-
# Kill existing processes on port
|
116
|
-
echo "Checking port
|
117
|
-
if ! check_port
|
118
|
-
echo "Port
|
119
|
-
lsof -ti:
|
115
|
+
# Kill existing processes on port 80 if needed
|
116
|
+
echo "Checking port 80..."
|
117
|
+
if ! check_port 80; then
|
118
|
+
echo "Port 80 is in use. Attempting to free it..."
|
119
|
+
lsof -ti:80 | xargs kill -9 2>/dev/null || true
|
120
120
|
sleep 2
|
121
121
|
fi
|
122
122
|
|
123
123
|
# Start production server
|
124
|
-
echo "Starting production server on port
|
124
|
+
echo "Starting production server on port 80..."
|
125
125
|
if [ "$CI" = "true" ]; then
|
126
126
|
echo "CI mode detected - skipping server start"
|
127
127
|
else
|
128
|
-
cd server && NODE_ENV=production PORT=
|
128
|
+
cd server && NODE_ENV=production PORT=80 npm start
|
129
129
|
fi
|
package/scripts/production.sh
CHANGED
@@ -1,9 +1,9 @@
|
|
1
1
|
#!/bin/bash
|
2
2
|
|
3
|
-
# SpecGen Production Script - Low Memory, Port
|
3
|
+
# SpecGen Production Script - Low Memory, Port 80 with Cleanup
|
4
4
|
set -e
|
5
5
|
|
6
|
-
echo "๐ Starting SpecGen in production mode on port
|
6
|
+
echo "๐ Starting SpecGen in production mode on port 80..."
|
7
7
|
echo "๐งน Cleaning up existing processes..."
|
8
8
|
|
9
9
|
# Function to check if port is available
|
@@ -27,7 +27,7 @@ npx pm2 delete all 2>/dev/null || true
|
|
27
27
|
|
28
28
|
# Kill processes on ports we'll use
|
29
29
|
echo "Freeing ports..."
|
30
|
-
for port in
|
30
|
+
for port in 80 3000 3001 3002; do
|
31
31
|
if ! check_port $port; then
|
32
32
|
echo "Port $port is in use. Attempting to free it..."
|
33
33
|
lsof -ti:$port | xargs kill -9 2>/dev/null || true
|
@@ -38,8 +38,8 @@ done
|
|
38
38
|
# Stop nginx if it might interfere
|
39
39
|
if command -v nginx &> /dev/null && systemctl is-active --quiet nginx 2>/dev/null; then
|
40
40
|
echo "Nginx is running, checking for conflicts..."
|
41
|
-
if nginx -T 2>/dev/null | grep -q ":
|
42
|
-
echo "โ ๏ธ Nginx is configured to use port
|
41
|
+
if nginx -T 2>/dev/null | grep -q ":80"; then
|
42
|
+
echo "โ ๏ธ Nginx is configured to use port 80. You may need to reconfigure nginx."
|
43
43
|
fi
|
44
44
|
fi
|
45
45
|
|
@@ -138,13 +138,13 @@ fi
|
|
138
138
|
# CONFIGURE ENVIRONMENT
|
139
139
|
# ========================================
|
140
140
|
|
141
|
-
# Update server .env to use port
|
141
|
+
# Update server .env to use port 80
|
142
142
|
if [ -f "server/.env" ]; then
|
143
|
-
# Update or add PORT=
|
143
|
+
# Update or add PORT=80 to .env
|
144
144
|
if grep -q "^PORT=" server/.env; then
|
145
|
-
sed -i.bak "s/^PORT=.*/PORT=
|
145
|
+
sed -i.bak "s/^PORT=.*/PORT=80/" server/.env
|
146
146
|
else
|
147
|
-
echo "PORT=
|
147
|
+
echo "PORT=80" >> server/.env
|
148
148
|
fi
|
149
149
|
rm -f server/.env.bak
|
150
150
|
fi
|
@@ -153,7 +153,7 @@ fi
|
|
153
153
|
cat > server/.env.production << EOF
|
154
154
|
$(cat server/.env)
|
155
155
|
NODE_ENV=production
|
156
|
-
PORT=
|
156
|
+
PORT=80
|
157
157
|
EOF
|
158
158
|
|
159
159
|
# Create logs directory
|
@@ -164,17 +164,17 @@ mkdir -p logs
|
|
164
164
|
# ========================================
|
165
165
|
|
166
166
|
# Final port check
|
167
|
-
echo "Final check for port
|
168
|
-
if ! check_port
|
169
|
-
echo "Port
|
170
|
-
lsof -ti:
|
167
|
+
echo "Final check for port 80..."
|
168
|
+
if ! check_port 80; then
|
169
|
+
echo "Port 80 is still in use after cleanup. Force killing..."
|
170
|
+
lsof -ti:80 | xargs kill -9 2>/dev/null || true
|
171
171
|
sleep 2
|
172
172
|
fi
|
173
173
|
|
174
174
|
# Start production server
|
175
|
-
echo "Starting production server on port
|
175
|
+
echo "Starting production server on port 80..."
|
176
176
|
if [ "$CI" = "true" ]; then
|
177
177
|
echo "CI mode detected - skipping server start"
|
178
178
|
else
|
179
|
-
cd server && NODE_ENV=production PORT=
|
179
|
+
cd server && NODE_ENV=production PORT=80 npm start
|
180
180
|
fi
|
package/scripts/setup.sh
CHANGED
@@ -45,7 +45,7 @@ rm -rf ~/.pm2/logs/* 2>/dev/null || true
|
|
45
45
|
|
46
46
|
# 2. Kill processes on ports we'll use
|
47
47
|
echo "Freeing up ports..."
|
48
|
-
for port in
|
48
|
+
for port in 80 3000 3001 3002; do
|
49
49
|
if lsof -Pi :$port -sTCP:LISTEN -t >/dev/null 2>&1; then
|
50
50
|
echo "Killing processes on port $port..."
|
51
51
|
lsof -ti:$port | xargs kill -9 2>/dev/null || true
|
@@ -163,7 +163,7 @@ done
|
|
163
163
|
|
164
164
|
echo "๐ง Setting up environment files..."
|
165
165
|
|
166
|
-
# Server .env (default to port
|
166
|
+
# Server .env (default to port 80)
|
167
167
|
if [ ! -f server/.env ] || [ "$CI" = "true" ]; then
|
168
168
|
# If in CI mode, use a dummy key
|
169
169
|
if [ "$CI" = "true" ]; then
|
@@ -173,7 +173,7 @@ if [ ! -f server/.env ] || [ "$CI" = "true" ]; then
|
|
173
173
|
cat > server/.env << EOF
|
174
174
|
OPENAI_API_KEY=sk-test1234
|
175
175
|
NODE_ENV=test
|
176
|
-
PORT=
|
176
|
+
PORT=80
|
177
177
|
EOF
|
178
178
|
echo "Created test .env file for CI environment"
|
179
179
|
fi
|
@@ -196,7 +196,7 @@ EOF
|
|
196
196
|
# OpenAI API key
|
197
197
|
OPENAI_API_KEY=$OPENAI_KEY
|
198
198
|
NODE_ENV=development
|
199
|
-
PORT=
|
199
|
+
PORT=80
|
200
200
|
EOF
|
201
201
|
|
202
202
|
if [ "$KEY_PROVIDED" = true ]; then
|
@@ -210,7 +210,7 @@ fi
|
|
210
210
|
# Admin .env.development
|
211
211
|
if [ -d admin ]; then
|
212
212
|
cat > admin/.env.development << 'EOF'
|
213
|
-
REACT_APP_API_URL=http://localhost:
|
213
|
+
REACT_APP_API_URL=http://localhost:80
|
214
214
|
PORT=3001
|
215
215
|
SKIP_PREFLIGHT_CHECK=true
|
216
216
|
GENERATE_SOURCEMAP=false
|
@@ -220,7 +220,7 @@ fi
|
|
220
220
|
# User .env.development
|
221
221
|
if [ -d user ]; then
|
222
222
|
cat > user/.env.development << 'EOF'
|
223
|
-
REACT_APP_API_URL=http://localhost:
|
223
|
+
REACT_APP_API_URL=http://localhost:80
|
224
224
|
PORT=3002
|
225
225
|
SKIP_PREFLIGHT_CHECK=true
|
226
226
|
GENERATE_SOURCEMAP=false
|
@@ -239,25 +239,25 @@ echo " - Nginx specgen configurations"
|
|
239
239
|
echo " - Systemd services"
|
240
240
|
echo " - Docker containers"
|
241
241
|
echo " - Old project files"
|
242
|
-
echo " - Freed ports:
|
242
|
+
echo " - Freed ports: 80, 3000, 3001, 3002"
|
243
243
|
echo ""
|
244
244
|
echo "Next steps:"
|
245
245
|
if [ "$KEY_PROVIDED" = false ]; then
|
246
246
|
echo "1. Add your OpenAI API key to server/.env"
|
247
247
|
echo "2. Run 'npm run dev' to start all services"
|
248
|
-
echo "3. Or run 'npm run production' for production mode on port
|
248
|
+
echo "3. Or run 'npm run production' for production mode on port 80"
|
249
249
|
else
|
250
250
|
echo "1. Run 'npm run dev' to start all services"
|
251
|
-
echo "2. Or run 'npm run production' for production mode on port
|
251
|
+
echo "2. Or run 'npm run production' for production mode on port 80"
|
252
252
|
fi
|
253
253
|
echo ""
|
254
254
|
echo "Access URLs:"
|
255
|
-
echo " ๐ Production: http://localhost:
|
256
|
-
echo " ๐ฑ Production User: http://localhost:
|
257
|
-
echo " โ๏ธ Production Admin: http://localhost:
|
258
|
-
echo " ๐ API Docs: http://localhost:
|
255
|
+
echo " ๐ Production: http://localhost:80 (main app)"
|
256
|
+
echo " ๐ฑ Production User: http://localhost:80/app"
|
257
|
+
echo " โ๏ธ Production Admin: http://localhost:80/admin"
|
258
|
+
echo " ๐ API Docs: http://localhost:80/api-docs"
|
259
259
|
echo ""
|
260
260
|
echo "Development URLs:"
|
261
261
|
echo " ๐ User Interface: http://localhost:3002"
|
262
262
|
echo " โ๏ธ Admin Interface: http://localhost:3001"
|
263
|
-
echo " ๐ง API: http://localhost:
|
263
|
+
echo " ๐ง API: http://localhost:80"
|