Skip to content

Commit

Permalink
Merge pull request #40 from dddwa/fix/anouncement-cors
Browse files Browse the repository at this point in the history
Fixing announcements, two instances
  • Loading branch information
JakeGinnivan authored Nov 16, 2024
2 parents b5b256b + a34bb39 commit 60188d5
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 21 deletions.
2 changes: 1 addition & 1 deletion infra/app/ddd.bicep
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,7 @@ resource app 'Microsoft.App/containerApps@2024-03-01' = {
}
]
scale: {
minReplicas: 1
minReplicas: 2
maxReplicas: 10
}
}
Expand Down
52 changes: 32 additions & 20 deletions website/app/routes/app-announcements.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import { trace } from '@opentelemetry/api'
import { json } from '@remix-run/server-runtime'
import { CACHE_CONTROL } from '~/lib/http.server'
import { resolveError } from '~/lib/resolve-error'

export type GoogleFormUpdates = {
Timestamp: string
Expand All @@ -14,29 +16,39 @@ export async function loader() {
return new Response(JSON.stringify({ message: 'No Google Forms API key or form ID' }), { status: 404 })
}

const BASE_URL = `https://www.googleapis.com/drive/v3/files/${fileId}?alt=media&key=${apiKey}`
try {
const BASE_URL = `https://www.googleapis.com/drive/v3/files/${fileId}?alt=media&key=${apiKey}`

const response = await fetch(BASE_URL, {
headers: {
'Content-Type': 'application/json',
Accept: 'application/json',
},
})
const response = await fetch(BASE_URL, {
headers: {
'Content-Type': 'application/json',
Accept: 'application/json',
},
})

const responseData = (await response.json()) as GoogleFormUpdates[]

const responseData = (await response.json()) as GoogleFormUpdates[]
const announcementData = responseData
.map((row) => {
return { createdTime: row.Timestamp, update: row.Message }
})
.sort((a, b) => {
return new Date(b.createdTime).getTime() - new Date(a.createdTime).getTime()
})

const announcementData = responseData
.map((row) => {
return { createdTime: row.Timestamp, update: row.Message }
return json(announcementData, {
headers: {
'Cache-Control': CACHE_CONTROL.announce,
'Access-Control-Allow-Origin': '*',
},
})
.sort((a, b) => {
return new Date(b.createdTime).getTime() - new Date(a.createdTime).getTime()
} catch (err) {
trace.getActiveSpan()?.recordException(resolveError(err))
return json([], {
headers: {
'Cache-Control': CACHE_CONTROL.announce,
'Access-Control-Allow-Origin': '*',
},
})

return json(announcementData, {
headers: {
'Cache-Control': CACHE_CONTROL.announce,
'Access-Control-Allow-Origin': '*',
},
})
}
}

0 comments on commit 60188d5

Please sign in to comment.