next.ts 638 B

123456789101112131415161718192021222324252627282930313233
  1. import type { NextServer, RequestHandler } from 'next/dist/server/next';
  2. import type { IncomingMessage } from 'http';
  3. type Crowi = {
  4. nextApp: NextServer;
  5. };
  6. type CrowiReq = IncomingMessage & {
  7. crowi: Crowi;
  8. };
  9. type NextDelegatorResult = {
  10. delegateToNext: RequestHandler;
  11. };
  12. const delegator = (crowi: Crowi): NextDelegatorResult => {
  13. const { nextApp } = crowi;
  14. const handle = nextApp.getRequestHandler();
  15. const delegateToNext: RequestHandler = (
  16. req: CrowiReq,
  17. res,
  18. ): Promise<void> => {
  19. req.crowi = crowi;
  20. return handle(req, res);
  21. };
  22. return {
  23. delegateToNext,
  24. };
  25. };
  26. export default delegator;