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
And API handlers to set and then get the global message getMessage.js
import Storage from '../../service/memoryStorage';
export default function handler(req, res) {
let message = Storage.getMessage();
console.log('Message from storage: ' + message);
res.status(200).json({message});
}
setMessage.js
import Storage from '../../service/memoryStorage';
export default function handler(req, res) {
Storage.setMessage('Hello World');
res.status(200).json({status: 'ok'});
}
In production build everything works as expected, the problem occurs only in dev. When I request the setMessage API and getMessage after that, message in a HTTP response of getMessage will be ,,undefined" instead of ,,Hello World". This happens because of the lazy compilation in DEV. When you try it the second time, it is going to work because the compilation has already finished.
Expected Behavior
getMessage API to return ,,Hello World" instead of undefined
Which browser are you using? (if relevant)
No response
How are you deploying your application? (if relevant)
No response
The text was updated successfully, but these errors were encountered:
I'm also experiencing this while trying to keep a Postgres connection pool alive between requests.
If persisting something on the global object isn't supported, I'd at least appreciate some official guidance in the documentation re: creating database connections.
Verify canary release
Provide environment information
Which area(s) of Next.js are affected? (leave empty if unsure)
No response
Link to the code that reproduces this issue
https://stackblitz.com/edit/vercel-next-js-xfenwd?file=pages/api/setMessage.js
To Reproduce
Just call the setMessage API method, after that call getMessage method
Describe the Bug
I have a basic in memory storage object
memoryStorage.js
And API handlers to set and then get the global message
getMessage.js
setMessage.js
In production build everything works as expected, the problem occurs only in dev. When I request the setMessage API and getMessage after that, message in a HTTP response of getMessage will be ,,undefined" instead of ,,Hello World". This happens because of the lazy compilation in DEV. When you try it the second time, it is going to work because the compilation has already finished.
Expected Behavior
getMessage API to return ,,Hello World" instead of undefined
Which browser are you using? (if relevant)
No response
How are you deploying your application? (if relevant)
No response
The text was updated successfully, but these errors were encountered: