Import API endpoint into getServerSideProps #17115
Unanswered
rawcomposition
asked this question in
Help
Replies: 0 comments
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.
-
So when using getServerSideProps in Next.js, the docs recommend not directly using fetch(), but instead, importing the API endpoint function directly. I tried doing this, but got hung up when trying to incorporate my MongoDB middleware. I end up with something like this:
How could I refactor this in such a way that I could directly import this endpoint into my getServerSideProps function? Or should I ignore the documentation suggestions and just use fetch()?
I was thinking I could do something like like below, but I'm not sure how to allow my
getPost
function to access the middleware DB connection.and then in my next.js page:
Beta Was this translation helpful? Give feedback.
All reactions