Skip to content

Commit 155971f

Browse files
fix: application url
1 parent 2f0b8e0 commit 155971f

1 file changed

Lines changed: 50 additions & 3 deletions

File tree

setup/setup.ps1

Lines changed: 50 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -150,6 +150,33 @@ $appName = Get-UserInput -prompt "Enter your application name (this will be disp
150150
# Get application URL
151151
$appUrl = Get-UserInput -prompt "Enter your application URL" -default $defaultSettings.Application.Default.Url -validationType 'url'
152152

153+
# Function to generate subdomain URLs
154+
function Get-SubdomainUrl {
155+
param (
156+
[string]$baseUrl,
157+
[string]$subdomain
158+
)
159+
160+
# Parse the URL to extract protocol and domain
161+
if ($baseUrl -match '^(https?://)([^/]+)(.*)$') {
162+
$protocol = $matches[1]
163+
$domain = $matches[2]
164+
$path = $matches[3]
165+
166+
# Add subdomain
167+
$newDomain = "$subdomain.$domain"
168+
169+
return "$protocol$newDomain$path"
170+
}
171+
172+
return $baseUrl
173+
}
174+
175+
# Generate URLs for different applications
176+
$webAppUrl = $appUrl
177+
$adminPanelUrl = Get-SubdomainUrl -baseUrl $appUrl -subdomain "admin"
178+
$apiUrl = Get-SubdomainUrl -baseUrl $appUrl -subdomain "api"
179+
153180
# Get admin user details
154181
$adminMobile = Get-UserInput -prompt "Enter admin user mobile number" -default $defaultSettings.Identity.AdminUser.Mobile -validationType 'mobile'
155182
$adminEmail = Get-UserInput -prompt "Enter admin user email" -default $defaultSettings.Identity.AdminUser.Email -validationType 'email'
@@ -169,10 +196,26 @@ try {
169196
Get-ChildItem -Recurse -Filter "appsettings.json" | ForEach-Object {
170197
$content = Get-Content $_.FullName -Raw
171198

199+
# Determine which URL to use based on the file path
200+
$currentUrl = $webAppUrl # Default to web app URL
201+
$currentIssuer = $apiUrl # Default issuer for JWT
202+
203+
if ($_.FullName -like "*AdminPanel*") {
204+
$currentUrl = $adminPanelUrl
205+
} elseif ($_.FullName -like "*Api*") {
206+
$currentUrl = $apiUrl
207+
$currentIssuer = $apiUrl
208+
}
209+
172210
# Update values using string replacement to preserve JSON structure
173211
# Only replace the application name in specific places
174212
$content = $content -replace '"Application":\s*{\s*"Default":\s*{\s*"Name":\s*"[^"]*"', "`"Application`": { `"Default`": { `"Name`": `"$appName`""
175-
$content = $content -replace '"Url":\s*"[^"]*"', "`"Url`": `"$appUrl`""
213+
$content = $content -replace '"Url":\s*"[^"]*"', "`"Url`": `"$currentUrl`""
214+
215+
# Update JWT Issuer for API project
216+
if ($_.FullName -like "*Api*") {
217+
$content = $content -replace '"Issuer":\s*"[^"]*"', "`"Issuer`": `"$currentIssuer`""
218+
}
176219

177220
# Preserve suffixes when replacing CanBeYours
178221
$content = $content -replace '"CookieName":\s*"CanBeYours\.([^"]*)"', "`"CookieName`": `"$solutionName.`$1`""
@@ -295,8 +338,12 @@ Write-Host "Solution Name: " -NoNewline
295338
Write-Host $solutionName -ForegroundColor Yellow
296339
Write-Host "Application Name: " -NoNewline
297340
Write-Host $appName -ForegroundColor Yellow
298-
Write-Host "Application URL: " -NoNewline
299-
Write-Host $appUrl -ForegroundColor Yellow
341+
Write-Host "Web Application URL: " -NoNewline
342+
Write-Host $webAppUrl -ForegroundColor Yellow
343+
Write-Host "Admin Panel URL: " -NoNewline
344+
Write-Host $adminPanelUrl -ForegroundColor Yellow
345+
Write-Host "API URL: " -NoNewline
346+
Write-Host $apiUrl -ForegroundColor Yellow
300347
Write-Host "Admin Email: " -NoNewline
301348
Write-Host $adminEmail -ForegroundColor Yellow
302349

0 commit comments

Comments
 (0)