Commit 14293ff6 authored by malkoG's avatar malkoG
Browse files

(nestjs) Add note about using express.raw() before fedifyMiddleware

- Updated integration.md and packages/nestjs/README.md with a note explaining
  why `express.raw()` must be applied before `fedifyMiddleware`.
- Clarified that Fedify requires the raw request body to perform HTTP signature
  verification for ActivityPub requests, which can break if the default body
  parser consumes or transforms the request body first.
parent e942196c
Loading
Loading
Loading
Loading
+7 −2
Original line number Diff line number Diff line
@@ -393,6 +393,7 @@ import {
  RequestMethod,
} from '@nestjs/common';
import { ConfigModule } from '@nestjs/config';
import * as express from 'express';
import { AppController } from './app.controller';
import { AppService } from './app.service';
import { DatabaseModule } from './database/database.module';
@@ -439,8 +440,12 @@ export class AppModule implements NestModule {
      },
    );

    // Apply middleware to all routes except auth endpoints
    consumer.apply(fedifyMiddleware).forRoutes({ path: '*', method: RequestMethod.ALL });
    // Fedify middleware requires the raw request body for HTTP signature verification
    // so we apply `express.raw()` before `fedifyMiddleware` to preserve the body.
    consumer.apply(
      express.raw({ type: '*/*' }),
      fedifyMiddleware
    ).forRoutes({ path: '*', method: RequestMethod.ALL });
  }
}
~~~~
+8 −2
Original line number Diff line number Diff line
@@ -71,6 +71,8 @@ import {
  NestModule,
  RequestMethod,
} from '@nestjs/common';
import { ConfigModule } from '@nestjs/config';
import * as express from 'express';
import { AppController } from './app.controller';
import { AppService } from './app.service';
import { DatabaseModule } from './database/database.module';
@@ -117,8 +119,12 @@ export class AppModule implements NestModule {
      },
    );

    // Apply middleware to all routes except auth endpoints
    consumer.apply(fedifyMiddleware)
    // Fedify middleware requires the raw request body for HTTP signature verification
    // so we apply `express.raw()` before `fedifyMiddleware` to preserve the body.
    consumer.apply(
      express.raw({ type: '*/*' }),
      fedifyMiddleware,
    ).forRoutes({ path: '*', method: RequestMethod.ALL
  }
}