I’m hoping for some feedback on the pattern I am using to leverage Parse Server in a NextJS project.
Note: I understand that there is an experimental Parse SSR package that is released, but I do not need live queries, and I want to prioritize stability.
I do, however, need to optimize for SEO on a few pages. Therefore, I will need to server side render data on a few pages. To do this, I have come up with the following pattern for the getServerSideProps()
function on my blogs pages:
export async function getServerSideProps (context) {
const blogId = context.params.slug
const NodeParse = require('parse/node')
NodeParse.initialize(process.env.NEXT_PUBLIC_PARSE_APPLICATION_ID)
NodeParse.serverURL = process.env.NEXT_PUBLIC_PARSE_HOST_URL
const blogQuery = new NodeParse.Query('Blog')
blogQuery.equalTo('objectId', blogId)
const blog = await blogQuery.first()
// ... some processing code
return {
props: {
title: blogTitle,
contentHtml
}
}
}
I use the client side Parse import to handle authentication and login gated routes. I initialize it in _app.js
as follows:
import Parse from 'parse'
Parse.initialize(process.env.NEXT_PUBLIC_PARSE_APPLICATION_ID)
Parse.serverURL = process.env.NEXT_PUBLIC_PARSE_HOST_URL
function MyApp ({ Component, pageProps }) {
return ( <Component {...pageProps} />)
}
I have the following parse dependency: "parse": "^3.5.1"
Does this seem reasonable? If so, can I safely ignore the following warning?
It looks like you're using the browser version of the SDK in a node.js environment. You should require('parse/node') instead.