I'd like to do server side rendering with Next.js using the getServerSideProps
method like explained in the docs.
The data should come from a database, so I'm using the mysql
package. This results in the following error:
Error serializing `.assertions[0]` returned from `getServerSideProps` in "/assertion". Reason: `object` ("[object Object]") cannot be serialized as JSON. Please only return JSON serializable data types.
I think the reason for this is, because the query
method from mysql
returns special objects (RowDataPacket
). The result that I'd like to pass to getServerSideProps
looks like this when logged:
[ RowDataPacket { id: 1, title: 'Test' } ]
I can fix this error by wrapping the result with JSON.parse(JSON.stringify(result))
but this seems very odd to me.
So, my simple question is: How to use mysql.query
and getServerSideProps
correctly?
Or might this be an issue that should be addressed by Next.js
?
Thank you