@gv-sh/specgen-app 0.6.5 → 0.6.6

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 CHANGED
@@ -1,6 +1,6 @@
1
1
  # SpecGen App - Complete Platform
2
2
 
3
- [![Version](https://img.shields.io/badge/version-0.6.5-blue.svg)](https://github.com/gv-sh/specgen-app)
3
+ [![Version](https://img.shields.io/badge/version-0.6.6-blue.svg)](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.5",
3
+ "version": "0.6.6",
4
4
  "description": "Complete SpecGen application with server, admin, and user interfaces",
5
5
  "main": "index.js",
6
6
  "bin": {
package/scripts/deploy.sh CHANGED
@@ -232,6 +232,170 @@ if [ ! -f "server/index.js" ]; then
232
232
  fi
233
233
 
234
234
  cd "$PROJECT_DIR"
235
+
236
+ # Replace with unified server that serves static files
237
+ echo " 🔧 Installing unified server for port 8080..."
238
+ cat > server/index.js << 'EOF'
239
+ // index.js - Unified server for port 8080 with proper routing
240
+ /* global process */
241
+ require('dotenv').config();
242
+ const express = require('express');
243
+ const cors = require('cors');
244
+ const path = require('path');
245
+ const errorHandler = require('./middleware/errorHandler');
246
+
247
+ // Initialize Express app
248
+ const app = express();
249
+ let PORT = process.env.PORT || 8080;
250
+
251
+ // Middleware
252
+ app.use(cors());
253
+ app.use(express.json());
254
+ app.use(express.urlencoded({ extended: true }));
255
+
256
+ // Serve static files for admin interface at /admin
257
+ const adminBuildPath = path.join(__dirname, '../admin/build');
258
+ const fs = require('fs');
259
+ if (fs.existsSync(adminBuildPath)) {
260
+ app.use('/admin', express.static(adminBuildPath));
261
+ // Handle React Router for admin (catch all admin routes)
262
+ app.get('/admin/*', (req, res) => {
263
+ res.sendFile(path.join(adminBuildPath, 'index.html'));
264
+ });
265
+ console.log('✅ Admin interface available at /admin');
266
+ } else {
267
+ console.log('⚠️ Admin build not found at', adminBuildPath);
268
+ }
269
+
270
+ // Serve static files for user interface at /app
271
+ const userBuildPath = path.join(__dirname, '../user/build');
272
+ if (fs.existsSync(userBuildPath)) {
273
+ app.use('/app', express.static(userBuildPath));
274
+ // Handle React Router for user app (catch all app routes)
275
+ app.get('/app/*', (req, res) => {
276
+ res.sendFile(path.join(userBuildPath, 'index.html'));
277
+ });
278
+ console.log('✅ User interface available at /app');
279
+ } else {
280
+ console.log('⚠️ User build not found at', userBuildPath);
281
+ }
282
+
283
+ // Serve user interface as default at root (/) as well
284
+ if (fs.existsSync(userBuildPath)) {
285
+ app.use('/', express.static(userBuildPath, { index: false }));
286
+ }
287
+
288
+ // Routes
289
+ const categoryRoutes = require('./routes/categories');
290
+ const parameterRoutes = require('./routes/parameters');
291
+ const generateRoutes = require('./routes/generate');
292
+ const databaseRoutes = require('./routes/database');
293
+ const contentRoutes = require('./routes/content');
294
+ const settingsRoutes = require('./routes/settings');
295
+
296
+ // API Routes
297
+ app.use('/api/categories', categoryRoutes);
298
+ app.use('/api/parameters', parameterRoutes);
299
+ app.use('/api/generate', generateRoutes);
300
+ app.use('/api/database', databaseRoutes);
301
+ app.use('/api/content', contentRoutes);
302
+ app.use('/api/settings', settingsRoutes);
303
+
304
+ // Only add Swagger in non-test environment
305
+ if (process.env.NODE_ENV !== 'test') {
306
+ const swaggerRoutes = require('./routes/swagger');
307
+ app.use('/api-docs', swaggerRoutes);
308
+ }
309
+
310
+ // Health check routes
311
+ const healthRoutes = require('./routes/health');
312
+ app.use('/api/health', healthRoutes);
313
+
314
+ // Root route - serve user app or provide navigation
315
+ app.get('/', (req, res) => {
316
+ // If user build exists, serve it
317
+ if (fs.existsSync(userBuildPath)) {
318
+ res.sendFile(path.join(userBuildPath, 'index.html'));
319
+ } else {
320
+ // Fallback navigation page
321
+ const html = `
322
+ <!DOCTYPE html>
323
+ <html>
324
+ <head>
325
+ <title>SpecGen - API & Applications</title>
326
+ <style>
327
+ body { font-family: Arial, sans-serif; max-width: 800px; margin: 50px auto; padding: 20px; background: #f8f9fa; }
328
+ .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); }
329
+ .nav-card:hover { background-color: #f8f9fa; transform: translateY(-2px); transition: all 0.2s; }
330
+ a { text-decoration: none; color: #007bff; }
331
+ h1 { color: #343a40; text-align: center; }
332
+ .status { color: #28a745; font-weight: bold; text-align: center; background: #d4edda; padding: 10px; border-radius: 5px; margin: 20px 0; }
333
+ .footer { text-align: center; margin-top: 30px; color: #6c757d; font-size: 14px; }
334
+ .warning { background: #fff3cd; border: 1px solid #ffeaa7; padding: 15px; border-radius: 5px; margin: 20px 0; }
335
+ </style>
336
+ </head>
337
+ <body>
338
+ <h1>🚀 SpecGen Platform</h1>
339
+ <div class="status">✅ All services running on port ${PORT}</div>
340
+
341
+ <div class="warning">
342
+ <strong>🔒 AWS Security Group Note:</strong> If you can't access this from outside,
343
+ add port ${PORT} to your AWS Security Group inbound rules.
344
+ </div>
345
+
346
+ <div class="nav-card">
347
+ <h3><a href="/app">📱 User Application</a></h3>
348
+ <p>Main SpecGen user interface for creating and managing specifications</p>
349
+ </div>
350
+
351
+ <div class="nav-card">
352
+ <h3><a href="/admin">⚙️ Admin Panel</a></h3>
353
+ <p>Administrative interface for system management and configuration</p>
354
+ </div>
355
+
356
+ <div class="nav-card">
357
+ <h3><a href="/api-docs">📚 API Documentation</a></h3>
358
+ <p>Interactive API documentation and testing interface</p>
359
+ </div>
360
+
361
+ <div class="nav-card">
362
+ <h3><a href="/api/health">❤️ Health Check</a></h3>
363
+ <p>System health and status monitoring endpoint</p>
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>
370
+ </div>
371
+ </body>
372
+ </html>`;
373
+ res.send(html);
374
+ }
375
+ });
376
+
377
+ // Error handling middleware
378
+ app.use(errorHandler);
379
+
380
+ if (require.main === module) {
381
+ app.listen(PORT, () => {
382
+ console.log(`🚀 SpecGen unified server running on port ${PORT}`);
383
+ console.log(`📱 User App: http://localhost:${PORT}/app`);
384
+ console.log(`⚙️ Admin Panel: http://localhost:${PORT}/admin`);
385
+ console.log(`📚 API Docs: http://localhost:${PORT}/api-docs`);
386
+ console.log(`❤️ Health Check: http://localhost:${PORT}/api/health`);
387
+ console.log(`🏠 Main Page: http://localhost:${PORT}/`);
388
+ console.log(`🔒 AWS Note: Ensure port ${PORT} is open in Security Groups`);
389
+ if (process.env.NODE_ENV !== 'test') {
390
+ console.log(`- API Documentation: http://localhost:${PORT}/api-docs`);
391
+ }
392
+ console.log(`- API is ready for use`);
393
+ });
394
+ }
395
+
396
+ module.exports = app;
397
+ EOF
398
+ echo "✅ Unified server installed"
235
399
  fi
236
400
 
237
401
  # Install and build admin
@@ -388,10 +552,10 @@ if [ "$DRY_RUN" = true ]; then
388
552
  HTTP_CODE=$(curl -s -o /dev/null -w "%{http_code}" http://localhost:$TEST_PORT/ 2>/dev/null || echo "000")
389
553
  echo " 📄 Main page: HTTP $HTTP_CODE"
390
554
 
391
- HTTP_CODE=$(curl -s -o /dev/null -w "%{http_code}" http://localhost:$TEST_PORT/admin 2>/dev/null || echo "000")
555
+ HTTP_CODE=$(curl -s -o /dev/null -w "%{http_code}" http://localhost:$TEST_PORT/admin/ 2>/dev/null || echo "000")
392
556
  echo " ⚙️ Admin page: HTTP $HTTP_CODE"
393
557
 
394
- HTTP_CODE=$(curl -s -o /dev/null -w "%{http_code}" http://localhost:$TEST_PORT/app 2>/dev/null || echo "000")
558
+ HTTP_CODE=$(curl -s -o /dev/null -w "%{http_code}" http://localhost:$TEST_PORT/app/ 2>/dev/null || echo "000")
395
559
  echo " 👤 User page: HTTP $HTTP_CODE"
396
560
 
397
561
  # Stop test server
@@ -411,6 +575,7 @@ if [ "$DRY_RUN" = true ]; then
411
575
  echo " ✅ All packages downloaded and extracted"
412
576
  echo " ✅ All dependencies installed"
413
577
  echo " ✅ React apps built successfully"
578
+ echo " ✅ Unified server installed"
414
579
  echo " ✅ Server can start and respond"
415
580
  echo ""
416
581
  if [ "$NODE_VERSION" -lt 20 ]; then
@@ -423,6 +588,11 @@ if [ "$DRY_RUN" = true ]; then
423
588
  echo "🚀 Ready for production deployment!"
424
589
  echo " Deploy to AWS with: npx @gv-sh/specgen-app deploy"
425
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 ""
426
596
  echo "🔧 To test locally right now:"
427
597
  echo " cd server && npm start"
428
598
  echo " Open http://localhost:8080/"
@@ -495,10 +665,10 @@ EOF
495
665
  HTTP_CODE=$(curl -s -o /dev/null -w "%{http_code}" http://localhost:8080/ 2>/dev/null)
496
666
  echo "📄 Main page: HTTP $HTTP_CODE"
497
667
 
498
- HTTP_CODE=$(curl -s -o /dev/null -w "%{http_code}" http://localhost:8080/admin 2>/dev/null)
668
+ HTTP_CODE=$(curl -s -o /dev/null -w "%{http_code}" http://localhost:8080/admin/ 2>/dev/null)
499
669
  echo "⚙️ Admin page: HTTP $HTTP_CODE"
500
670
 
501
- HTTP_CODE=$(curl -s -o /dev/null -w "%{http_code}" http://localhost:8080/app 2>/dev/null)
671
+ HTTP_CODE=$(curl -s -o /dev/null -w "%{http_code}" http://localhost:8080/app/ 2>/dev/null)
502
672
  echo "👤 User page: HTTP $HTTP_CODE"
503
673
 
504
674
  PUBLIC_IP=$(curl -s ifconfig.me 2>/dev/null || curl -s ipecho.net/plain 2>/dev/null || echo 'your-server')
@@ -508,11 +678,16 @@ EOF
508
678
  echo ""
509
679
  echo "🌐 Access your application at:"
510
680
  echo " - Main page: http://$PUBLIC_IP:8080/"
511
- echo " - User app: http://$PUBLIC_IP:8080/app"
512
- echo " - Admin panel: http://$PUBLIC_IP:8080/admin"
681
+ echo " - User app: http://$PUBLIC_IP:8080/app/"
682
+ echo " - Admin panel: http://$PUBLIC_IP:8080/admin/"
513
683
  echo " - API docs: http://$PUBLIC_IP:8080/api-docs"
514
684
  echo " - Health check: http://$PUBLIC_IP:8080/api/health"
515
685
  echo ""
686
+ echo "🔒 AWS Security Group:"
687
+ echo " If you can't access from outside, add port 8080 to inbound rules:"
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 ""
516
691
  echo "📊 Management commands:"
517
692
  echo " $PM2_CMD status # Check status"
518
693
  echo " $PM2_CMD logs specgen # View logs"