Spaces:
Runtime error

FireTech-Message-server / setup-https.ps1
Dhurgh's picture
Initial commit: updated chat app
272dfc6
Raw History Blame
3.55 kB
# Ultimate Chat App - Quick HTTPS Setup for LAN Access
# Run this in PowerShell from the project directory
Write-Host "πŸš€ Ultimate Chat App - HTTPS LAN Setup" -ForegroundColor Cyan
Write-Host "=======================================" -ForegroundColor Cyan
Write-Host ""
# Get LAN IP
$lanIP = (Get-NetIPAddress -AddressFamily IPv4 | Where-Object {$_.InterfaceAlias -notlike "*Loopback*" -and $_.IPAddress -notlike "169.254.*"}).IPAddress | Select-Object -First 1
if (!$lanIP) {
Write-Host "❌ Could not detect LAN IP address" -ForegroundColor Red
exit 1
}
Write-Host "πŸ“‘ Detected LAN IP: $lanIP" -ForegroundColor Green
Write-Host ""
# Stop existing Node processes
Write-Host "πŸ›‘ Stopping existing Node processes..." -ForegroundColor Yellow
taskkill /F /IM node.exe 2>$null | Out-Null
# Create certs directory
Write-Host "πŸ“ Creating certs directory..." -ForegroundColor Yellow
New-Item -ItemType Directory -Force .\certs | Out-Null
# Add firewall rule
Write-Host "πŸ”₯ Adding Windows Firewall rule..." -ForegroundColor Yellow
$existingRule = Get-NetFirewallRule -DisplayName "Chat App HTTPS" -ErrorAction SilentlyContinue
if (!$existingRule) {
New-NetFirewallRule -DisplayName "Chat App HTTPS" -Direction Inbound -LocalPort 3001 -Protocol TCP -Action Allow | Out-Null
Write-Host "βœ… Firewall rule added" -ForegroundColor Green
} else {
Write-Host "βœ… Firewall rule already exists" -ForegroundColor Green
}
# Generate certificate
Write-Host "πŸ” Generating HTTPS certificate for localhost and $lanIP..." -ForegroundColor Yellow
$cert = New-SelfSignedCertificate `
-Subject "CN=localhost" `
-CertStoreLocation "Cert:\CurrentUser\My" `
-KeyAlgorithm RSA -KeyLength 2048 `
-HashAlgorithm SHA256 `
-NotAfter (Get-Date).AddYears(2) `
-TextExtension @("2.5.29.17={text}DNS=localhost&IPAddress=$lanIP")
# Export certificate
$pwd = ConvertTo-SecureString "123456" -AsPlainText -Force
Export-PfxCertificate -Cert $cert -FilePath ".\certs\lan-localhost.pfx" -Password $pwd | Out-Null
Export-Certificate -Cert $cert -FilePath ".\certs\lan-localhost.cer" -Force | Out-Null
Write-Host "βœ… Certificate generated" -ForegroundColor Green
# Trust certificate
Write-Host "πŸ”’ Trusting certificate..." -ForegroundColor Yellow
Import-Certificate -FilePath ".\certs\lan-localhost.cer" -CertStoreLocation "Cert:\CurrentUser\Root" | Out-Null
Write-Host "βœ… Certificate trusted" -ForegroundColor Green
Write-Host ""
# Set environment variables
$env:SSL_PFX_PATH = (Resolve-Path ".\certs\lan-localhost.pfx").Path
$env:SSL_PFX_PASSPHRASE = "123456"
$env:PORT = "3001"
# Display access URLs
Write-Host "╔═══════════════════════════════════════╗" -ForegroundColor Cyan
Write-Host "β•‘ πŸŽ‰ Setup Complete! β•‘" -ForegroundColor Cyan
Write-Host "β•šβ•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•" -ForegroundColor Cyan
Write-Host ""
Write-Host "Access URLs:" -ForegroundColor Yellow
Write-Host " πŸ“± On this PC: https://localhost:3001" -ForegroundColor White
Write-Host " πŸ“± On LAN devices: https://$lanIP:3001" -ForegroundColor White
Write-Host ""
Write-Host "Note: Mobile devices will show a certificate warning." -ForegroundColor Gray
Write-Host " Click 'Advanced' β†’ 'Proceed' to continue." -ForegroundColor Gray
Write-Host ""
Write-Host "Starting server..." -ForegroundColor Yellow
Write-Host ""
# Start the app
npm start