From f6f8fa07344cc67424f9c82c283927198e3e6986 Mon Sep 17 00:00:00 2001 From: Eric Cabrel TIOGO Date: Sun, 4 Aug 2024 16:03:43 +0200 Subject: [PATCH] feat(backend): build the homepage --- .changeset/beige-experts-occur.md | 5 ++ .../actions/install-dependencies/action.yml | 2 +- .github/workflows/build.yml | 2 +- .github/workflows/deploy-frontend.yml | 2 +- apps/backend/Dockerfile | 10 +-- apps/backend/jest.config.ts | 2 +- apps/backend/nest-cli.json | 10 ++- apps/backend/package.json | 5 +- apps/backend/src/app.module.ts | 12 +++- apps/backend/src/assets/favicon.ico | Bin 0 -> 15406 bytes apps/backend/src/assets/index.html | 65 ++++++++++++++++++ .../src/features/app/app.controller.ts | 11 --- .../src/features/app/app.integration.spec.ts | 2 +- apps/backend/src/main.ts | 2 +- apps/backend/tsconfig.json | 1 + package.json | 2 +- yarn.lock | 30 ++++++++ 17 files changed, 132 insertions(+), 31 deletions(-) create mode 100644 .changeset/beige-experts-occur.md create mode 100644 apps/backend/src/assets/favicon.ico create mode 100644 apps/backend/src/assets/index.html delete mode 100644 apps/backend/src/features/app/app.controller.ts diff --git a/.changeset/beige-experts-occur.md b/.changeset/beige-experts-occur.md new file mode 100644 index 00000000..67d43312 --- /dev/null +++ b/.changeset/beige-experts-occur.md @@ -0,0 +1,5 @@ +--- +'@snipcode/backend': patch +--- + +Build the backend API homepage diff --git a/.github/actions/install-dependencies/action.yml b/.github/actions/install-dependencies/action.yml index b8183e02..59984267 100644 --- a/.github/actions/install-dependencies/action.yml +++ b/.github/actions/install-dependencies/action.yml @@ -24,7 +24,7 @@ runs: shell: bash run: | corepack enable - yarn set version 4.3.1 + yarn set version 4.4.0 - name: Install projects dependencies shell: bash diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 3d5a1fb0..9a9b19c0 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -68,7 +68,7 @@ jobs: - name: Install Yarn 4 run: | corepack enable - yarn set version 4.3.1 + yarn set version 4.4.0 - name: Install Vercel CLI run: npm install --global vercel@latest diff --git a/.github/workflows/deploy-frontend.yml b/.github/workflows/deploy-frontend.yml index 8c49e4ef..0ca41291 100644 --- a/.github/workflows/deploy-frontend.yml +++ b/.github/workflows/deploy-frontend.yml @@ -23,7 +23,7 @@ jobs: - name: Install Yarn 4 run: | corepack enable - yarn set version 4.3.1 + yarn set version 4.4.0 - name: Install Vercel CLI run: npm install --global vercel@latest diff --git a/apps/backend/Dockerfile b/apps/backend/Dockerfile index ae4152ab..70bdfd94 100644 --- a/apps/backend/Dockerfile +++ b/apps/backend/Dockerfile @@ -6,7 +6,7 @@ WORKDIR /app COPY . . -RUN corepack enable && yarn set version berry +RUN corepack enable && yarn set version 4.4.0 RUN yarn install @@ -35,7 +35,7 @@ ENV APP_VERSION=${APP_VERSION} WORKDIR /app -RUN corepack enable && yarn set version berry +RUN corepack enable && yarn set version 4.4.0 COPY --chown=node:node --from=builder /app/package.json . COPY --chown=node:node --from=builder /app/.yarnrc.yml . @@ -43,12 +43,6 @@ COPY --chown=node:node --from=builder /app/.yarnrc.yml . COPY --chown=node:node --from=builder /app/apps/backend/dist/src ./apps/backend/src COPY --chown=node:node --from=builder /app/apps/backend/package.json ./apps/backend -COPY --chown=node:node --from=builder /app/apps/backend/src/features/schema.graphql ./apps/backend/src/features/schema.graphql -COPY --chown=node:node --from=builder /app/apps/backend/src/features/users/graphql/schema.graphql ./apps/backend/src/features/users/graphql/schema.graphql -COPY --chown=node:node --from=builder /app/apps/backend/src/features/snippets/graphql/schema.graphql ./apps/backend/src/features/snippets/graphql/schema.graphql -COPY --chown=node:node --from=builder /app/apps/backend/src/features/folders/graphql/schema.graphql ./apps/backend/src/features/folders/graphql/schema.graphql -COPY --chown=node:node --from=builder /app/apps/backend/src/features/auth/graphql/schema.graphql ./apps/backend/src/features/auth/graphql/schema.graphql - COPY --chown=node:node --from=builder /app/packages/domain/package.json ./packages/domain/package.json COPY --chown=node:node --from=builder /app/packages/domain/dist ./packages/domain/dist diff --git a/apps/backend/jest.config.ts b/apps/backend/jest.config.ts index b48aaa30..281ec792 100644 --- a/apps/backend/jest.config.ts +++ b/apps/backend/jest.config.ts @@ -5,7 +5,7 @@ const config: Config.InitialOptions = { maxWorkers: 1, moduleFileExtensions: ['js', 'json', 'ts'], preset: 'ts-jest', - roots: ['.'], + roots: ['src'], snapshotFormat: { printBasicPrototype: false, }, diff --git a/apps/backend/nest-cli.json b/apps/backend/nest-cli.json index f9aa683b..5fbe064d 100644 --- a/apps/backend/nest-cli.json +++ b/apps/backend/nest-cli.json @@ -3,6 +3,14 @@ "collection": "@nestjs/schematics", "sourceRoot": "src", "compilerOptions": { - "deleteOutDir": true + "deleteOutDir": true, + "assets": [ + { "include": "assets", "outDir": "dist/src", "watchAssets": true }, + { "include": "features/schema.graphql", "outDir": "dist/src", "watchAssets": true }, + { "include": "features/auth/graphql/schema.graphql", "outDir": "dist/src", "watchAssets": true }, + { "include": "features/folders/graphql/schema.graphql", "outDir": "dist/src", "watchAssets": true }, + { "include": "features/snippets/graphql/schema.graphql", "outDir": "dist/src", "watchAssets": true }, + { "include": "features/users/graphql/schema.graphql", "outDir": "dist/src", "watchAssets": true } + ] } } diff --git a/apps/backend/package.json b/apps/backend/package.json index fbc74742..ca2a93a3 100644 --- a/apps/backend/package.json +++ b/apps/backend/package.json @@ -8,8 +8,8 @@ "scripts": { "build": "nest build", "clean": "rm -rf .turbo dist build logs", - "dev": "dotenv -e .env.local -- nest start --watch", - "dev:debug": "nest start --debug --watch", + "dev": "dotenv -e .env.local -- nest start --watch --watchAssets", + "dev:debug": "dotenv -e .env.local -- nest start --debug --watch", "gql:gen:types": "ts-node scripts/generate-graphql-types.ts", "lint": "eslint \"{src,scripts}/**/*.ts\" --fix", "prod": "node dist/main", @@ -27,6 +27,7 @@ "@nestjs/core": "10.3.9", "@nestjs/graphql": "12.1.1", "@nestjs/platform-express": "10.3.9", + "@nestjs/serve-static": "4.0.2", "@prisma/client": "5.14.0", "@sentry/node": "8.11.0", "@snipcode/domain": "workspace:*", diff --git a/apps/backend/src/app.module.ts b/apps/backend/src/app.module.ts index fe837dce..76524cc5 100644 --- a/apps/backend/src/app.module.ts +++ b/apps/backend/src/app.module.ts @@ -1,13 +1,15 @@ +import { join } from 'path'; + import { ApolloServerPlugin } from '@apollo/server'; import { ApolloServerPluginLandingPageLocalDefault } from '@apollo/server/plugin/landingPage/default'; import { ApolloDriver, ApolloDriverConfig } from '@nestjs/apollo'; import { Logger, Module } from '@nestjs/common'; import { ConfigModule, ConfigService } from '@nestjs/config'; import { GraphQLModule } from '@nestjs/graphql'; +import { ServeStaticModule } from '@nestjs/serve-static'; import { DomainModule } from '@snipcode/domain'; import { EnvironmentVariables, validate } from './configs/environment'; -import { AppController } from './features/app/app.controller'; import { AppService } from './features/app/app.service'; import { AuthFeatureModule } from './features/auth/auth.module'; import { FolderFeatureModule } from './features/folders/folder.module'; @@ -19,7 +21,7 @@ import { DateScalar } from './utils/graphql/date-scalar'; const explorerPlugin: ApolloServerPlugin[] = IS_DEV ? [ApolloServerPluginLandingPageLocalDefault({ embed: true })] : []; @Module({ - controllers: [AppController], + controllers: [], imports: [ ConfigModule.forRoot({ envFilePath: ['.env.local', '.env.test'], @@ -54,6 +56,12 @@ const explorerPlugin: ApolloServerPlugin[] = IS_DEV ? [ApolloServerPluginLanding }; }, }), + ServeStaticModule.forRoot({ + exclude: ['/graphql', '/auth*', '/snippets*'], + renderPath: '/', + rootPath: join(__dirname, 'assets'), + serveRoot: '/', + }), AuthFeatureModule, FolderFeatureModule, SnippetFeatureModule, diff --git a/apps/backend/src/assets/favicon.ico b/apps/backend/src/assets/favicon.ico new file mode 100644 index 0000000000000000000000000000000000000000..2c6859a36b01e48f0a4099a098da36c41b10e136 GIT binary patch literal 15406 zcmeI2d9+UD9>-rvhRkV_;h@CTAWFAVX^;k_>z1VnEnQ8d7M0Sl(&RQN8a2@^S!pgx zu7-PQLR3;J>6Y7wkR;Ome760(Yw!2G?{Us?{B_%Feb@I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/backend/src/features/app/app.controller.ts b/apps/backend/src/features/app/app.controller.ts deleted file mode 100644 index 83771475..00000000 --- a/apps/backend/src/features/app/app.controller.ts +++ /dev/null @@ -1,11 +0,0 @@ -import { Controller, Get } from '@nestjs/common'; - -@Controller() -export class AppController { - constructor() {} - - @Get() - async helloWorld(): Promise { - return 'Hello from Snipcode!'; - } -} diff --git a/apps/backend/src/features/app/app.integration.spec.ts b/apps/backend/src/features/app/app.integration.spec.ts index d38448bb..b25ebcfe 100644 --- a/apps/backend/src/features/app/app.integration.spec.ts +++ b/apps/backend/src/features/app/app.integration.spec.ts @@ -17,6 +17,6 @@ describe('Application Common Endpoints', () => { const response = await request(server.app.getHttpServer()).get('/').expect(200); expect(response.body).toEqual({}); - expect(response.text).toBe('Hello from Snipcode!'); + expect(response.text).toBeDefined(); }); }); diff --git a/apps/backend/src/main.ts b/apps/backend/src/main.ts index 8507fd67..21646035 100644 --- a/apps/backend/src/main.ts +++ b/apps/backend/src/main.ts @@ -17,7 +17,7 @@ const bootstrap = async () => { const host = configService.get('HOST'); await app.listen(port, () => { - logger.log(`Application ready at ${host}:${port}/graphql`); + logger.log(`Application ready at ${host}:${port}`); }); }; diff --git a/apps/backend/tsconfig.json b/apps/backend/tsconfig.json index 23e86132..3a172d78 100644 --- a/apps/backend/tsconfig.json +++ b/apps/backend/tsconfig.json @@ -15,6 +15,7 @@ "./scripts/**/*" ], "exclude": [ + "dist", "node_modules", ".turbo" ], diff --git a/package.json b/package.json index 4a8f1b1d..47e8c4e3 100644 --- a/package.json +++ b/package.json @@ -67,5 +67,5 @@ "turbo": "2.0.5", "typescript": "5.5.2" }, - "packageManager": "yarn@4.3.1" + "packageManager": "yarn@4.4.0" } diff --git a/yarn.lock b/yarn.lock index 35089159..b1687cd3 100644 --- a/yarn.lock +++ b/yarn.lock @@ -3878,6 +3878,28 @@ __metadata: languageName: node linkType: hard +"@nestjs/serve-static@npm:4.0.2": + version: 4.0.2 + resolution: "@nestjs/serve-static@npm:4.0.2" + dependencies: + path-to-regexp: "npm:0.2.5" + peerDependencies: + "@fastify/static": ^6.5.0 || ^7.0.0 + "@nestjs/common": ^9.0.0 || ^10.0.0 + "@nestjs/core": ^9.0.0 || ^10.0.0 + express: ^4.18.1 + fastify: ^4.7.0 + peerDependenciesMeta: + "@fastify/static": + optional: true + express: + optional: true + fastify: + optional: true + checksum: 10/337905afb5545ef7280ed408e8929aa4ab7ecf754e11d0c4a7b3e641b50cd34ed9bdd70e16c19f01fb1446a17cd6098481db6de2719c808a43031fdcd8792ac8 + languageName: node + linkType: hard + "@nestjs/testing@npm:10.3.9": version: 10.3.9 resolution: "@nestjs/testing@npm:10.3.9" @@ -5392,6 +5414,7 @@ __metadata: "@nestjs/graphql": "npm:12.1.1" "@nestjs/platform-express": "npm:10.3.9" "@nestjs/schematics": "npm:10.1.1" + "@nestjs/serve-static": "npm:4.0.2" "@nestjs/testing": "npm:10.3.9" "@ngneat/falso": "npm:7.2.0" "@prisma/client": "npm:5.14.0" @@ -15025,6 +15048,13 @@ __metadata: languageName: node linkType: hard +"path-to-regexp@npm:0.2.5": + version: 0.2.5 + resolution: "path-to-regexp@npm:0.2.5" + checksum: 10/9652fd2b74ec932a0df8a868478478565da81e7445a8dde1e65ca80553ad03062336b1f79234068551ecc01f3b76ad774e34f784cc3a34a97c4646cb5cfcbea9 + languageName: node + linkType: hard + "path-to-regexp@npm:2.2.1": version: 2.2.1 resolution: "path-to-regexp@npm:2.2.1"