diff --git a/examples/with-nestjs/README.md b/examples/with-nestjs/README.md index d307c03901d8d..96648d66a30db 100644 --- a/examples/with-nestjs/README.md +++ b/examples/with-nestjs/README.md @@ -12,22 +12,24 @@ npx create-turbo@latest -e with-nestjs ## What's inside? -This Turborepo includes the following packages/apps: +This Turborepo includes the following packages & apps: ### Apps and Packages - . - ├── apps - │ ├── api # NestJS app (https://nestjs.com). - │ └── web # Next.js app (https://nextjs.org). - └── packages - ├── @repo/api # Shared `NestJS` resources. - ├── @repo/eslint-config # `eslint` configurations (includes `prettier`) - ├── @repo/jest-config # `jest` configurations - ├── @repo/typescript-config # `tsconfig.json`s used throughout the monorepo - └── @repo/ui # Shareable stub React component library. +```shell +. +├── apps +│ ├── api # NestJS app (https://nestjs.com). +│ └── web # Next.js app (https://nextjs.org). +└── packages + ├── @repo/api # Shared `NestJS` resources. + ├── @repo/eslint-config # `eslint` configurations (includes `prettier`) + ├── @repo/jest-config # `jest` configurations + ├── @repo/typescript-config # `tsconfig.json`s used throughout the monorepo + └── @repo/ui # Shareable stub React component library. +``` -Each package and application are 100% [TypeScript](https://www.typescriptlang.org/) safe. +Each package and application are mostly written in [TypeScript](https://www.typescriptlang.org/). ### Utilities @@ -110,6 +112,8 @@ npx turbo link ## Useful Links +This example take some inspiration the [with-nextjs](https://github.com/vercel/turborepo/tree/main/examples/with-nextjs) `Turbo` example and [01-cats-app](https://github.com/nestjs/nest/tree/master/sample/01-cats-app) `NestJs` sample. + Learn more about the power of Turborepo: - [Tasks](https://turborepo.com/docs/crafting-your-repository/running-tasks) diff --git a/examples/with-nestjs/apps/api/.prettierrc.mjs b/examples/with-nestjs/apps/api/.prettierrc.mjs index 89f612fb73886..efa0b73414f83 100644 --- a/examples/with-nestjs/apps/api/.prettierrc.mjs +++ b/examples/with-nestjs/apps/api/.prettierrc.mjs @@ -1,4 +1,4 @@ -import config from "@repo/eslint-config/prettier-base"; +import config from '@repo/eslint-config/prettier-base'; /** @type {import("prettier").Config} */ export default config; diff --git a/examples/with-nestjs/apps/api/README.md b/examples/with-nestjs/apps/api/README.md index 8560acd226524..425c22835ba2b 100644 --- a/examples/with-nestjs/apps/api/README.md +++ b/examples/with-nestjs/apps/api/README.md @@ -6,19 +6,20 @@ First, run the development server: ```bash pnpm run dev +# Also works with NPM, YARN, BUN, ... ``` -By default, your server will run at [http://localhost:3000](http://localhost:3000). You can use your favorite API platform like [Insomnia](https://insomnia.rest/) or [Postman](https://www.postman.com/) to test your APIs +By default, your server will run at [localhost:3000](http://localhost:3000). You can use your favorite API platform like [Insomnia](https://insomnia.rest/) or [Postman](https://www.postman.com/) to test your APIs You can start editing the demo **APIs** by modifying [linksService](./src/links/links.service.ts) provider. -### ⚠️ Note about build +### Important Note 🚧 -If you plan to only build this app. Please make sure you've built the packages first. +If you plan to `build` or `test` the app. Please make sure to build the `packages/*` first. ## Learn More -To learn more about NestJs, take a look at the following resources: +Learn more about `NestJs` with following resources: - [Official Documentation](https://docs.nestjs.com) - A progressive Node.js framework for building efficient, reliable and scalable server-side applications. - [Official NestJS Courses](https://courses.nestjs.com) - Learn everything you need to master NestJS and tackle modern backend applications at any scale. diff --git a/examples/with-nestjs/apps/api/eslint.config.mjs b/examples/with-nestjs/apps/api/eslint.config.mjs index 3285917fb2200..dea45ec254f1c 100644 --- a/examples/with-nestjs/apps/api/eslint.config.mjs +++ b/examples/with-nestjs/apps/api/eslint.config.mjs @@ -1,4 +1,9 @@ -import { nestJsConfig } from "@repo/eslint-config/nest-js"; +import { nestJsConfig } from '@repo/eslint-config/nest-js'; /** @type {import("eslint").Linter.Config} */ -export default nestJsConfig; +export default [ + ...nestJsConfig, + { + ignores: ['.prettierrc.mjs', 'eslint.config.mjs'], + }, +]; diff --git a/examples/with-nestjs/apps/api/src/links/links.controller.ts b/examples/with-nestjs/apps/api/src/links/links.controller.ts index 8875e9964fe96..ca976a34795d2 100644 --- a/examples/with-nestjs/apps/api/src/links/links.controller.ts +++ b/examples/with-nestjs/apps/api/src/links/links.controller.ts @@ -7,10 +7,10 @@ import { Param, Delete, } from '@nestjs/common'; -import { LinksService } from './links.service'; -import { CreateLinkDto } from '@repo/api/links/dto/create-link.dto'; -import { UpdateLinkDto } from '@repo/api/links/dto/update-link.dto'; +import type { CreateLinkDto, UpdateLinkDto } from '@repo/api'; + +import { LinksService } from './links.service'; @Controller('links') export class LinksController { diff --git a/examples/with-nestjs/apps/api/src/links/links.service.ts b/examples/with-nestjs/apps/api/src/links/links.service.ts index dc5a376870fd1..962b5b28b41cb 100644 --- a/examples/with-nestjs/apps/api/src/links/links.service.ts +++ b/examples/with-nestjs/apps/api/src/links/links.service.ts @@ -1,44 +1,33 @@ import { Injectable } from '@nestjs/common'; -import { Link } from '@repo/api/links/entities/link.entity'; - -import { CreateLinkDto } from '@repo/api/links/dto/create-link.dto'; -import { UpdateLinkDto } from '@repo/api/links/dto/update-link.dto'; +import { Link, CreateLinkDto, UpdateLinkDto } from '@repo/api'; @Injectable() export class LinksService { private readonly _links: Link[] = [ { id: 0, - title: 'Docs', - url: 'https://turborepo.com/docs', - description: - 'Find in-depth information about Turborepo features and API.', + title: 'Installation', + url: 'https://turborepo.com/docs/getting-started/installation', + description: 'Get started with Turborepo in a few moments using', }, { id: 1, - title: 'Learn', - url: 'https://turborepo.com/docs/handbook', - description: 'Learn more about monorepos with our handbook.', + title: 'Crafting', + url: 'https://turborepo.com/docs/crafting-your-repository', + description: 'Architecting a monorepo is a careful process.', }, { id: 2, - title: 'Templates', - url: 'https://turborepo.com/docs/getting-started/from-example', - description: - 'Choose from over 15 examples and deploy with a single click.', - }, - { - id: 3, - title: 'Deploy', - url: 'https://vercel.com/new', + title: 'Add Repositories', + url: 'https://turborepo.com/docs/getting-started/add-to-existing-repository', description: - 'Instantly deploy your Turborepo to a shareable URL with Vercel.', + 'Turborepo can be incrementally adopted in any repository, single or multi-package, to speed up the developer and CI workflows of the repository.', }, ]; create(createLinkDto: CreateLinkDto) { - return `This action adds a new link ${createLinkDto}`; + return `TODO: This action should add a new link '${createLinkDto.title}'`; } findAll() { @@ -46,14 +35,14 @@ export class LinksService { } findOne(id: number) { - return `This action returns a #${id} link`; + return `TODO: This action should return a Link with id #${id}`; } update(id: number, updateLinkDto: UpdateLinkDto) { - return `This action updates a #${id} link ${updateLinkDto}`; + return `TODO: This action should update a #${id} link ${updateLinkDto.title}`; } remove(id: number) { - return `This action removes a #${id} link`; + return `TODO: This action should remove a #${id} link`; } } diff --git a/examples/with-nestjs/apps/api/src/main.ts b/examples/with-nestjs/apps/api/src/main.ts index 829d5f8d47655..6c97a2342ce51 100644 --- a/examples/with-nestjs/apps/api/src/main.ts +++ b/examples/with-nestjs/apps/api/src/main.ts @@ -1,8 +1,10 @@ import { NestFactory } from '@nestjs/core'; + import { AppModule } from './app.module'; async function bootstrap() { const app = await NestFactory.create(AppModule); + app.enableCors(); await app.listen(3000); } diff --git a/examples/with-nestjs/apps/web/README.md b/examples/with-nestjs/apps/web/README.md index a98bfa8140e14..2684dba40854a 100644 --- a/examples/with-nestjs/apps/web/README.md +++ b/examples/with-nestjs/apps/web/README.md @@ -1,20 +1,13 @@ -This is a [Next.js](https://nextjs.org) project bootstrapped with [`create-next-app`](https://nextjs.org/docs/app/api-reference/create-next-app). - -## Getting Started +# Getting Started First, run the development server: ```bash -npm run dev -# or -yarn dev -# or pnpm dev -# or -bun dev +# Also works with NPM, YARN, BUN, ... ``` -Open [http://localhost:3000](http://localhost:3000) with your browser to see the result. +Browse [localhost:3001](http://localhost:3001) to see the result. You can start editing the page by modifying `app/page.tsx`. The page auto-updates as you edit the file. @@ -22,7 +15,7 @@ This project uses [`next/font`](https://nextjs.org/docs/app/building-your-applic ## Learn More -To learn more about Next.js, take a look at the following resources: +Learn more about `Next.js` with the following resources: - [Next.js Documentation](https://nextjs.org/docs) - learn about Next.js features and API. - [Learn Next.js](https://nextjs.org/learn) - an interactive Next.js tutorial. diff --git a/examples/with-nestjs/apps/web/app/page.tsx b/examples/with-nestjs/apps/web/app/page.tsx index b4a718f0f43ef..4fe47804d3046 100644 --- a/examples/with-nestjs/apps/web/app/page.tsx +++ b/examples/with-nestjs/apps/web/app/page.tsx @@ -1,5 +1,7 @@ -import Image, { type ImageProps } from 'next/image'; +import type { Link } from '@repo/api'; import { Button } from '@repo/ui/button'; +import Image, { type ImageProps } from 'next/image'; + import styles from './page.module.css'; type Props = Omit & { @@ -18,7 +20,26 @@ const ThemeImage = (props: Props) => { ); }; -export default function Home() { +async function getLinks(): Promise { + try { + const res = await fetch('http://localhost:3000/links', { + cache: 'no-store', + }); + + if (!res.ok) { + throw new Error('Failed to fetch links'); + } + + return res.json(); + } catch (error) { + console.error('Error fetching links:', error); + return []; + } +} + +export default async function Home() { + const links = await getLinks(); + return (
@@ -63,10 +84,34 @@ export default function Home() { Read our docs
+ + + {links.length > 0 ? ( +
+ {links.map((link) => ( + + {link.title} + + ))} +
+ ) : ( +
+ No links available. Make sure the NestJS API is running on port + 3000. +
+ )} +