124 lines
2.9 KiB
Bash
124 lines
2.9 KiB
Bash
#!/bin/bash
|
|
|
|
# CC24-Hub - Node.js Deployment Script
|
|
|
|
set -e
|
|
|
|
PROJECT_DIR="/var/www/dfir-tools-hub"
|
|
SERVICE_NAME="dfir-tools-hub"
|
|
SERVICE_PORT="3000"
|
|
|
|
echo "🔧 Setting up Node.js deployment..."
|
|
|
|
cd $PROJECT_DIR
|
|
|
|
# Install PM2 globally if not present
|
|
if ! command -v pm2 &> /dev/null; then
|
|
sudo npm install -g pm2
|
|
fi
|
|
|
|
# Install dependencies
|
|
npm ci --production
|
|
|
|
# Update astro.config.mjs for Node.js adapter
|
|
cat > astro.config.mjs << 'EOF'
|
|
import { defineConfig } from 'astro/config';
|
|
|
|
export default defineConfig({
|
|
output: 'server',
|
|
adapter: '@astrojs/node',
|
|
server: {
|
|
port: 3000,
|
|
host: '127.0.0.1'
|
|
}
|
|
});
|
|
EOF
|
|
|
|
# Install Node.js adapter
|
|
npm install @astrojs/node
|
|
|
|
# Build for Node.js
|
|
npm run build
|
|
|
|
# Create PM2 ecosystem file
|
|
cat > ecosystem.config.js << EOF
|
|
module.exports = {
|
|
apps: [{
|
|
name: '$SERVICE_NAME',
|
|
script: './dist/server/entry.mjs',
|
|
instances: 'max',
|
|
exec_mode: 'cluster',
|
|
env: {
|
|
NODE_ENV: 'production',
|
|
PORT: $SERVICE_PORT,
|
|
HOST: '127.0.0.1'
|
|
},
|
|
error_file: '/var/log/pm2/$SERVICE_NAME-error.log',
|
|
out_file: '/var/log/pm2/$SERVICE_NAME-out.log',
|
|
log_file: '/var/log/pm2/$SERVICE_NAME.log',
|
|
time: true,
|
|
max_memory_restart: '1G'
|
|
}]
|
|
};
|
|
EOF
|
|
|
|
# Create log directory
|
|
sudo mkdir -p /var/log/pm2
|
|
sudo chown -R $(whoami):$(whoami) /var/log/pm2
|
|
|
|
# Start/restart with PM2
|
|
pm2 delete $SERVICE_NAME 2>/dev/null || true
|
|
pm2 start ecosystem.config.js
|
|
pm2 save
|
|
pm2 startup
|
|
|
|
echo "🔧 Configuring nginx reverse proxy..."
|
|
|
|
# Create nginx configuration for Node.js
|
|
sudo tee /etc/nginx/sites-available/$SERVICE_NAME << EOF
|
|
upstream dfir_backend {
|
|
server 127.0.0.1:$SERVICE_PORT;
|
|
}
|
|
|
|
server {
|
|
listen 80;
|
|
server_name dfir-tools.yourdomain.com; # Replace with your domain
|
|
|
|
# Security headers
|
|
add_header X-Frame-Options "SAMEORIGIN" always;
|
|
add_header X-Content-Type-Options "nosniff" always;
|
|
add_header X-XSS-Protection "1; mode=block" always;
|
|
|
|
# Proxy to Node.js application
|
|
location / {
|
|
proxy_pass http://dfir_backend;
|
|
proxy_http_version 1.1;
|
|
proxy_set_header Upgrade \$http_upgrade;
|
|
proxy_set_header Connection 'upgrade';
|
|
proxy_set_header Host \$host;
|
|
proxy_set_header X-Real-IP \$remote_addr;
|
|
proxy_set_header X-Forwarded-For \$proxy_add_x_forwarded_for;
|
|
proxy_set_header X-Forwarded-Proto \$scheme;
|
|
proxy_cache_bypass \$http_upgrade;
|
|
|
|
# Timeouts
|
|
proxy_connect_timeout 60s;
|
|
proxy_send_timeout 60s;
|
|
proxy_read_timeout 60s;
|
|
}
|
|
|
|
# Health check endpoint
|
|
location /health {
|
|
access_log off;
|
|
proxy_pass http://dfir_backend/health;
|
|
}
|
|
}
|
|
EOF
|
|
|
|
# Enable site and reload nginx
|
|
sudo ln -sf /etc/nginx/sites-available/$SERVICE_NAME /etc/nginx/sites-enabled/
|
|
sudo nginx -t && sudo systemctl reload nginx
|
|
|
|
echo "✅ Node.js deployment completed!"
|
|
echo "🔍 Status: pm2 status"
|
|
echo "📋 Logs: pm2 logs $SERVICE_NAME" |