Skip to content

Commit 1a6f9aa

Browse files
committed
Use node-fetch to make requests with different Host headers as the built-in fetch does not support modifying the Host header
1 parent ff22ee8 commit 1a6f9aa

1 file changed

Lines changed: 3 additions & 0 deletions

File tree

test/serverWithAutoCors.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import test from 'ava'
22
import listen from 'test-listen'
33
import mockedEnv from 'mocked-env'
4+
import fetch from 'node-fetch'
45

56
import server from '../src/server.js'
67
import Domain from '../src/models/Domain.js'
@@ -26,13 +27,15 @@ test('return cors headers based on fully qualifed domain names', async (t) => {
2627
ACKEE_AUTO_ORIGIN: 'true',
2728
})
2829

30+
// Use node-fetch to make requests with different Host headers as the built-in fetch does not support modifying the Host header
2931
const { headers: fqdnHeaders } = await fetch(url.href, { headers: { Host: 'fqdn.example.com' } })
3032

3133
t.is(fqdnHeaders.get('Access-Control-Allow-Origin'), 'fqdn.example.com')
3234
t.is(fqdnHeaders.get('Access-Control-Allow-Methods'), 'GET, POST, PATCH, OPTIONS')
3335
t.is(fqdnHeaders.get('Access-Control-Allow-Headers'), 'Content-Type, Authorization, Time-Zone')
3436
t.is(fqdnHeaders.get('Access-Control-Allow-Credentials'), 'true')
3537

38+
// Use node-fetch to make requests with different Host headers as the built-in fetch does not support modifying the Host header
3639
const { headers: noFqdnHeaders } = await fetch(url.href, { headers: { Host: 'No fqdn' } })
3740

3841
t.is(noFqdnHeaders.get('Access-Control-Allow-Origin'), null)

0 commit comments

Comments
 (0)