๐ป Lab 7 - Add a NestJS API
May 31, 2023 ยท View on GitHub
โฐ Estimated time: 10-15 minutes
Up until now we've had a single app in our repository, and a few other libs that it uses.
But remember how we created that fake-api way back in the second lab, that only our store app can access?
Our new routed component suddenly needs access to the games as well, so in this lab we'll be adding a completely new app, this time on the backend, as an API. And we'll use the @nx/nest package to easily generate everything we need.
You do not need to be familiar with Nest (and you can use the @nrwl/express:app plugin instead if you wish). All the NestJS specific code for serving the games is provided in the solution.
๐ Learning outcomes:
- Explore other plugins in the Nx ecosystem
๐ฒ After this workshop, you should have:
App Screenshot
No change in how the app looks!File structure
๐๏ธโโ๏ธ Steps:
-
Stop any running
nx serveinstance -
Install
@nx/nest -
Generate a new NestJS app, called
apiโ ๏ธ Make sure you instruct the generator to configure a proxy from the frontend
storeto the newapiservice (use--helpto see the available options) -
Update
proxy.conf.jsoninapps/storeto point to port3000 -
Copy the code from the
fake apito the new Nestapps/api/src/app/app.service.ts and expose thegetGames()andgetGame()methods -
Update the Nest app.controller.ts to use the new methods from the service
-
Let's now inspect the project graph!
-
Inspect what changed from the last time you committed, then commit your changes
๐If you get stuck, check out the solution