Skip to content

Middleware not working when custom server uses app.render() #44199

Closed as not planned
@Tasiobg

Description

Verify canary release

  • I verified that the issue exists in the latest Next.js canary release

Provide environment information

Operating System:
  Platform: darwin
  Arch: x64
  Version: Darwin Kernel Version 21.6.0: Thu Sep 29 20:12:57 PDT 2022; root:xnu-8020.240.7~1/RELEASE_X86_64
Binaries:
  Node: 16.19.0
  npm: 8.19.3
  Yarn: 1.22.19
  pnpm: N/A
Relevant packages:
  next: 13.0.8-canary.1
  eslint-config-next: 13.0.7
  react: 18.2.0
  react-dom: 18.2.0

Which area(s) of Next.js are affected? (leave empty if unsure)

Middleware / Edge (API routes, runtime)

Link to the code that reproduces this issue

https://github.com/Tasiobg/next-app-issue

To Reproduce

The example above is based in the default "next-app", I only added 2 files
https://github.com/Tasiobg/next-app-issue/blob/main/server.js
and
https://github.com/Tasiobg/next-app-issue/blob/main/middleware.ts

In order to reproduce the issue swap the commented line between 16 and 17 https://github.com/Tasiobg/next-app-issue/blob/main/server.js#L16-L17. "handle" works as expected but "app.render" doesn't seem to trigger the midleware.

Please make sure you are running the custom server node server.js instead of the default next dev server

Describe the Bug

Requests doesn't seem to trigger the middleware when using a custom server with app.render but works fine when using handle().

Expected Behavior

Middleware to work when using "app.render" or some documentation inside custom server and middleware docs to warn about that behaviour.

Which browser are you using? (if relevant)

No response

How are you deploying your application? (if relevant)

node server.js

Metadata

Assignees

No one assigned

    Labels

    bugIssue was opened via the bug report template.staleThe issue has not seen recent activity.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions