77 lines
2.9 KiB
Batchfile
77 lines
2.9 KiB
Batchfile
@echo off
|
|
setlocal
|
|
|
|
if "%~1"=="" goto usage
|
|
|
|
set "MODE=%~1"
|
|
set "CADDYFILE=C:\caddy\Caddyfile"
|
|
set "DOMAIN=www.clinicaveterinariaformiginese.it"
|
|
set "LIVE_ROOT=C:\deploy\clinica_veterinaria_formiginese\clinica-app\dist\public"
|
|
set "COMING_SOON_ROOT=C:\deploy\clinica_veterinaria_formiginese\coming-soon"
|
|
|
|
if /I "%MODE%"=="true" goto publish_live
|
|
if /I "%MODE%"=="false" goto publish_coming_soon
|
|
goto usage
|
|
|
|
:publish_live
|
|
echo Modalita selezionata: DEMO PUBBLICATA
|
|
powershell -NoProfile -ExecutionPolicy Bypass -Command ^
|
|
"$path = '%CADDYFILE%';" ^
|
|
"$content = Get-Content -Raw $path;" ^
|
|
"$pattern = '(?ms)^%DOMAIN% \{[\s\S]*?^\}';" ^
|
|
"$replacement = '%DOMAIN% {' + [Environment]::NewLine + ' route {' + [Environment]::NewLine + ' handle /api/* {' + [Environment]::NewLine + ' reverse_proxy 127.0.0.1:8000' + [Environment]::NewLine + ' }' + [Environment]::NewLine + ' handle {' + [Environment]::NewLine + ' root * %LIVE_ROOT%' + [Environment]::NewLine + ' try_files {path} /index.html' + [Environment]::NewLine + ' file_server' + [Environment]::NewLine + ' }' + [Environment]::NewLine + ' }' + [Environment]::NewLine + '}';" ^
|
|
"$updated = [regex]::Replace($content, $pattern, $replacement);" ^
|
|
"Set-Content -Path $path -Value $updated -Encoding UTF8;"
|
|
if errorlevel 1 (
|
|
echo ERRORE: aggiornamento del Caddyfile non riuscito.
|
|
exit /b 1
|
|
)
|
|
goto reload_caddy
|
|
|
|
:publish_coming_soon
|
|
echo Modalita selezionata: COMING SOON
|
|
powershell -NoProfile -ExecutionPolicy Bypass -Command ^
|
|
"$path = '%CADDYFILE%';" ^
|
|
"$content = Get-Content -Raw $path;" ^
|
|
"$pattern = '(?ms)^%DOMAIN% \{[\s\S]*?^\}';" ^
|
|
"$replacement = '%DOMAIN% {' + [Environment]::NewLine + ' route {' + [Environment]::NewLine + ' handle /api/* {' + [Environment]::NewLine + ' reverse_proxy 127.0.0.1:8000' + [Environment]::NewLine + ' }' + [Environment]::NewLine + ' handle {' + [Environment]::NewLine + ' root * %COMING_SOON_ROOT%' + [Environment]::NewLine + ' file_server' + [Environment]::NewLine + ' }' + [Environment]::NewLine + ' }' + [Environment]::NewLine + '}';" ^
|
|
"$updated = [regex]::Replace($content, $pattern, $replacement);" ^
|
|
"Set-Content -Path $path -Value $updated -Encoding UTF8;"
|
|
if errorlevel 1 (
|
|
echo ERRORE: aggiornamento del Caddyfile non riuscito.
|
|
exit /b 1
|
|
)
|
|
|
|
:reload_caddy
|
|
echo.
|
|
echo Ricarico Caddy...
|
|
C:\caddy\caddy.exe validate --config "%CADDYFILE%" --adapter caddyfile
|
|
if errorlevel 1 (
|
|
echo ERRORE: Caddyfile non valido. Nessun reload eseguito.
|
|
exit /b 1
|
|
)
|
|
|
|
C:\caddy\caddy.exe reload --config "%CADDYFILE%" --adapter caddyfile
|
|
if errorlevel 1 (
|
|
echo ERRORE: reload di Caddy non riuscito.
|
|
exit /b 1
|
|
)
|
|
|
|
echo.
|
|
if /I "%MODE%"=="true" (
|
|
echo Demo online: https://%DOMAIN%
|
|
) else (
|
|
echo Coming soon online: https://%DOMAIN%
|
|
)
|
|
echo Operazione completata.
|
|
exit /b 0
|
|
|
|
:usage
|
|
echo Uso:
|
|
echo publish_demo.bat true
|
|
echo publish_demo.bat false
|
|
echo.
|
|
echo true = pubblica la demo completa
|
|
echo false = mostra la pagina coming soon
|
|
exit /b 1
|