Skip to content

Commit

Permalink
feat(backend): build the homepage
Browse files Browse the repository at this point in the history
  • Loading branch information
tericcabrel committed Aug 4, 2024
1 parent 0082c12 commit f6f8fa0
Show file tree
Hide file tree
Showing 17 changed files with 132 additions and 31 deletions.
5 changes: 5 additions & 0 deletions .changeset/beige-experts-occur.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@snipcode/backend': patch
---

Build the backend API homepage
2 changes: 1 addition & 1 deletion .github/actions/install-dependencies/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/deploy-frontend.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
10 changes: 2 additions & 8 deletions apps/backend/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -35,20 +35,14 @@ 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 .

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

Expand Down
2 changes: 1 addition & 1 deletion apps/backend/jest.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ const config: Config.InitialOptions = {
maxWorkers: 1,
moduleFileExtensions: ['js', 'json', 'ts'],
preset: 'ts-jest',
roots: ['.'],
roots: ['src'],
snapshotFormat: {
printBasicPrototype: false,
},
Expand Down
10 changes: 9 additions & 1 deletion apps/backend/nest-cli.json
Original file line number Diff line number Diff line change
Expand Up @@ -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 }
]
}
}
5 changes: 3 additions & 2 deletions apps/backend/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -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:*",
Expand Down
12 changes: 10 additions & 2 deletions apps/backend/src/app.module.ts
Original file line number Diff line number Diff line change
@@ -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';
Expand All @@ -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'],
Expand Down Expand Up @@ -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,
Expand Down
Binary file added apps/backend/src/assets/favicon.ico
Binary file not shown.
65 changes: 65 additions & 0 deletions apps/backend/src/assets/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">

<link rel="icon" href="/favicon.ico">
<title>Snipcode API</title>

<!-- Fonts -->
<link href="https://fonts.googleapis.com/css?family=Inter:200,600" rel="stylesheet">

<!-- Styles -->
<style>
html, body {
background-color: #242424;
color: #ffffff;
font-family: 'Inter', sans-serif;
font-weight: 200;
height: 100vh;
margin: 0;
}
.main {
height: 100vh;
align-items: center;
display: flex;
justify-content: center;
position: relative;
}
.content {
text-align: center;
}
.title {
font-size: 50px;
margin-bottom: 30px;
}
.links > a {
color: #ffffff;
padding: 0 25px;
font-size: 13px;
font-weight: 600;
letter-spacing: .1rem;
text-decoration: none;
text-transform: uppercase;
}
</style>
</head>
<body>
<div class="main">
<div class="content">
<div class="title">
<h1>Snipcode API</h1>
</div>

<div class="links">
<a href="/graphql">GraphQL Playground</a>
<!--<a href="/documentation">Documentation</a>-->
<a href="https://snipcode.dev" target="_blank">Web Application</a>
<a href="https://github.com/tericcabrel/snipcode" target="_blank">GitHub Repo</a>
</div>
</div>
</div>

</body>
</html>
11 changes: 0 additions & 11 deletions apps/backend/src/features/app/app.controller.ts

This file was deleted.

2 changes: 1 addition & 1 deletion apps/backend/src/features/app/app.integration.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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();
});
});
2 changes: 1 addition & 1 deletion apps/backend/src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ const bootstrap = async () => {
const host = configService.get<string>('HOST');

await app.listen(port, () => {
logger.log(`Application ready at ${host}:${port}/graphql`);
logger.log(`Application ready at ${host}:${port}`);
});
};

Expand Down
1 change: 1 addition & 0 deletions apps/backend/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
"./scripts/**/*"
],
"exclude": [
"dist",
"node_modules",
".turbo"
],
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -67,5 +67,5 @@
"turbo": "2.0.5",
"typescript": "5.5.2"
},
"packageManager": "yarn@4.3.1"
"packageManager": "yarn@4.4.0"
}
30 changes: 30 additions & 0 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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"
Expand Down Expand Up @@ -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"
Expand Down

0 comments on commit f6f8fa0

Please sign in to comment.