mirror of
https://github.com/withastro/astro.git
synced 2025-01-20 22:12:38 -05:00
fix: handle base path with images (#12272)
This commit is contained in:
parent
c2ee963cb6
commit
388d2375b6
3 changed files with 14 additions and 0 deletions
5
.changeset/wise-parents-agree.md
Normal file
5
.changeset/wise-parents-agree.md
Normal file
|
@ -0,0 +1,5 @@
|
|||
---
|
||||
'astro': patch
|
||||
---
|
||||
|
||||
Correctly handles local images when using a base path in SSR
|
|
@ -24,6 +24,12 @@ async function loadLocalImage(src: string, url: URL) {
|
|||
fileUrl = pathToFileURL(removeQueryString(replaceFileSystemReferences(src)));
|
||||
} else {
|
||||
try {
|
||||
// If the _image segment isn't at the start of the path, we have a base
|
||||
const idx = url.pathname.indexOf('/_image');
|
||||
if (idx > 0) {
|
||||
// Remove the base path
|
||||
src = src.slice(idx);
|
||||
}
|
||||
fileUrl = new URL('.' + src, outDir);
|
||||
const filePath = fileURLToPath(fileUrl);
|
||||
|
||||
|
|
|
@ -820,6 +820,7 @@ describe('astro:image', () => {
|
|||
},
|
||||
adapter: testAdapter(),
|
||||
image: {
|
||||
endpoint: 'astro/assets/endpoint/node',
|
||||
service: testImageService(),
|
||||
},
|
||||
base: '/blog',
|
||||
|
@ -833,6 +834,8 @@ describe('astro:image', () => {
|
|||
const $ = cheerio.load(html);
|
||||
const src = $('#local img').attr('src');
|
||||
assert.equal(src.startsWith('/blog'), true);
|
||||
const img = await app.render(new Request(`https://example.com${src}`));
|
||||
assert.equal(img.status, 200);
|
||||
});
|
||||
});
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue