Skip to content

Commit cd1e5c4

Browse files
committed
feat(cors): allow chancencampus
1 parent 81995be commit cd1e5c4

File tree

2 files changed

+13
-5
lines changed

2 files changed

+13
-5
lines changed

__tests__/api.ts

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,7 @@ describe('setting of response header `Access-Control-Allow-Origin`', () => {
7979
'http://localhost:3000',
8080
'http://localhost:3001',
8181
'https://frontend-7md9ymhyw-serlo.vercel.app',
82+
'https://chancencampus.org',
8283
]
8384

8485
describe('when we are in the staging environment, the same value is sent back in `Access-Control-Allow-Origin`', () => {
@@ -94,7 +95,7 @@ describe('setting of response header `Access-Control-Allow-Origin`', () => {
9495
})
9596
})
9697

97-
describe('when we are in the production environment, the current domain is sent back in `Access-Control-Allow-Origin`', () => {
98+
describe('when we are in the production environment, the current domain or chancencampus.org is sent back in `Access-Control-Allow-Origin`', () => {
9899
test.each(domains)('when `Origin` is `%s`', async (origin) => {
99100
const env = currentTestEnvironmentWhen(
100101
(conf) => conf.ENVIRONMENT === 'production',
@@ -103,9 +104,15 @@ describe('setting of response header `Access-Control-Allow-Origin`', () => {
103104

104105
const response = await fetchApi({ headers: { Origin: origin } }, env)
105106

106-
expect(response.headers.get('Access-Control-Allow-Origin')).toBe(
107-
`https://${env.getDomain()}`,
108-
)
107+
if (origin == 'https://chancencampus.org') {
108+
expect(response.headers.get('Access-Control-Allow-Origin')).toBe(
109+
'https://chancencampus.org',
110+
)
111+
} else {
112+
expect(response.headers.get('Access-Control-Allow-Origin')).toBe(
113+
`https://${env.getDomain()}`,
114+
)
115+
}
109116
})
110117
})
111118
})

src/api.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,8 @@ function getAllowedOrigin(requestOrigin: string | null, env: CFEnvironment) {
7373
url.port === '8000' ||
7474
url.port === '8080')) ||
7575
url.hostname.includes('-serlo.vercel.app'))) ||
76-
url.hostname.includes('.adornis.de')
76+
url.hostname.includes('.adornis.de') ||
77+
url.domain === 'chancencampus.org'
7778
) {
7879
return requestOrigin
7980
}

0 commit comments

Comments
 (0)