-
-
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.
fix: better dev routing with base using middleware
- Loading branch information
1 parent
6809a0d
commit c2bdcd2
Showing
8 changed files
with
157 additions
and
42 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': patch | ||
--- | ||
|
||
Use a base middleware for better base path handling in dev. |
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,8 @@ | ||
{ | ||
"name": "@test/public-base-404", | ||
"version": "0.0.0", | ||
"private": true, | ||
"dependencies": { | ||
"astro": "workspace:*" | ||
} | ||
} |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
8 changes: 8 additions & 0 deletions
8
packages/astro/test/fixtures/public-base-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 |
---|---|---|
@@ -0,0 +1,8 @@ | ||
<html lang="en"> | ||
<head> | ||
<title>Not Found</title> | ||
</head> | ||
<body> | ||
<h1>404</h1> | ||
</body> | ||
</html> |
8 changes: 8 additions & 0 deletions
8
packages/astro/test/fixtures/public-base-404/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 lang="en"> | ||
<head> | ||
<title>This Site</title> | ||
</head> | ||
<body> | ||
<img src="/twitter.png" /> | ||
</body> | ||
</html> |
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,64 @@ | ||
import { expect } from 'chai'; | ||
import * as cheerio from 'cheerio'; | ||
import { loadFixture } from './test-utils.js'; | ||
|
||
describe('Public dev with base', () => { | ||
/** @type {import('./test-utils').Fixture} */ | ||
let fixture; | ||
/** @type {import('./test-utils').DevServer} */ | ||
let devServer; | ||
let $; | ||
|
||
before(async () => { | ||
fixture = await loadFixture({ | ||
root: './fixtures/public-base-404/', | ||
site: 'http://example.com/', | ||
base: '/blog' | ||
}); | ||
devServer = await fixture.startDevServer(); | ||
}); | ||
|
||
it('200 when loading /@vite/client', async () => { | ||
const response = await fixture.fetch('/@vite/client', { | ||
redirect: 'manual' | ||
}); | ||
expect(response.status).to.equal(200); | ||
const content = await response.text() | ||
expect(content).to.contain('vite') | ||
}); | ||
|
||
it('200 when loading /blog/twitter.png', async () => { | ||
const response = await fixture.fetch('/blog/twitter.png', { | ||
redirect: 'manual' | ||
}); | ||
expect(response.status).to.equal(200); | ||
}); | ||
|
||
it('custom 404 page when loading /blog/blog/', async () => { | ||
const response = await fixture.fetch('/blog/blog/'); | ||
const html = await response.text() | ||
$ = cheerio.load(html); | ||
expect($('h1').text()).to.equal('404'); | ||
}); | ||
|
||
it('default 404 hint page when loading /', async () => { | ||
const response = await fixture.fetch('/'); | ||
expect(response.status).to.equal(404); | ||
const html = await response.text() | ||
$ = cheerio.load(html); | ||
expect($('a').first().text()).to.equal('/blog/'); | ||
}); | ||
|
||
it('default 404 page when loading /none/', async () => { | ||
const response = await fixture.fetch('/none/', { | ||
headers: { | ||
accept: 'text/html,*/*' | ||
} | ||
}); | ||
expect(response.status).to.equal(404); | ||
const html = await response.text() | ||
$ = cheerio.load(html); | ||
expect($('h1').text()).to.equal('404: Not found'); | ||
expect($('pre').text()).to.equal('Path: /none/'); | ||
}); | ||
}); |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.