-
-
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.
- Loading branch information
Showing
14 changed files
with
154 additions
and
105 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,8 @@ | ||
--- | ||
'astro': minor | ||
'@astrojs/cloudflare': minor | ||
'@astrojs/netlify': minor | ||
'@astrojs/vercel': minor | ||
--- | ||
|
||
Support for 404 and 500 pages in SSR |
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
6 changes: 1 addition & 5 deletions
6
packages/astro/test/fixtures/ssr-api-route-custom-404/src/pages/404.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 |
---|---|---|
@@ -1,5 +1 @@ | ||
--- | ||
--- | ||
|
||
<h1>Something went horribly wrong!!</h1> | ||
<h1>Something went horribly wrong!</h1> |
4 changes: 1 addition & 3 deletions
4
packages/astro/test/fixtures/ssr-api-route-custom-404/src/pages/500.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 |
---|---|---|
@@ -1,3 +1 @@ | ||
--- | ||
throw new Error(`oops`); | ||
--- | ||
<h1>This is an error page</h1> |
3 changes: 3 additions & 0 deletions
3
packages/astro/test/fixtures/ssr-api-route-custom-404/src/pages/causes-error.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,3 @@ | ||
--- | ||
throw new Error(`oops`); | ||
--- |
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'; | ||
import testAdapter from './test-adapter.js'; | ||
import * as cheerio from 'cheerio'; | ||
|
||
describe('404 and 500 pages', () => { | ||
/** @type {import('./test-utils').Fixture} */ | ||
let fixture; | ||
|
||
before(async () => { | ||
fixture = await loadFixture({ | ||
root: './fixtures/ssr-api-route-custom-404/', | ||
experimental: { | ||
ssr: true, | ||
}, | ||
adapter: testAdapter(), | ||
}); | ||
await fixture.build({ }); | ||
}); | ||
|
||
it('404 page returned when a route does not match', async () => { | ||
const app = await fixture.loadTestAdapterApp(); | ||
const request = new Request('http://example.com/some/fake/route'); | ||
const response = await app.render(request); | ||
expect(response.status).to.equal(404); | ||
const html = await response.text(); | ||
const $ = cheerio.load(html); | ||
expect($('h1').text()).to.equal('Something went horribly wrong!'); | ||
}); | ||
|
||
it('500 page returned when there is an error', async () => { | ||
const app = await fixture.loadTestAdapterApp(); | ||
const request = new Request('http://example.com/causes-error'); | ||
const response = await app.render(request); | ||
expect(response.status).to.equal(500); | ||
const html = await response.text(); | ||
const $ = cheerio.load(html); | ||
expect($('h1').text()).to.equal('This is an error page'); | ||
}); | ||
}); |
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
Oops, something went wrong.