@gv-sh/specgen-app 0.6.3 โ 0.6.4
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 +3 -1
- package/scripts/deploy.sh +294 -149
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,6 +1,6 @@
|
|
1
1
|
{
|
2
2
|
"name": "@gv-sh/specgen-app",
|
3
|
-
"version": "0.6.
|
3
|
+
"version": "0.6.4",
|
4
4
|
"description": "Complete SpecGen application with server, admin, and user interfaces",
|
5
5
|
"main": "index.js",
|
6
6
|
"bin": {
|
@@ -13,6 +13,8 @@
|
|
13
13
|
"start": "cd server && npm start",
|
14
14
|
"production": "chmod +x scripts/production.sh && ./scripts/production.sh",
|
15
15
|
"deploy": "chmod +x scripts/deploy.sh && ./scripts/deploy.sh",
|
16
|
+
"deploy:dry-run": "chmod +x scripts/deploy.sh && ./scripts/deploy.sh --dry-run",
|
17
|
+
"test:deploy": "chmod +x scripts/deploy.sh && ./scripts/deploy.sh --dry-run",
|
16
18
|
"make-executable": "chmod +x scripts/make-executable.sh && ./scripts/make-executable.sh",
|
17
19
|
"deploy:stop": "chmod +x scripts/stop.sh && ./scripts/stop.sh",
|
18
20
|
"deploy:restart": "chmod +x scripts/restart.sh && ./scripts/restart.sh",
|
package/scripts/deploy.sh
CHANGED
@@ -3,7 +3,16 @@
|
|
3
3
|
# SpecGen Deploy Script - Self-Contained Deployment on Port 8080
|
4
4
|
set -e
|
5
5
|
|
6
|
-
|
6
|
+
# Check for dry-run mode
|
7
|
+
DRY_RUN=false
|
8
|
+
if [ "$1" = "--dry-run" ] || [ "$1" = "-d" ]; then
|
9
|
+
DRY_RUN=true
|
10
|
+
echo "๐งช DRY RUN MODE - Testing deployment locally"
|
11
|
+
echo "๐ฅ๏ธ Platform: $(uname -s) $(uname -m)"
|
12
|
+
else
|
13
|
+
echo "๐ Deploying SpecGen to production on port 8080..."
|
14
|
+
fi
|
15
|
+
|
7
16
|
echo "๐ฆ This is a complete deployment - no separate setup needed!"
|
8
17
|
|
9
18
|
# Function to check if port is available
|
@@ -21,30 +30,51 @@ PROJECT_DIR=$(pwd)
|
|
21
30
|
echo "๐ Project directory: $PROJECT_DIR"
|
22
31
|
|
23
32
|
# ========================================
|
24
|
-
#
|
33
|
+
# PLATFORM-SPECIFIC SETUP
|
25
34
|
# ========================================
|
26
35
|
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
npx pm2
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
+
# Detect platform
|
37
|
+
PLATFORM=$(uname -s)
|
38
|
+
if [ "$PLATFORM" = "Darwin" ]; then
|
39
|
+
echo "๐ Detected macOS"
|
40
|
+
PM2_CMD="npx pm2"
|
41
|
+
elif [ "$PLATFORM" = "Linux" ]; then
|
42
|
+
echo "๐ง Detected Linux"
|
43
|
+
PM2_CMD="npx pm2"
|
44
|
+
else
|
45
|
+
echo "โ ๏ธ Unknown platform: $PLATFORM"
|
46
|
+
PM2_CMD="npx pm2"
|
47
|
+
fi
|
36
48
|
|
37
|
-
#
|
38
|
-
|
39
|
-
|
40
|
-
echo "Killing processes on port $port..."
|
41
|
-
lsof -ti:$port | xargs kill -9 2>/dev/null || true
|
42
|
-
sleep 1
|
43
|
-
fi
|
44
|
-
done
|
49
|
+
# ========================================
|
50
|
+
# CLEANUP (Skip in dry-run for safety)
|
51
|
+
# ========================================
|
45
52
|
|
46
|
-
|
47
|
-
|
53
|
+
if [ "$DRY_RUN" = false ]; then
|
54
|
+
echo "๐งน Cleaning up existing installations..."
|
55
|
+
|
56
|
+
# Stop and remove all PM2 processes
|
57
|
+
$PM2_CMD stop all 2>/dev/null || true
|
58
|
+
$PM2_CMD delete all 2>/dev/null || true
|
59
|
+
$PM2_CMD kill 2>/dev/null || true
|
60
|
+
|
61
|
+
# Remove old PM2 config files
|
62
|
+
rm -f ecosystem.config.js 2>/dev/null || true
|
63
|
+
|
64
|
+
# Kill processes on all relevant ports
|
65
|
+
for port in 8080 3000 3001 3002; do
|
66
|
+
if ! check_port $port; then
|
67
|
+
echo "Killing processes on port $port..."
|
68
|
+
lsof -ti:$port | xargs kill -9 2>/dev/null || true
|
69
|
+
sleep 1
|
70
|
+
fi
|
71
|
+
done
|
72
|
+
|
73
|
+
# Clean up old files
|
74
|
+
rm -rf logs/* 2>/dev/null || true
|
75
|
+
else
|
76
|
+
echo "๐งช DRY RUN: Skipping cleanup (existing processes will remain)"
|
77
|
+
fi
|
48
78
|
|
49
79
|
# ========================================
|
50
80
|
# VERIFY PREREQUISITES
|
@@ -56,8 +86,32 @@ echo "๐ Checking prerequisites..."
|
|
56
86
|
NODE_VERSION=$(node --version | sed 's/v//' | cut -d. -f1)
|
57
87
|
if [ "$NODE_VERSION" -lt 20 ]; then
|
58
88
|
echo "โ Node.js 20+ required. Current version: $(node --version)"
|
59
|
-
|
89
|
+
if [ "$PLATFORM" = "Darwin" ]; then
|
90
|
+
echo "Install with: brew install node@20"
|
91
|
+
else
|
92
|
+
echo "Install with: curl -fsSL https://deb.nodesource.com/setup_20.x | sudo -E bash - && sudo apt-get install -y nodejs"
|
93
|
+
fi
|
60
94
|
exit 1
|
95
|
+
else
|
96
|
+
echo "โ
Node.js version: $(node --version)"
|
97
|
+
fi
|
98
|
+
|
99
|
+
# Check npm
|
100
|
+
echo "โ
npm version: $(npm --version)"
|
101
|
+
|
102
|
+
# Check available memory
|
103
|
+
if [ "$PLATFORM" = "Darwin" ]; then
|
104
|
+
MEMORY_GB=$(sysctl -n hw.memsize | awk '{print int($1/1024/1024/1024)}')
|
105
|
+
echo "โ
Available memory: ${MEMORY_GB}GB"
|
106
|
+
if [ "$MEMORY_GB" -lt 4 ]; then
|
107
|
+
echo "โ ๏ธ Warning: Less than 4GB RAM detected. Builds may be slow."
|
108
|
+
fi
|
109
|
+
elif [ "$PLATFORM" = "Linux" ]; then
|
110
|
+
MEMORY_GB=$(free -g | awk '/^Mem:/{print $2}')
|
111
|
+
echo "โ
Available memory: ${MEMORY_GB}GB"
|
112
|
+
if [ "$MEMORY_GB" -lt 1 ]; then
|
113
|
+
echo "โ ๏ธ Warning: Less than 1GB RAM detected. Consider adding swap space."
|
114
|
+
fi
|
61
115
|
fi
|
62
116
|
|
63
117
|
# ========================================
|
@@ -66,8 +120,14 @@ fi
|
|
66
120
|
|
67
121
|
echo "๐ Setting up OpenAI API key..."
|
68
122
|
|
69
|
-
#
|
70
|
-
if [
|
123
|
+
# In dry-run mode, use a test key
|
124
|
+
if [ "$DRY_RUN" = true ]; then
|
125
|
+
echo "๐งช DRY RUN: Using test API key"
|
126
|
+
mkdir -p "$PROJECT_DIR/server"
|
127
|
+
echo "OPENAI_API_KEY=sk-test1234567890abcdef" > "$PROJECT_DIR/server/.env"
|
128
|
+
echo "NODE_ENV=production" >> "$PROJECT_DIR/server/.env"
|
129
|
+
echo "PORT=8080" >> "$PROJECT_DIR/server/.env"
|
130
|
+
elif [ ! -f "$PROJECT_DIR/server/.env" ] || grep -q "your_openai_api_key_here" "$PROJECT_DIR/server/.env" 2>/dev/null; then
|
71
131
|
if [ "$CI" = "true" ]; then
|
72
132
|
echo "CI mode - using test API key"
|
73
133
|
mkdir -p "$PROJECT_DIR/server"
|
@@ -76,12 +136,12 @@ if [ ! -f "$PROJECT_DIR/server/.env" ] || grep -q "your_openai_api_key_here" "$P
|
|
76
136
|
echo "PORT=8080" >> "$PROJECT_DIR/server/.env"
|
77
137
|
else
|
78
138
|
echo "โ ๏ธ OpenAI API key required for SpecGen to work."
|
79
|
-
echo "Enter your OpenAI API key: "
|
139
|
+
echo "Enter your OpenAI API key (or press Enter to use test key for dry-run): "
|
80
140
|
read -r OPENAI_KEY
|
81
141
|
|
82
142
|
if [ -z "$OPENAI_KEY" ]; then
|
83
|
-
|
84
|
-
|
143
|
+
OPENAI_KEY="sk-test1234567890abcdef"
|
144
|
+
echo "Using test API key for this deployment"
|
85
145
|
fi
|
86
146
|
|
87
147
|
mkdir -p "$PROJECT_DIR/server"
|
@@ -101,35 +161,80 @@ echo "๐๏ธ Building application components..."
|
|
101
161
|
# Navigate to project directory
|
102
162
|
cd "$PROJECT_DIR"
|
103
163
|
|
104
|
-
# Install and build server
|
105
|
-
if [ ! -
|
164
|
+
# Install and build server with better extraction
|
165
|
+
if [ ! -f "server/index.js" ]; then
|
106
166
|
echo "๐ฆ Setting up server..."
|
107
|
-
|
167
|
+
|
168
|
+
# Clean up any existing server directory
|
169
|
+
rm -rf server
|
170
|
+
|
171
|
+
# Download and extract server
|
172
|
+
echo " Downloading server package..."
|
173
|
+
npm pack @gv-sh/specgen-server --loglevel=warn
|
174
|
+
|
175
|
+
echo " Extracting server package..."
|
108
176
|
tar -xzf gv-sh-specgen-server-*.tgz
|
109
|
-
|
177
|
+
|
178
|
+
# Move the extracted package to server directory
|
179
|
+
if [ -d "package" ]; then
|
180
|
+
mv package server
|
181
|
+
echo "โ
Server extracted successfully"
|
182
|
+
else
|
183
|
+
echo "โ Failed to extract server package"
|
184
|
+
ls -la
|
185
|
+
exit 1
|
186
|
+
fi
|
187
|
+
|
188
|
+
# Clean up the tar file
|
110
189
|
rm gv-sh-specgen-server-*.tgz
|
111
190
|
|
191
|
+
# Install server dependencies
|
192
|
+
echo " Installing server dependencies..."
|
112
193
|
cd server
|
113
194
|
echo "engine-strict=false" > .npmrc
|
114
195
|
npm install --no-fund --no-audit --production --maxsockets=2 --loglevel=warn
|
196
|
+
|
197
|
+
# Verify server files
|
198
|
+
if [ ! -f "index.js" ]; then
|
199
|
+
echo "โ Server index.js not found after installation"
|
200
|
+
echo "Server directory contents:"
|
201
|
+
ls -la
|
202
|
+
exit 1
|
203
|
+
fi
|
204
|
+
|
115
205
|
cd "$PROJECT_DIR"
|
116
206
|
fi
|
117
207
|
|
118
208
|
# Install and build admin
|
119
209
|
if [ ! -d "admin/build" ]; then
|
120
210
|
echo "๐ฑ Building admin interface..."
|
211
|
+
|
121
212
|
if [ ! -d "admin" ]; then
|
122
|
-
|
213
|
+
# Clean up any existing admin directory
|
214
|
+
rm -rf admin
|
215
|
+
|
216
|
+
echo " Downloading admin package..."
|
217
|
+
npm pack @gv-sh/specgen-admin --loglevel=warn
|
123
218
|
tar -xzf gv-sh-specgen-admin-*.tgz
|
124
|
-
|
219
|
+
|
220
|
+
if [ -d "package" ]; then
|
221
|
+
mv package admin
|
222
|
+
echo "โ
Admin extracted successfully"
|
223
|
+
else
|
224
|
+
echo "โ Failed to extract admin package"
|
225
|
+
exit 1
|
226
|
+
fi
|
227
|
+
|
125
228
|
rm gv-sh-specgen-admin-*.tgz
|
126
229
|
fi
|
127
230
|
|
231
|
+
echo " Installing admin dependencies..."
|
128
232
|
cd admin
|
129
233
|
echo "engine-strict=false" > .npmrc
|
130
234
|
# Install ALL dependencies for build process
|
131
235
|
npm install --no-fund --no-audit --maxsockets=2 --loglevel=warn
|
132
|
-
|
236
|
+
echo " Building admin interface..."
|
237
|
+
# Build with proper environment variables
|
133
238
|
GENERATE_SOURCEMAP=false SKIP_PREFLIGHT_CHECK=true PUBLIC_URL=/admin npm run build
|
134
239
|
cd "$PROJECT_DIR"
|
135
240
|
fi
|
@@ -137,18 +242,33 @@ fi
|
|
137
242
|
# Install and build user
|
138
243
|
if [ ! -d "user/build" ]; then
|
139
244
|
echo "๐ค Building user interface..."
|
245
|
+
|
140
246
|
if [ ! -d "user" ]; then
|
141
|
-
|
247
|
+
# Clean up any existing user directory
|
248
|
+
rm -rf user
|
249
|
+
|
250
|
+
echo " Downloading user package..."
|
251
|
+
npm pack @gv-sh/specgen-user --loglevel=warn
|
142
252
|
tar -xzf gv-sh-specgen-user-*.tgz
|
143
|
-
|
253
|
+
|
254
|
+
if [ -d "package" ]; then
|
255
|
+
mv package user
|
256
|
+
echo "โ
User extracted successfully"
|
257
|
+
else
|
258
|
+
echo "โ Failed to extract user package"
|
259
|
+
exit 1
|
260
|
+
fi
|
261
|
+
|
144
262
|
rm gv-sh-specgen-user-*.tgz
|
145
263
|
fi
|
146
264
|
|
265
|
+
echo " Installing user dependencies..."
|
147
266
|
cd user
|
148
267
|
echo "engine-strict=false" > .npmrc
|
149
268
|
# Install ALL dependencies for build process
|
150
269
|
npm install --no-fund --no-audit --maxsockets=2 --loglevel=warn
|
151
|
-
|
270
|
+
echo " Building user interface..."
|
271
|
+
# Build with proper environment variables
|
152
272
|
GENERATE_SOURCEMAP=false SKIP_PREFLIGHT_CHECK=true REACT_APP_API_URL=/api PUBLIC_URL=/app npm run build
|
153
273
|
cd "$PROJECT_DIR"
|
154
274
|
fi
|
@@ -158,20 +278,25 @@ fi
|
|
158
278
|
# ========================================
|
159
279
|
|
160
280
|
echo "โ
Verifying builds..."
|
281
|
+
|
282
|
+
# Check admin build
|
161
283
|
if [ ! -d "$PROJECT_DIR/admin/build" ]; then
|
162
284
|
echo "โ Admin build failed"
|
163
285
|
ls -la "$PROJECT_DIR/admin/" || echo "Admin directory not found"
|
164
286
|
exit 1
|
165
287
|
fi
|
166
288
|
|
289
|
+
# Check user build
|
167
290
|
if [ ! -d "$PROJECT_DIR/user/build" ]; then
|
168
291
|
echo "โ User build failed"
|
169
292
|
ls -la "$PROJECT_DIR/user/" || echo "User directory not found"
|
170
293
|
exit 1
|
171
294
|
fi
|
172
295
|
|
296
|
+
# Check server
|
173
297
|
if [ ! -f "$PROJECT_DIR/server/index.js" ]; then
|
174
298
|
echo "โ Server index.js not found"
|
299
|
+
echo "Server directory contents:"
|
175
300
|
ls -la "$PROJECT_DIR/server/" || echo "Server directory not found"
|
176
301
|
exit 1
|
177
302
|
fi
|
@@ -179,23 +304,84 @@ fi
|
|
179
304
|
echo "๐ Build verification:"
|
180
305
|
echo " Admin build: $(ls -la "$PROJECT_DIR/admin/build/" | wc -l) files"
|
181
306
|
echo " User build: $(ls -la "$PROJECT_DIR/user/build/" | wc -l) files"
|
182
|
-
echo " Server: $(ls -la "$PROJECT_DIR/server/" | wc -l) files"
|
183
|
-
echo " Server script: $PROJECT_DIR/server/index.js"
|
307
|
+
echo " Server files: $(ls -la "$PROJECT_DIR/server/" | wc -l) files"
|
308
|
+
echo " โ
Server script: $PROJECT_DIR/server/index.js"
|
184
309
|
|
185
310
|
# Show some sample files to verify builds
|
186
|
-
echo "๐
|
187
|
-
ls "$PROJECT_DIR/admin/build/" | head -
|
188
|
-
echo "
|
189
|
-
ls "$PROJECT_DIR/
|
311
|
+
echo "๐ Key files found:"
|
312
|
+
echo " Admin: $(ls "$PROJECT_DIR/admin/build/" | grep -E '\.(html|js|css)$' | head -3 | tr '\n' ' ')"
|
313
|
+
echo " User: $(ls "$PROJECT_DIR/user/build/" | grep -E '\.(html|js|css)$' | head -3 | tr '\n' ' ')"
|
314
|
+
echo " Server: $(ls "$PROJECT_DIR/server/" | grep -E '\.(js|json)$' | head -3 | tr '\n' ' ')"
|
190
315
|
|
191
316
|
# ========================================
|
192
|
-
#
|
317
|
+
# DEPLOYMENT / TEST SERVER
|
193
318
|
# ========================================
|
194
319
|
|
195
|
-
|
196
|
-
|
197
|
-
|
198
|
-
|
320
|
+
if [ "$DRY_RUN" = true ]; then
|
321
|
+
echo ""
|
322
|
+
echo "๐งช DRY RUN: Testing server startup..."
|
323
|
+
|
324
|
+
# Test if the server can start
|
325
|
+
cd "$PROJECT_DIR"
|
326
|
+
|
327
|
+
# Copy environment
|
328
|
+
cp "$PROJECT_DIR/server/.env" "$PROJECT_DIR/.env" 2>/dev/null || true
|
329
|
+
|
330
|
+
echo " Starting test server on port 8080 for 10 seconds..."
|
331
|
+
|
332
|
+
# Start server in background
|
333
|
+
(cd server && NODE_ENV=production PORT=8080 node index.js) &
|
334
|
+
SERVER_PID=$!
|
335
|
+
|
336
|
+
# Wait a bit for server to start
|
337
|
+
sleep 3
|
338
|
+
|
339
|
+
# Test the endpoints
|
340
|
+
echo " Testing endpoints:"
|
341
|
+
|
342
|
+
if curl -s http://localhost:8080/api/health >/dev/null 2>&1; then
|
343
|
+
echo " โ
Health endpoint: OK"
|
344
|
+
echo " Response: $(curl -s http://localhost:8080/api/health | head -c 100)..."
|
345
|
+
else
|
346
|
+
echo " โ Health endpoint: FAILED"
|
347
|
+
fi
|
348
|
+
|
349
|
+
HTTP_CODE=$(curl -s -o /dev/null -w "%{http_code}" http://localhost:8080/ 2>/dev/null || echo "000")
|
350
|
+
echo " ๐ Main page: HTTP $HTTP_CODE"
|
351
|
+
|
352
|
+
HTTP_CODE=$(curl -s -o /dev/null -w "%{http_code}" http://localhost:8080/admin 2>/dev/null || echo "000")
|
353
|
+
echo " โ๏ธ Admin page: HTTP $HTTP_CODE"
|
354
|
+
|
355
|
+
HTTP_CODE=$(curl -s -o /dev/null -w "%{http_code}" http://localhost:8080/app 2>/dev/null || echo "000")
|
356
|
+
echo " ๐ค User page: HTTP $HTTP_CODE"
|
357
|
+
|
358
|
+
# Stop test server
|
359
|
+
sleep 2
|
360
|
+
kill $SERVER_PID 2>/dev/null || true
|
361
|
+
wait $SERVER_PID 2>/dev/null || true
|
362
|
+
|
363
|
+
echo ""
|
364
|
+
echo "๐ DRY RUN COMPLETED!"
|
365
|
+
echo ""
|
366
|
+
echo "๐ Summary:"
|
367
|
+
echo " โ
All packages downloaded and extracted"
|
368
|
+
echo " โ
All dependencies installed"
|
369
|
+
echo " โ
React apps built successfully"
|
370
|
+
echo " โ
Server can start and respond"
|
371
|
+
echo ""
|
372
|
+
echo "๐ Ready for production deployment!"
|
373
|
+
echo " Run without --dry-run to deploy for real"
|
374
|
+
echo ""
|
375
|
+
echo "๐ง To test locally:"
|
376
|
+
echo " cd server && npm start"
|
377
|
+
echo " Open http://localhost:8080/"
|
378
|
+
|
379
|
+
else
|
380
|
+
# Real deployment with PM2
|
381
|
+
echo "๐ Starting PM2 deployment..."
|
382
|
+
|
383
|
+
# Create PM2 ecosystem configuration with absolute paths
|
384
|
+
cat > "$PROJECT_DIR/ecosystem.config.js" << EOF
|
199
385
|
module.exports = {
|
200
386
|
apps: [{
|
201
387
|
name: 'specgen',
|
@@ -220,113 +406,72 @@ module.exports = {
|
|
220
406
|
}]
|
221
407
|
}
|
222
408
|
EOF
|
223
|
-
|
224
|
-
# Create logs directory
|
225
|
-
mkdir -p "$PROJECT_DIR/logs"
|
226
|
-
|
227
|
-
# Copy .env to project root for PM2
|
228
|
-
cp "$PROJECT_DIR/server/.env" "$PROJECT_DIR/.env" 2>/dev/null || true
|
229
|
-
|
230
|
-
# Final port check
|
231
|
-
if ! check_port 8080; then
|
232
|
-
echo "Port 8080 occupied, force cleaning..."
|
233
|
-
lsof -ti:8080 | xargs kill -9 2>/dev/null || true
|
234
|
-
sleep 2
|
235
|
-
fi
|
236
|
-
|
237
|
-
# Change to project directory and start with PM2
|
238
|
-
cd "$PROJECT_DIR"
|
239
|
-
echo "โถ๏ธ Starting SpecGen with PM2..."
|
240
|
-
echo " Script: $PROJECT_DIR/server/index.js"
|
241
|
-
echo " Working Directory: $PROJECT_DIR"
|
242
|
-
|
243
|
-
# Verify the script exists before starting PM2
|
244
|
-
if [ ! -f "$PROJECT_DIR/server/index.js" ]; then
|
245
|
-
echo "โ ERROR: Server script not found at $PROJECT_DIR/server/index.js"
|
246
|
-
echo "Contents of server directory:"
|
247
|
-
ls -la "$PROJECT_DIR/server/"
|
248
|
-
exit 1
|
249
|
-
fi
|
250
|
-
|
251
|
-
NODE_ENV=production PORT=8080 npx pm2 start "$PROJECT_DIR/ecosystem.config.js"
|
252
|
-
|
253
|
-
# Wait for startup and verify
|
254
|
-
sleep 5
|
255
|
-
|
256
|
-
# ========================================
|
257
|
-
# DEPLOYMENT VERIFICATION
|
258
|
-
# ========================================
|
259
|
-
|
260
|
-
echo "๐ Verifying deployment..."
|
261
|
-
|
262
|
-
if npx pm2 list | grep -q "online"; then
|
263
|
-
# Test endpoints
|
264
|
-
echo "Testing endpoints:"
|
265
409
|
|
266
|
-
#
|
267
|
-
|
268
|
-
echo "โ
Health endpoint: OK"
|
269
|
-
else
|
270
|
-
echo "โ Health endpoint: FAILED"
|
271
|
-
fi
|
410
|
+
# Create logs directory
|
411
|
+
mkdir -p "$PROJECT_DIR/logs"
|
272
412
|
|
273
|
-
#
|
274
|
-
|
275
|
-
if [ "$HTTP_CODE" = "200" ]; then
|
276
|
-
echo "โ
Main page: OK (HTTP $HTTP_CODE)"
|
277
|
-
else
|
278
|
-
echo "โ ๏ธ Main page: HTTP $HTTP_CODE"
|
279
|
-
# Show what the server is actually serving
|
280
|
-
echo "Response preview:"
|
281
|
-
curl -s http://localhost:8080/ | head -3
|
282
|
-
fi
|
413
|
+
# Copy .env to project root for PM2
|
414
|
+
cp "$PROJECT_DIR/server/.env" "$PROJECT_DIR/.env" 2>/dev/null || true
|
283
415
|
|
284
|
-
#
|
285
|
-
|
286
|
-
|
287
|
-
|
288
|
-
|
289
|
-
echo "โ ๏ธ Admin page: HTTP $HTTP_CODE"
|
416
|
+
# Final port check
|
417
|
+
if ! check_port 8080; then
|
418
|
+
echo "Port 8080 occupied, force cleaning..."
|
419
|
+
lsof -ti:8080 | xargs kill -9 2>/dev/null || true
|
420
|
+
sleep 2
|
290
421
|
fi
|
291
422
|
|
292
|
-
#
|
293
|
-
|
294
|
-
|
295
|
-
echo "โ
User app: OK (HTTP $HTTP_CODE)"
|
296
|
-
else
|
297
|
-
echo "โ ๏ธ User app: HTTP $HTTP_CODE"
|
298
|
-
fi
|
423
|
+
# Start with PM2
|
424
|
+
cd "$PROJECT_DIR"
|
425
|
+
echo "โถ๏ธ Starting SpecGen with PM2..."
|
299
426
|
|
300
|
-
|
427
|
+
NODE_ENV=production PORT=8080 $PM2_CMD start "$PROJECT_DIR/ecosystem.config.js"
|
301
428
|
|
302
|
-
|
303
|
-
|
304
|
-
echo ""
|
305
|
-
echo "๐ Access your application at:"
|
306
|
-
echo " - Main page: http://$PUBLIC_IP:8080/"
|
307
|
-
echo " - User app: http://$PUBLIC_IP:8080/app"
|
308
|
-
echo " - Admin panel: http://$PUBLIC_IP:8080/admin"
|
309
|
-
echo " - API docs: http://$PUBLIC_IP:8080/api-docs"
|
310
|
-
echo " - Health check: http://$PUBLIC_IP:8080/api/health"
|
311
|
-
echo ""
|
312
|
-
echo "๐ Management:"
|
313
|
-
echo " npx pm2 status # Check status"
|
314
|
-
echo " npx pm2 logs specgen # View logs"
|
315
|
-
echo " npx pm2 restart specgen # Restart"
|
316
|
-
echo ""
|
317
|
-
echo "๐ง Troubleshooting:"
|
318
|
-
echo " curl http://localhost:8080/api/health # Test API"
|
319
|
-
echo " curl -I http://localhost:8080/ # Test main page"
|
320
|
-
echo " ls -la */build/ # Check builds"
|
321
|
-
echo ""
|
429
|
+
# Wait for startup and verify
|
430
|
+
sleep 5
|
322
431
|
|
323
|
-
|
324
|
-
echo ""
|
325
|
-
|
326
|
-
|
327
|
-
|
328
|
-
|
329
|
-
|
330
|
-
|
331
|
-
|
432
|
+
# Verify deployment
|
433
|
+
echo "๐ Verifying deployment..."
|
434
|
+
|
435
|
+
if $PM2_CMD list | grep -q "online"; then
|
436
|
+
echo "Testing endpoints:"
|
437
|
+
|
438
|
+
if curl -s http://localhost:8080/api/health >/dev/null 2>&1; then
|
439
|
+
echo "โ
Health endpoint: OK"
|
440
|
+
else
|
441
|
+
echo "โ Health endpoint: FAILED"
|
442
|
+
fi
|
443
|
+
|
444
|
+
HTTP_CODE=$(curl -s -o /dev/null -w "%{http_code}" http://localhost:8080/ 2>/dev/null)
|
445
|
+
echo "๐ Main page: HTTP $HTTP_CODE"
|
446
|
+
|
447
|
+
HTTP_CODE=$(curl -s -o /dev/null -w "%{http_code}" http://localhost:8080/admin 2>/dev/null)
|
448
|
+
echo "โ๏ธ Admin page: HTTP $HTTP_CODE"
|
449
|
+
|
450
|
+
HTTP_CODE=$(curl -s -o /dev/null -w "%{http_code}" http://localhost:8080/app 2>/dev/null)
|
451
|
+
echo "๐ค User page: HTTP $HTTP_CODE"
|
452
|
+
|
453
|
+
PUBLIC_IP=$(curl -s ifconfig.me 2>/dev/null || curl -s ipecho.net/plain 2>/dev/null || echo 'your-server')
|
454
|
+
|
455
|
+
echo ""
|
456
|
+
echo "๐ SpecGen deployment completed!"
|
457
|
+
echo ""
|
458
|
+
echo "๐ Access your application at:"
|
459
|
+
echo " - Main page: http://$PUBLIC_IP:8080/"
|
460
|
+
echo " - User app: http://$PUBLIC_IP:8080/app"
|
461
|
+
echo " - Admin panel: http://$PUBLIC_IP:8080/admin"
|
462
|
+
echo " - API docs: http://$PUBLIC_IP:8080/api-docs"
|
463
|
+
echo " - Health check: http://$PUBLIC_IP:8080/api/health"
|
464
|
+
echo ""
|
465
|
+
echo "๐ Management commands:"
|
466
|
+
echo " $PM2_CMD status # Check status"
|
467
|
+
echo " $PM2_CMD logs specgen # View logs"
|
468
|
+
echo " $PM2_CMD restart specgen # Restart"
|
469
|
+
|
470
|
+
else
|
471
|
+
echo ""
|
472
|
+
echo "โ Deployment failed!"
|
473
|
+
echo "๐ Check logs: $PM2_CMD logs specgen"
|
474
|
+
echo "๐ Check status: $PM2_CMD status"
|
475
|
+
exit 1
|
476
|
+
fi
|
332
477
|
fi
|