Skip to content

Commit 014be63

Browse files
committed
Add configuration files for static web app with global headers
1 parent faf81b1 commit 014be63

File tree

4 files changed

+79
-0
lines changed

4 files changed

+79
-0
lines changed

.github/workflows/main.yml

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -670,6 +670,67 @@ jobs:
670670
with:
671671
name: AzureDevOpsMigrationTools-Site2
672672
path: ./_site2
673+
674+
- name: Merge Configuration Files
675+
run: |
676+
# Find all files matching the pattern in a safe way
677+
$files = Get-ChildItem -Path "." -Recurse -Filter "staticwebapp.*.json" -ErrorAction Stop
678+
679+
if ($files.Count -eq 0) {
680+
Write-Host "No files matching the pattern 'staticwebapp.*.json' were found."
681+
exit 1
682+
}
683+
684+
# Output each file's full name (for verification/debugging purposes)
685+
$files | ForEach-Object {
686+
Write-Host "Found file: $($_.FullName)"
687+
}
688+
689+
# Paths to main and environment-specific config files
690+
$rootConfig = "./_site/staticwebapp.config.json"
691+
$environmentConfig = "./_site/staticwebapp.config.${{ (needs.Setup.outputs.nkdAgility_AzureSitesEnvironment) }}.json"
692+
# $routesConfig = "./_site/staticwebapp.config.routes.json"
693+
694+
# Check if both target files exist
695+
if ((Test-Path -Path $rootConfig -ErrorAction Stop) -and (Test-Path -Path $environmentConfig -ErrorAction Stop)) {
696+
try {
697+
# Run jq to merge files and capture the output
698+
$mergedContent = & jq -s 'reduce .[] as $item ({}; . * $item)' $rootConfig $environmentConfig # $routesConfig
699+
700+
if ($mergedContent -ne "") {
701+
# Write the merged content to the output file
702+
$mergedContent | Set-Content -Path "./staticwebapp.config.json"
703+
Write-Host "Merged JSON files successfully."
704+
}
705+
else {
706+
Write-Host "jq command produced empty output. Check JSON structures in input files."
707+
exit 1
708+
}
709+
}
710+
catch {
711+
Write-Host "Error merging JSON files with jq: $_"
712+
exit 1
713+
}
714+
}
715+
else {
716+
Write-Host "One or both of the specified config files were not found:"
717+
if (!(Test-Path -Path $rootConfig)) { Write-Host " - $rootConfig not found" }
718+
if (!(Test-Path -Path $environmentConfig)) { Write-Host " - $environmentConfig not found" }
719+
exit 1
720+
}
721+
722+
# Verify and read the merged file content
723+
try {
724+
$content = Get-Content -Path "./staticwebapp.config.json" -ErrorAction Stop
725+
Write-Host "Content of merged config file:"
726+
Write-Output $content
727+
}
728+
catch {
729+
Write-Host "Error reading the merged config file: $_"
730+
exit 1
731+
}
732+
733+
673734
- name: "Find files"
674735
shell: pwsh
675736
run: |
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
{
2+
}
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
{
2+
"globalHeaders": {
3+
"Access-Control-Allow-Origin": "https://devopsmigration.io",
4+
"Access-Control-Allow-Methods": "GET, OPTIONS",
5+
"Access-Control-Allow-Headers": "Content-Type",
6+
"Vary": "Origin"
7+
}
8+
}
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
{
2+
"globalHeaders": {
3+
"Access-Control-Allow-Origin": "https://blue-river-093197403-preview.westeurope.5.azurestaticapps.net",
4+
"Access-Control-Allow-Methods": "GET, OPTIONS",
5+
"Access-Control-Allow-Headers": "Content-Type",
6+
"Vary": "Origin"
7+
}
8+
}

0 commit comments

Comments
 (0)