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 00000000..2c6859a3 Binary files /dev/null and b/apps/backend/src/assets/favicon.ico differ diff --git a/apps/backend/src/assets/index.html b/apps/backend/src/assets/index.html new file mode 100644 index 00000000..a48727c9 --- /dev/null +++ b/apps/backend/src/assets/index.html @@ -0,0 +1,65 @@ + + + + + + + + Snipcode API + + + + + + + + +
+
+
+

Snipcode API

+
+ + +
+
+ + + diff --git a/apps/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"