diff --git a/packages/backend/src/server/api/mastodon/index.ts b/packages/backend/src/server/api/mastodon/index.ts index aece784bc..80227094b 100644 --- a/packages/backend/src/server/api/mastodon/index.ts +++ b/packages/backend/src/server/api/mastodon/index.ts @@ -17,6 +17,7 @@ import { CacheMiddleware } from "@/server/api/mastodon/middleware/cache.js"; import { KoaBodyMiddleware } from "@/server/api/mastodon/middleware/koa-body.js"; import { NormalizeQueryMiddleware } from "@/server/api/mastodon/middleware/normalize-query.js"; import { PaginationMiddleware } from "@/server/api/mastodon/middleware/pagination.js"; +import { SetHeadersMiddleware } from "@/server/api/mastodon/middleware/set-headers.js"; export const logger = apiLogger.createSubLogger("mastodon"); export type MastoContext = RouterContext & DefaultContext; @@ -37,6 +38,7 @@ export function setupMastodonApi(router: Router): void { function setupMiddleware(router: Router): void { router.use(KoaBodyMiddleware()); + router.use(SetHeadersMiddleware); router.use(CatchErrorsMiddleware); router.use(NormalizeQueryMiddleware); router.use(PaginationMiddleware); diff --git a/packages/backend/src/server/api/mastodon/middleware/set-headers.ts b/packages/backend/src/server/api/mastodon/middleware/set-headers.ts new file mode 100644 index 000000000..0e073e673 --- /dev/null +++ b/packages/backend/src/server/api/mastodon/middleware/set-headers.ts @@ -0,0 +1,10 @@ +import { MastoContext } from "@/server/api/mastodon/index.js"; + +const headers = { + "Access-Control-Expose-Headers": "Link,Connection,Sec-Websocket-Accept,Upgrade" +}; + +export async function SetHeadersMiddleware(ctx: MastoContext, next: () => Promise) { + ctx.set(headers); + await next(); +} \ No newline at end of file