Spaces:
Runtime error

File size: 3,550 Bytes
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
81
# 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