You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Hi there. I'm looking at a project that uses a custom server (boo! hiss) and I'm exploring migrating to Next's middleware instead.
I've found that I can do most things (header mangling, redirects, /api-short-circuiting nextUrl.pathname behavior), but an obvious case that I would have expected to work out of the box is....writing to a file. Let's say I wanted to return the (Next)Response generated in the middleware interaction:
OK, I get that, but a middleware isn't exactly a client-side thing. At the basis, I would expect that a middleware provides me access to the request, the response, and whatever other APIs I choose to use. Consider a canonical middleware use case: logging request paths and responses. If I don't have access to fs, net.Socket, etc. , how could that ever be implemented?
Searching the vercel/examples, there was no example. Anyone have a pattern on this?
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
-
Hi there. I'm looking at a project that uses a custom server (boo! hiss) and I'm exploring migrating to Next's middleware instead.
I've found that I can do most things (header mangling, redirects,
/api
-short-circuitingnextUrl.pathname
behavior), but an obvious case that I would have expected to work out of the box is....writing to a file. Let's say I wanted to return the (Next
)Response
generated in the middleware interaction:Error: Module not found: Can't resolve 'fs'
I think I understand what's going on here, 'fs' is not available to client-side code.
-- https://nextjs.org/docs/api-reference/edge-runtime#unsupported-apis
OK, I get that, but a middleware isn't exactly a client-side thing. At the basis, I would expect that a middleware provides me access to the request, the response, and whatever other APIs I choose to use. Consider a canonical middleware use case: logging request paths and responses. If I don't have access to
fs
,net.Socket
, etc. , how could that ever be implemented?Searching the vercel/examples, there was no example. Anyone have a pattern on this?
Beta Was this translation helpful? Give feedback.
All reactions