Hi All ๐
Is it possible to create a resource route which takes priority over existing files in the public folder?
The usecase I have is for an image proxy which allows resizing of images, so for example if I have an existing file /public/images/my-image.jpg and I have a resource route at routes/images.$.ts
In that loader I do my logic which reads the image as a buffer using fs from the splat path and then applies sharp transformations and caches the transformed image, so for example:
const loader = ({params, request}) => {
const imagePath = params["*"]
const readFile = async () => {
try {
const relativePath = path.resolve(
process.cwd(),
`public/images/${imagePath}`
);
debug("Trying to read image at", relativePath);
return await fs.readFileSync(relativePath);
} catch (error) {
console.error(error);
throw new Response("Image not found", { status: 404 });
}
};
return myMediaProxy(request, readFile) // applies `sharp` transformation logic and caching on the file returned from `readFile`
}
When I visit the route /public/images/my-image.jpg?width=10&height=10 it is not triggering my loader as it is using the static resource as priority.
โ Is it possible to tell remix that the loader should take priority over the existing resource?