-
-
Notifications
You must be signed in to change notification settings - Fork 2.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
With this new `server.headers` option, the users can specify custom headers for `astro dev` and `astro preview` servers. This is useful when they want to build a website requiring specific response headers such as `Cross-Origin-Opener-Policy`.
- Loading branch information
Showing
13 changed files
with
157 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
'astro': minor | ||
--- | ||
|
||
Add `server.headers` option |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
import { expect } from 'chai'; | ||
import { loadFixture } from './test-utils.js'; | ||
|
||
describe('Astro dev headers', () => { | ||
let fixture; | ||
let devServer; | ||
const headers = { | ||
'x-astro': 'test', | ||
}; | ||
|
||
before(async () => { | ||
fixture = await loadFixture({ | ||
root: './fixtures/astro-dev-headers/', | ||
server: { | ||
headers, | ||
}, | ||
}); | ||
await fixture.build(); | ||
devServer = await fixture.startDevServer(); | ||
}); | ||
|
||
after(async () => { | ||
await devServer.stop(); | ||
}); | ||
|
||
describe('dev', () => { | ||
it('returns custom headers for valid URLs', async () => { | ||
const result = await fixture.fetch('/'); | ||
expect(result.status).to.equal(200); | ||
expect(Object.fromEntries(result.headers)).to.include(headers); | ||
}); | ||
|
||
it('does not return custom headers for invalid URLs', async () => { | ||
const result = await fixture.fetch('/bad-url'); | ||
expect(result.status).to.equal(404); | ||
expect(Object.fromEntries(result.headers)).not.to.include(headers); | ||
}); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
import { expect } from 'chai'; | ||
import { loadFixture } from './test-utils.js'; | ||
|
||
describe('Astro preview headers', () => { | ||
let fixture; | ||
let previewServer; | ||
const headers = { | ||
astro: 'test', | ||
}; | ||
|
||
before(async () => { | ||
fixture = await loadFixture({ | ||
root: './fixtures/astro-preview-headers/', | ||
server: { | ||
headers, | ||
}, | ||
}); | ||
await fixture.build(); | ||
previewServer = await fixture.preview(); | ||
}); | ||
|
||
// important: close preview server (free up port and connection) | ||
after(async () => { | ||
await previewServer.stop(); | ||
}); | ||
|
||
describe('preview', () => { | ||
it('returns custom headers for valid URLs', async () => { | ||
const result = await fixture.fetch('/'); | ||
expect(result.status).to.equal(200); | ||
expect(Object.fromEntries(result.headers)).to.include(headers); | ||
}); | ||
|
||
it('does not return custom headers for invalid URLs', async () => { | ||
const result = await fixture.fetch('/bad-url'); | ||
expect(result.status).to.equal(404); | ||
expect(Object.fromEntries(result.headers)).not.to.include(headers); | ||
}); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
{ | ||
"name": "@test/astro-dev-headers", | ||
"version": "0.0.0", | ||
"private": true, | ||
"dependencies": { | ||
"astro": "workspace:*" | ||
} | ||
} |
8 changes: 8 additions & 0 deletions
8
packages/astro/test/fixtures/astro-dev-headers/src/pages/index.astro
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
<html> | ||
<head> | ||
</head> | ||
<body> | ||
<h1>Hello world!</h1> | ||
</body> | ||
</html> | ||
|
8 changes: 8 additions & 0 deletions
8
packages/astro/test/fixtures/astro-preview-headers/package.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
{ | ||
"name": "@test/astro-preview-headers", | ||
"version": "0.0.0", | ||
"private": true, | ||
"dependencies": { | ||
"astro": "workspace:*" | ||
} | ||
} |
8 changes: 8 additions & 0 deletions
8
packages/astro/test/fixtures/astro-preview-headers/src/pages/index.astro
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
<html> | ||
<head> | ||
</head> | ||
<body> | ||
<h1>Hello world!</h1> | ||
</body> | ||
</html> | ||
|
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.