Skip to content

Plugin API routes can't return non-JSON responses (e.g. images) #2110

Description

@rhaegalll

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

  1. Add a plugin route whose handler returns an image:

    routes: {
      image: {
        handler: async () =>
          new Response(pngBytes, { headers: { "Content-Type": "image/png" } }),
      },
    }
  2. Call the route: GET /_emdash/api/plugins/<plugin>/image.

  3. The image isn't returned

Environment

  • emdash version: v0.29.0
  • Node.js version: 22.16.0
  • Runtime: Cloudflare Workers

Logs / error output

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions