Replies: 1 comment
-
When I try using AsyncLocalStorage, asyncLocalStorage.getStore() is undefined in Route Handler
|
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
In a Next.js app with a custom server (e.g., server.ts), there is no documented or straightforward mechanism to pass values—whether value types (e.g., strings, numbers) or reference types (e.g., objects, class instances)—from the custom server to API route handlers (e.g., app/api/route.ts). As a workaround, I attempted to use globalThis to share values between the custom server and route handlers. While globalThis works for value types, it fails for reference types, as the references do not match across contexts.
Sample code:
Observe that globalA is accessible via globalThis, but reference do not maintain the same. How can I pass value A from a custom server and use it in a route handler?
Beta Was this translation helpful? Give feedback.
All reactions