-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathserver.ps1
More file actions
60 lines (48 loc) · 1.92 KB
/
Copy pathserver.ps1
File metadata and controls
60 lines (48 loc) · 1.92 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
Import-Module Pode
Start-PodeServer {
Add-PodeEndpoint -Address localhost -Port 8081 -Protocol Http
Set-PodeState -Name 'AppConfig' -Value (Get-Content -Raw -Path 'config.json' | ConvertFrom-Json)
Add-PodeRoute -Method Get -Path '/config.js' -ScriptBlock {
$config = Get-PodeState -Name 'AppConfig'
$combined = @{
jiraDomain = $config.integrations.jira.domain
harvestDomain = $config.integrations.harvest.domain
projectAliases = $config.projectAliases
}
$json = $combined | ConvertTo-Json -Compress
$js = "window.AppConfig = $json;"
Write-PodeTextResponse -Value $js -ContentType 'application/javascript'
}
Add-PodeRoute -Method Get -Path '/' -ScriptBlock {
Write-PodeViewResponse -Path 'index'
}
Add-PodeRoute -Method Get -Path '/api/entries' -ScriptBlock {
$fromDate = $WebEvent.Query['fromDate']
$toDate = $WebEvent.Query['toDate']
if (-not $fromDate -or -not $toDate ) {
Set-PodeResponseStatus -Code 400
Write-PodeJsonResponse -Value @{ error = "Missing required query parameters" }
return
}
$args = @{
FromDate = $fromDate
ToDate = $toDate
}
try {
$jira = & "$PSScriptRoot/integrations/jira.ps1" @args
$harvest = & "$PSScriptRoot/integrations/harvest.ps1" @args
}
catch {
Write-Host "Error in script:"
Write-Host $_
Set-PodeResponseStatus -Code 500
Write-PodeJsonResponse -Value @{ error = "Fetch scripts failed: $($_.Exception.Message)" }
return
}
$combined = @{
jira = $jira
harvest = $harvest
}
Write-PodeJsonResponse -Value $combined
}
}