Open-source and local-first Slack and Notion alternative that puts you in control of your data
TypeScript chatchat-applicationcrdteditorelectronknowledge-baselocal-firstnotionnotion-alternativerealtime-collaborationself-hostedslacksqliteteam-collaborationwikiyjs
Remove content type parsers to handle empty JSON body errors (#289)
Hakan Shehud4c1af8ce191
diff --git a/apps/server/src/api/client/routes/accounts/account-sync.ts b/apps/server/src/api/client/routes/accounts/account-sync.tsindex df16c9c0..29a79445 100644--- a/apps/server/src/api/client/routes/accounts/account-sync.ts+++ b/apps/server/src/api/client/routes/accounts/account-sync.ts@@ -16,6 +16,14 @@ export const accountSyncRoute: FastifyPluginCallbackZod = (_,done) => {+ // This endpoint doesn't expect a body, so we remove all content type parsers+ // to prevent Fastify from throwing FST_ERR_CTP_EMPTY_JSON_BODY when browsers+ // send Content-Type: application/json with an empty body+ instance.removeAllContentTypeParsers();+ instance.addContentTypeParser('*', (_req, _payload, done) => {+ done(null, undefined);+ });+instance.route({method: 'POST',url: '/sync',diff --git a/apps/server/src/api/client/routes/sockets/socket-init.ts b/apps/server/src/api/client/routes/sockets/socket-init.tsindex 2f5bdf90..381cdd2b 100644--- a/apps/server/src/api/client/routes/sockets/socket-init.ts+++ b/apps/server/src/api/client/routes/sockets/socket-init.ts@@ -7,6 +7,14 @@ import { socketService } from '@colanode/server/services/socket-service';export const socketInitHandler: FastifyPluginCallback = (instance, _, done) => {instance.register(accountAuthenticator);+ // This endpoint doesn't expect a body, so we remove all content type parsers+ // to prevent Fastify from throwing FST_ERR_CTP_EMPTY_JSON_BODY when browsers+ // send Content-Type: application/json with an empty body+ instance.removeAllContentTypeParsers();+ instance.addContentTypeParser('*', (_req, _payload, done) => {+ done(null, undefined);+ });+instance.route({method: 'POST',url: '/',