Skip to content

Commit

Permalink
fix: _image endpoint returning a 404 for local images (#8828)
Browse files Browse the repository at this point in the history
  • Loading branch information
Rishi Raj Jain authored Oct 17, 2023
1 parent 3468c06 commit 11f45b9
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
5 changes: 5 additions & 0 deletions .changeset/heavy-lies-cover.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'astro': patch
---

fix file system path references
7 changes: 6 additions & 1 deletion packages/astro/src/assets/endpoint/node.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,20 @@
import { isRemotePath, removeQueryString } from '@astrojs/internal-helpers/path';
import { readFile } from 'fs/promises';
import mime from 'mime/lite.js';
import os from 'os';
import type { APIRoute } from '../../@types/astro.js';
import { getConfiguredImageService, isRemoteAllowed } from '../internal.js';
import { etag } from '../utils/etag.js';
// @ts-expect-error
import { assetsDir, imageConfig } from 'astro:assets';

function replaceFileSystemReferences(src: string) {
return os.platform().includes('win32') ? src.replace(/^\/@fs\//, '') : src.replace(/^\/@fs/, '');
}

async function loadLocalImage(src: string, url: URL) {
const filePath = import.meta.env.DEV
? removeQueryString(src.slice('/@fs'.length))
? removeQueryString(replaceFileSystemReferences(src))
: new URL('.' + src, assetsDir);
let buffer: Buffer | undefined = undefined;

Expand Down

0 comments on commit 11f45b9

Please sign in to comment.