Fix asset loading in dev mode (#6466)
* Fix asset loading in dev mode * Proper windows support
This commit is contained in:
parent
401b97ad0e
commit
ec04553525
3 changed files with 15 additions and 3 deletions
5
.changeset/red-candles-retire.md
Normal file
5
.changeset/red-candles-retire.md
Normal file
|
@ -0,0 +1,5 @@
|
|||
---
|
||||
'astro': patch
|
||||
---
|
||||
|
||||
In dev, load assets relative to the root
|
|
@ -78,8 +78,8 @@ export default function assets({
|
|||
return next();
|
||||
}
|
||||
|
||||
const filePathURL = new URL(filePath, 'file:');
|
||||
const file = await fs.readFile(filePathURL.pathname);
|
||||
const filePathURL = new URL('.' + filePath, settings.config.root);
|
||||
const file = await fs.readFile(filePathURL);
|
||||
|
||||
// Get the file's metadata from the URL
|
||||
let meta = getOrigQueryParams(filePathURL.searchParams);
|
||||
|
@ -109,7 +109,7 @@ export default function assets({
|
|||
format = result.format;
|
||||
}
|
||||
|
||||
res.setHeader('Content-Type', mime.getType(fileURLToPath(url)) || `image/${format}`);
|
||||
res.setHeader('Content-Type', mime.getType(fileURLToPath(filePathURL)) || `image/${format}`);
|
||||
res.setHeader('Cache-Control', 'max-age=360000');
|
||||
|
||||
const stream = Readable.from(data);
|
||||
|
|
|
@ -72,6 +72,13 @@ describe('astro:image', () => {
|
|||
expect($img.attr('alt')).to.equal('a penguin');
|
||||
});
|
||||
|
||||
it('middleware loads the file', async() => {
|
||||
let $img = $('#local img');
|
||||
let src = $img.attr('src');
|
||||
let res = await fixture.fetch(src);
|
||||
expect(res.status).to.equal(200);
|
||||
});
|
||||
|
||||
it('errors on unsupported formats', async () => {
|
||||
logs.length = 0;
|
||||
let res = await fixture.fetch('/unsupported-format');
|
||||
|
|
Loading…
Reference in a new issue