diff options
| author | Hazelnoot <acomputerdog@gmail.com> | 2025-06-13 23:18:06 -0400 |
|---|---|---|
| committer | Hazelnoot <acomputerdog@gmail.com> | 2025-06-13 23:18:06 -0400 |
| commit | b44abe0eaaeb85111d94046b182e03e67993a101 (patch) | |
| tree | 0d84360a061434aedcdb41db3076764bb8292ce4 /packages/backend/src/server/api | |
| parent | merge: Fix uncaught exception hooks and add more shutdown logging. (!1111) (diff) | |
| download | sharkey-b44abe0eaaeb85111d94046b182e03e67993a101.tar.gz sharkey-b44abe0eaaeb85111d94046b182e03e67993a101.tar.bz2 sharkey-b44abe0eaaeb85111d94046b182e03e67993a101.zip | |
set X-Robots-Tag to disable indexing API endpoints
Diffstat (limited to 'packages/backend/src/server/api')
| -rw-r--r-- | packages/backend/src/server/api/ApiCallService.ts | 4 | ||||
| -rw-r--r-- | packages/backend/src/server/api/mastodon/MastodonApiServerService.ts | 7 |
2 files changed, 11 insertions, 0 deletions
diff --git a/packages/backend/src/server/api/ApiCallService.ts b/packages/backend/src/server/api/ApiCallService.ts index 6d6c86bb82..66d968224a 100644 --- a/packages/backend/src/server/api/ApiCallService.ts +++ b/packages/backend/src/server/api/ApiCallService.ts @@ -148,6 +148,10 @@ export class ApiCallService implements OnApplicationShutdown { request: FastifyRequest<{ Body: Record<string, unknown> | undefined, Querystring: Record<string, unknown> }>, reply: FastifyReply, ): void { + // Tell crawlers not to index API endpoints. + // https://developers.google.com/search/docs/crawling-indexing/block-indexing + reply.header('X-Robots-Tag', 'noindex'); + const body = request.method === 'GET' ? request.query : request.body; diff --git a/packages/backend/src/server/api/mastodon/MastodonApiServerService.ts b/packages/backend/src/server/api/mastodon/MastodonApiServerService.ts index 74fd9d7d59..072dacf708 100644 --- a/packages/backend/src/server/api/mastodon/MastodonApiServerService.ts +++ b/packages/backend/src/server/api/mastodon/MastodonApiServerService.ts @@ -71,6 +71,13 @@ export class MastodonApiServerService { done(); }); + // Tell crawlers not to index API endpoints. + // https://developers.google.com/search/docs/crawling-indexing/block-indexing + fastify.addHook('onRequest', (request, reply, done) => { + reply.header('X-Robots-Tag', 'noindex'); + done(); + }); + // External endpoints this.apiAccountMastodon.register(fastify); this.apiAppsMastodon.register(fastify); |