Add production build scripts and ecosystem configurations for seedbox frontend

This commit is contained in:
Salman Qureshi
2025-08-10 04:16:06 +05:30
parent 08bd136ca2
commit dc91bc8cdc
7 changed files with 121 additions and 8 deletions

1
.gitignore vendored
View File

@@ -61,3 +61,4 @@ coverage/
# Optional eslint cache
.eslintcache
server-new/.env.production

View File

@@ -0,0 +1,15 @@
#!/bin/bash
# Production build script
echo "🔨 Building frontend for production..."
# Set production environment
export NODE_ENV=production
export VITE_API_BASE_URL=https://seedbox-api.isalman.dev
# Build the project
npm run build
echo "✅ Production build complete!"
echo "📦 Built files are in the 'dist' directory"
echo "🌐 API Base URL: ${VITE_API_BASE_URL}"

View File

@@ -0,0 +1,21 @@
module.exports = {
apps: [
{
name: 'seedbox-frontend',
script: 'server.js',
cwd: '/home/toor/seedbox-lite/client',
instances: 1,
autorestart: true,
watch: false,
max_memory_restart: '1G',
error_file: './logs/frontend-error.log',
out_file: './logs/frontend-out.log',
log_file: './logs/frontend-combined.log',
time: true,
env: {
NODE_ENV: 'production',
PORT: 5174
}
}
]
};

View File

@@ -0,0 +1,21 @@
module.exports = {
apps: [
{
name: 'seedbox-frontend',
script: 'npx',
args: ['serve', '-s', 'dist', '-l', '5174'],
cwd: '/home/toor/seedbox-lite/client',
instances: 1,
autorestart: true,
watch: false,
max_memory_restart: '1G',
error_file: './logs/frontend-error.log',
out_file: './logs/frontend-out.log',
log_file: './logs/frontend-combined.log',
time: true,
env: {
NODE_ENV: 'production'
}
}
]
};

View File

@@ -0,0 +1,23 @@
module.exports = {
apps: [
{
name: 'seedbox-frontend',
script: 'serve',
args: ['-s', 'dist', '-l', '5174', '-C'],
env: {
PM2_SERVE_PATH: './dist',
PM2_SERVE_PORT: 5174,
PM2_SERVE_SPA: 'true',
PM2_SERVE_HOMEPAGE: '/index.html'
},
instances: 1,
autorestart: true,
watch: false,
max_memory_restart: '1G',
error_file: './logs/frontend-error.log',
out_file: './logs/frontend-out.log',
log_file: './logs/frontend-combined.log',
time: true
}
]
};

18
client/server.js Normal file
View File

@@ -0,0 +1,18 @@
#!/usr/bin/env node
const express = require('express');
const path = require('path');
const app = express();
const PORT = process.env.PORT || 5174;
// Serve static files from dist directory
app.use(express.static(path.join(__dirname, 'dist')));
// Handle React Router - send all requests to index.html
app.get('*', (req, res) => {
res.sendFile(path.join(__dirname, 'dist', 'index.html'));
});
app.listen(PORT, () => {
console.log(`🚀 Frontend server running on http://localhost:${PORT}`);
});

View File

@@ -19,7 +19,7 @@ const config = {
omdb: {
apiKey: process.env.OMDB_API_KEY || '8265bd1c' // Free API key for development
},
isDevelopment: process.env.NODE_ENV === 'development'
isDevelopment: process.env.NODE_ENV !== 'production'
};
const app = express();
@@ -630,14 +630,28 @@ const upload = multer({
});
// CORS Configuration
const allowedOrigins = [
config.frontend.url,
'http://localhost:5173',
'http://localhost:5174',
'http://localhost:3000',
'http://127.0.0.1:5173',
'http://127.0.0.1:5174',
'http://127.0.0.1:3000'
];
// Add production domains if not in development
if (!config.isDevelopment) {
allowedOrigins.push(
'https://seedbox.isalman.dev',
'https://seedbox-api.isalman.dev'
);
}
console.log('🌐 CORS allowed origins:', allowedOrigins);
app.use(cors({
origin: [
config.frontend.url,
'http://localhost:5173',
'http://localhost:3000',
'http://127.0.0.1:5173',
'http://127.0.0.1:3000'
],
origin: allowedOrigins,
credentials: true,
methods: ['GET', 'POST', 'PUT', 'DELETE', 'OPTIONS'],
allowedHeaders: ['Content-Type', 'Authorization']