Spaces:
Runtime error
Runtime error
File size: 3,180 Bytes
64e57ec 272dfc6 55a57c5 272dfc6 64e57ec 272dfc6 55a57c5 272dfc6 55a57c5 272dfc6 64e57ec 55a57c5 272dfc6 64e57ec 55a57c5 272dfc6 64e57ec 55a57c5 272dfc6 55a57c5 272dfc6 55a57c5 272dfc6 64e57ec 55a57c5 272dfc6 64e57ec 272dfc6 55a57c5 272dfc6 64e57ec 55a57c5 272dfc6 55a57c5 272dfc6 64e57ec 272dfc6 64e57ec 272dfc6 55a57c5 272dfc6 55a57c5 272dfc6 64e57ec 272dfc6 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 |
Write-Host " Ultimate Chat App - HTTPS LAN Setup" -ForegroundColor Cyan
Write-Host "=======================================" -ForegroundColor Cyan
Write-Host ""
$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 ""
Write-Host " Stopping existing Node processes..." -ForegroundColor Yellow
taskkill /F /IM node.exe 2>$null | Out-Null
Write-Host " Creating certs directory..." -ForegroundColor Yellow
New-Item -ItemType Directory -Force .\certs | Out-Null
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
}
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")
$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
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 ""
$env:SSL_PFX_PATH = (Resolve-Path ".\certs\lan-localhost.pfx").Path
$env:SSL_PFX_PASSPHRASE = "123456"
$env:PORT = "3001"
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 ""
npm start
|