109 lines
4.7 KiB
Batchfile
109 lines
4.7 KiB
Batchfile
|
|
@echo off
|
||
|
|
REM Complete IIS Fix - Unlock Handlers and Configure Everything
|
||
|
|
REM Run as Administrator
|
||
|
|
|
||
|
|
echo ========================================
|
||
|
|
echo COMPLETE IIS FIX FOR POZO APP
|
||
|
|
echo ========================================
|
||
|
|
echo.
|
||
|
|
|
||
|
|
REM Check if running as Administrator
|
||
|
|
net session >nul 2>&1
|
||
|
|
if %errorLevel% neq 0 (
|
||
|
|
echo [ERROR] This script must be run as Administrator!
|
||
|
|
echo Please right-click and select "Run as administrator"
|
||
|
|
pause
|
||
|
|
exit /b 1
|
||
|
|
)
|
||
|
|
|
||
|
|
echo [1/5] Checking iisnode installation...
|
||
|
|
if exist "C:\Program Files\iisnode\iisnode.dll" (
|
||
|
|
echo [OK] iisnode is installed
|
||
|
|
) else if exist "C:\Program Files (x86)\iisnode\iisnode.dll" (
|
||
|
|
echo [OK] iisnode is installed (x86)
|
||
|
|
) else (
|
||
|
|
echo [WARNING] iisnode.dll not found in standard locations
|
||
|
|
echo [INFO] Checking IIS modules...
|
||
|
|
powershell -Command "Import-Module WebAdministration; Get-WebGlobalModule | Where-Object { $_.Name -eq 'iisnode' } | Format-Table Name, Image" 2>nul
|
||
|
|
)
|
||
|
|
|
||
|
|
echo.
|
||
|
|
echo [2/5] Unlocking handlers section...
|
||
|
|
powershell -Command "$ErrorActionPreference = 'SilentlyContinue'; Import-Module WebAdministration; try { Set-WebConfigurationProperty -PSPath 'MACHINE/WEBROOT/APPHOST' -Filter 'system.webServer/handlers' -Name 'overrideMode' -Value 'Allow' -ErrorAction Stop; Write-Host '[OK] Handlers section unlocked' } catch { Write-Host '[INFO] Trying alternative method...'; try { $config = Get-WebConfiguration -PSPath 'MACHINE/WEBROOT/APPHOST' -Filter 'system.webServer/handlers'; $config.overrideMode = 'Allow'; Set-WebConfiguration -PSPath 'MACHINE/WEBROOT/APPHOST' -Filter 'system.webServer/handlers' -Value $config; Write-Host '[OK] Handlers section unlocked (alternative method)' } catch { Write-Host '[WARNING] Could not unlock automatically' ; Write-Host 'Please unlock manually: IIS Manager ^> Server ^> Feature Delegation ^> Handler Mappings ^> Read/Write' } }"
|
||
|
|
|
||
|
|
echo.
|
||
|
|
echo [3/5] Unlocking rewrite section (if needed)...
|
||
|
|
powershell -Command "$ErrorActionPreference = 'SilentlyContinue'; Import-Module WebAdministration; try { Set-WebConfigurationProperty -PSPath 'MACHINE/WEBROOT/APPHOST' -Filter 'system.webServer/rewrite' -Name 'overrideMode' -Value 'Allow' -ErrorAction Stop; Write-Host '[OK] Rewrite section unlocked' } catch { Write-Host '[INFO] Rewrite section may already be unlocked' }"
|
||
|
|
|
||
|
|
echo.
|
||
|
|
echo [4/5] Verifying web.config...
|
||
|
|
REM Change to script directory first
|
||
|
|
cd /d "%~dp0"
|
||
|
|
if exist "dist\web.config" (
|
||
|
|
echo [OK] web.config exists
|
||
|
|
) else (
|
||
|
|
echo [WARNING] web.config not found in dist folder!
|
||
|
|
echo [INFO] Creating web.config...
|
||
|
|
|
||
|
|
REM Create web.config
|
||
|
|
(
|
||
|
|
echo ^<?xml version="1.0" encoding="UTF-8"?^>
|
||
|
|
echo ^<configuration^>
|
||
|
|
echo ^<system.webServer^>
|
||
|
|
echo ^<handlers^>
|
||
|
|
echo ^<add name="iisnode" path="server.js" verb="*" modules="iisnode" resourceType="File" /^>
|
||
|
|
echo ^</handlers^>
|
||
|
|
echo ^<rewrite^>
|
||
|
|
echo ^<rules^>
|
||
|
|
echo ^<rule name="StaticContent" stopProcessing="true"^>
|
||
|
|
echo ^<match url="^(assets^|og^|static^|src^|favicon^|robots^|sitemap^|manifest^|sw\.js^|vite\.svg^|ads\.txt^|BingSiteAuth^|google-site-verification^|browserconfig^|schema\.json^|.*\.(js^|css^|png^|jpg^|jpeg^|gif^|svg^|woff^|woff2^|ttf^|eot^|ico^|json^|xml^|webp))" /^>
|
||
|
|
echo ^<action type="None" /^>
|
||
|
|
echo ^</rule^>
|
||
|
|
echo ^<rule name="NodeApp" stopProcessing="true"^>
|
||
|
|
echo ^<match url=".*" /^>
|
||
|
|
echo ^<conditions^>
|
||
|
|
echo ^<add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" /^>
|
||
|
|
echo ^</conditions^>
|
||
|
|
echo ^<action type="Rewrite" url="server.js" /^>
|
||
|
|
echo ^</rule^>
|
||
|
|
echo ^</rules^>
|
||
|
|
echo ^</rewrite^>
|
||
|
|
echo ^<iisnode node_env="production" loggingEnabled="true" logDirectory="iisnode" /^>
|
||
|
|
echo ^</system.webServer^>
|
||
|
|
echo ^</configuration^>
|
||
|
|
) > "dist\web.config"
|
||
|
|
|
||
|
|
if exist "dist\web.config" (
|
||
|
|
echo [OK] web.config created successfully
|
||
|
|
) else (
|
||
|
|
echo [ERROR] Failed to create web.config!
|
||
|
|
echo [INFO] Please create it manually or copy from project root
|
||
|
|
pause
|
||
|
|
exit /b 1
|
||
|
|
)
|
||
|
|
)
|
||
|
|
|
||
|
|
echo.
|
||
|
|
echo [5/5] Restarting IIS...
|
||
|
|
iisreset /noforce
|
||
|
|
if %errorLevel% equ 0 (
|
||
|
|
echo [OK] IIS restarted successfully
|
||
|
|
) else (
|
||
|
|
echo [WARNING] IIS restart had issues, but continuing...
|
||
|
|
)
|
||
|
|
|
||
|
|
echo.
|
||
|
|
echo ========================================
|
||
|
|
echo FIX COMPLETE!
|
||
|
|
echo ========================================
|
||
|
|
echo.
|
||
|
|
echo Next Steps:
|
||
|
|
echo 1. Open browser: http://localhost
|
||
|
|
echo 2. If still error, check:
|
||
|
|
echo - IIS Manager ^> Server ^> Feature Delegation
|
||
|
|
echo - Find "Handler Mappings" ^> Set to "Read/Write"
|
||
|
|
echo 3. Check logs: dist\iisnode\ folder
|
||
|
|
echo.
|
||
|
|
pause
|
||
|
|
|