149 lines
5.6 KiB
Batchfile
149 lines
5.6 KiB
Batchfile
@echo off
|
|
REM IIS Setup Script for Pozo App
|
|
REM Run as Administrator
|
|
|
|
REM Change to script directory (important for npm commands)
|
|
cd /d "%~dp0"
|
|
|
|
echo ========================================
|
|
echo POZO APP - IIS SETUP SCRIPT
|
|
echo ========================================
|
|
echo.
|
|
echo Current Directory: %CD%
|
|
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/6] Checking Node.js installation...
|
|
where node >nul 2>&1
|
|
if %errorLevel% neq 0 (
|
|
echo [ERROR] Node.js is not installed or not in PATH!
|
|
echo Please install Node.js from https://nodejs.org/
|
|
pause
|
|
exit /b 1
|
|
)
|
|
node --version
|
|
echo [OK] Node.js found
|
|
echo.
|
|
|
|
echo [2/6] Checking if project is built...
|
|
if not exist "dist\server.js" (
|
|
echo [WARNING] dist\server.js not found. Building project...
|
|
call npm run build
|
|
if %errorLevel% neq 0 (
|
|
echo [ERROR] Build failed!
|
|
pause
|
|
exit /b 1
|
|
)
|
|
)
|
|
echo [OK] Project is built
|
|
echo.
|
|
|
|
echo [3/6] Checking web.config...
|
|
if not exist "dist\web.config" (
|
|
echo [WARNING] dist\web.config not found!
|
|
echo [INFO] Creating web.config file...
|
|
|
|
REM Create web.config if it doesn't exist
|
|
(
|
|
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" /^>
|
|
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!
|
|
pause
|
|
exit /b 1
|
|
)
|
|
) else (
|
|
echo [OK] web.config found
|
|
)
|
|
echo.
|
|
|
|
echo [4/6] Setting up IIS Website...
|
|
set SITE_NAME=PozoApp
|
|
set PHYSICAL_PATH=%~dp0dist
|
|
set PORT=80
|
|
|
|
REM Convert to short path format for PowerShell
|
|
for %%I in ("%PHYSICAL_PATH%") do set SHORT_PATH=%%~sI
|
|
|
|
echo Creating Application Pool: %SITE_NAME%
|
|
powershell -Command "Import-Module WebAdministration; if (!(Test-Path 'IIS:\AppPools\%SITE_NAME%')) { New-WebAppPool -Name '%SITE_NAME%'; Set-ItemProperty IIS:\AppPools\%SITE_NAME% -Name managedRuntimeVersion -Value ''; Set-ItemProperty IIS:\AppPools\%SITE_NAME% -Name enable32BitAppOnWin64 -Value $false; Write-Host '[OK] Application Pool created' } else { Write-Host '[INFO] Application Pool already exists' }"
|
|
|
|
echo Creating Website: %SITE_NAME%
|
|
powershell -Command "Import-Module WebAdministration; if (!(Test-Path 'IIS:\Sites\%SITE_NAME%')) { New-Website -Name '%SITE_NAME%' -PhysicalPath '%PHYSICAL_PATH%' -Port %PORT% -ApplicationPool '%SITE_NAME%'; Write-Host '[OK] Website created' } else { Write-Host '[INFO] Website already exists' }"
|
|
|
|
echo [OK] IIS Website setup complete
|
|
echo.
|
|
|
|
echo [5/6] Setting folder permissions...
|
|
set IDENTITY=IIS AppPool\%SITE_NAME%
|
|
echo Granting permissions to: %IDENTITY%
|
|
icacls "%PHYSICAL_PATH%" /grant "%IDENTITY%:(OI)(CI)F" /T >nul 2>&1
|
|
if %errorLevel% equ 0 (
|
|
echo [OK] Permissions set
|
|
) else (
|
|
echo [WARNING] Could not set permissions. Please set manually:
|
|
echo Folder: %PHYSICAL_PATH%
|
|
echo User: %IDENTITY%
|
|
echo Permissions: Full Control
|
|
)
|
|
echo.
|
|
|
|
echo [6/6] Starting website...
|
|
powershell -Command "$ErrorActionPreference = 'SilentlyContinue'; Import-Module WebAdministration; $siteState = Get-WebsiteState -Name '%SITE_NAME%'; $poolState = Get-WebAppPoolState -Name '%SITE_NAME%'; if ($siteState.Value -ne 'Started') { Start-Website -Name '%SITE_NAME%' -ErrorAction SilentlyContinue; if ($?) { Write-Host '[OK] Website started' } else { Write-Host '[INFO] Website may already be running or starting' } } else { Write-Host '[INFO] Website is already running' }; if ($poolState.Value -ne 'Started') { Start-WebAppPool -Name '%SITE_NAME%' -ErrorAction SilentlyContinue; if ($?) { Write-Host '[OK] Application Pool started' } else { Write-Host '[INFO] Application Pool may already be running' } } else { Write-Host '[INFO] Application Pool is already running' }"
|
|
echo.
|
|
|
|
echo ========================================
|
|
echo SETUP COMPLETE!
|
|
echo ========================================
|
|
echo.
|
|
echo Website Name: %SITE_NAME%
|
|
echo Physical Path: %PHYSICAL_PATH%
|
|
echo URL: http://localhost:%PORT%
|
|
echo.
|
|
echo Next Steps:
|
|
echo 1. Open IIS Manager
|
|
echo 2. Verify website is running
|
|
echo 3. Test in browser: http://localhost
|
|
echo 4. Check logs if there are any issues
|
|
echo.
|
|
echo Logs Location:
|
|
echo - IIS Logs: C:\inetpub\logs\LogFiles\
|
|
echo - iisnode Logs: %PHYSICAL_PATH%\iisnode\
|
|
echo.
|
|
pause
|
|
|