Skn0tt / nextjs-nestjs-integration-example

https://nextjs-nestjs-integration-example.now.sh
156 stars 36 forks source link

Calling NestJS in getServerSideProps #10

Closed ttsirkia closed 3 years ago

ttsirkia commented 3 years ago

What if you had a service providing the random number, would it be possible to call that service easily in getServerSideProps? And the same service in the controller.

In this way you could handle both API calls and loading data for pages by using the same services.

Skn0tt commented 3 years ago

It sure is! I've added an example here: pages/gssp.tsx

Skn0tt commented 3 years ago

The example injects a Controller, but services can be injected the same way.

ttsirkia commented 3 years ago

OK, it's that simple. Thank you very much!