Description
Plugin API route handlers can only return JSON. Whatever a handler returns is wrapped in the standard { success, data } response, so there's no way to serve an image, a file, or anything with a custom content type from a plugin route.
I ran into this building a plugin whose route returns an image: there's no way to actually send the image back to the caller. Returning a Response from the handler doesn't help either.
Expected: a plugin route should be able to return non-JSON content such as an image.
Steps to reproduce
-
Add a plugin route whose handler returns an image:
routes: {
image: {
handler: async () =>
new Response(pngBytes, { headers: { "Content-Type": "image/png" } }),
},
}
-
Call the route: GET /_emdash/api/plugins/<plugin>/image.
-
The image isn't returned
Environment
- emdash version: v0.29.0
- Node.js version: 22.16.0
- Runtime: Cloudflare Workers
Logs / error output
Description
Plugin API route handlers can only return JSON. Whatever a handler returns is wrapped in the standard
{ success, data }response, so there's no way to serve an image, a file, or anything with a custom content type from a plugin route.I ran into this building a plugin whose route returns an image: there's no way to actually send the image back to the caller. Returning a
Responsefrom the handler doesn't help either.Expected: a plugin route should be able to return non-JSON content such as an image.
Steps to reproduce
Add a plugin route whose handler returns an image:
Call the route:
GET /_emdash/api/plugins/<plugin>/image.The image isn't returned
Environment
Logs / error output