Skip to content

Commit 743b56e

Browse files
committed
fixing dockerized bug, and adding auto documentation with openapi
1 parent 848370d commit 743b56e

File tree

7 files changed

+73
-20
lines changed

7 files changed

+73
-20
lines changed

.env.example

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
PROJECT_NAME=starter-kit # please use kebab-case or snake_case, example : starter-kit or starter_kit
2+
13
APP_ENV=development
24
APP_API_KEY=sandbox
35

@@ -28,6 +30,8 @@ GOOGLE_APPLICATION_CREDENTIALS=/app/dist/service-account.json
2830

2931

3032
# DOCKER ENV
31-
DB_EXPOSED_PORT=
32-
APP_EXPOSED_PORT=
33-
REDIS_EXPOSED_PORT=
33+
DB_EXPOSED_PORT=8610
34+
APP_EXPOSED_PORT=8611
35+
ADMINER_EXPOSED_PORT=8613
36+
REDIS_EXPOSED_PORT=8612
37+
SMTP_EXPOSED_PORT=8614

Dockerfile

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,8 @@ WORKDIR /app
2121
RUN --mount=type=bind,source=package.json,target=package.json \
2222
--mount=type=bind,source=yarn.lock,target=yarn.lock \
2323
--mount=type=cache,target=/root/.yarn \
24-
yarn install --production --frozen-lockfile
24+
yarn install
25+
# yarn install --production --frozen-lockfile
2526

2627
# Run the application as a non-root user.
2728
USER node
@@ -33,5 +34,4 @@ COPY . .
3334
EXPOSE 8100
3435

3536
# Run the application.
36-
CMD yarn run build
37-
CMD yarn run start:dev
37+
CMD yarn run start:dev

compose.yaml

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,15 @@
77
# You can add other services your application may depend on here, such as a
88
# database or a cache. For examples, see the Awesome Compose repository:
99
# https://github.com/docker/awesome-compose
10-
name: "starter-kit"
10+
name: ${PROJECT_NAME}
1111
services:
1212
app:
1313
container_name: "starter-kit-app"
1414
build:
1515
context: .
1616
environment:
17-
NODE_ENV: production
17+
# NODE_ENV: production # will installed without 'devDependencies'
18+
NODE_ENV: development
1819
ports:
1920
- ${APP_EXPOSED_PORT:-8610}:3000
2021
depends_on:
@@ -29,6 +30,7 @@ services:
2930
- /bin/sh
3031
- -c
3132
- |
33+
yarn install
3234
yarn run build
3335
yarn run start:dev
3436

package.json

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
"description": "",
55
"author": "",
66
"private": true,
7-
"license": "UNLICENSED",
7+
"license": "MIT",
88
"scripts": {
99
"build": "nest build",
1010
"format": "prettier --write \"src/**/*.ts\" \"test/**/*.ts\"",
@@ -31,6 +31,7 @@
3131
"@nestjs/jwt": "^10.1.0",
3232
"@nestjs/passport": "^10.0.2",
3333
"@nestjs/platform-express": "^10.0.2",
34+
"@nestjs/swagger": "^7.1.13",
3435
"@nestjs/typeorm": "^10.0.0",
3536
"@svtslv/nestjs-ioredis": "^1.0.2",
3637
"bcrypt": "^5.1.0",
@@ -50,7 +51,7 @@
5051
"uuid": "^9.0.0"
5152
},
5253
"devDependencies": {
53-
"@nestjs/cli": "^10.1.0",
54+
"@nestjs/cli": "^10.1.18",
5455
"@nestjs/schematics": "^10.0.2",
5556
"@nestjs/testing": "^10.2.7",
5657
"@types/bcrypt": "^5.0.0",

src/apps/auth/auth.controller.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import { AuthService } from './auth.service';
66
import { LoginDTO } from './dto/login.dto';
77
import { RegisterDTO } from './dto/register.dto';
88
import { I18n, I18nContext } from 'nestjs-i18n';
9+
import { ApiTags } from '@nestjs/swagger';
910

1011
@Controller('auth')
1112
export class AuthController {
@@ -14,6 +15,7 @@ export class AuthController {
1415
private authService: AuthService,
1516
) {}
1617

18+
@ApiTags("Auth")
1719
@Post('/login')
1820
@HttpCode(HttpStatus.OK)
1921
async login(

src/main.ts

Lines changed: 25 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import { join } from 'path';
44
import { ApiKeyGuard } from './apps/app.guard';
55
import { AppModule } from './apps/app.module';
66
import { HttpExceptionFilter } from './common/filters/http-exception.filter';
7+
import { SwaggerModule, DocumentBuilder } from '@nestjs/swagger';
78

89
const APP_PORT = 3000;
910

@@ -20,9 +21,31 @@ async function bootstrap() {
2021

2122
app.setViewEngine('ejs');
2223

23-
await app.listen(APP_PORT);
2424

25-
console.log('listening http://0.0.0.0:' + APP_PORT);
25+
26+
const config = new DocumentBuilder()
27+
.setTitle('StarterKit Project')
28+
.setDescription('This is nestjs starter kit, it\'s will help you when creating new project with nestjs.')
29+
.setVersion('1.0')
30+
.addTag('Auth', "All about authentication")
31+
.build();
32+
const document = SwaggerModule.createDocument(app, config);
33+
SwaggerModule.setup('api', app, document);
34+
35+
await app.listen(APP_PORT);
36+
37+
console.log("--------------------------------------------------------");
38+
39+
if(process.env.DB_EXPOSED_PORT != undefined) {
40+
console.log(`Adminer Exposed on http://0.0.0.0:${process.env.ADMINER_EXPOSED_PORT}/?pgsql=${process.env.DB_HOST}&username=${process.env.DB_USER}&db=${process.env.DB_NAME}`);
41+
}
42+
43+
if(process.env.APP_EXPOSED_PORT != undefined) {
44+
console.log(`App Exposed on http://0.0.0.0:${process.env.APP_EXPOSED_PORT}`);
45+
}
46+
47+
console.log("--------------------------------------------------------");
48+
2649
}
2750

2851
bootstrap();

yarn.lock

Lines changed: 29 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -816,7 +816,7 @@
816816
resolved "https://registry.yarnpkg.com/@nestjs/cache-manager/-/cache-manager-2.1.0.tgz#e4dadc4ba9c02c059db4dac5e0b5513466e2895a"
817817
integrity sha512-9kep3a8Mq5cMuXN/anGhSYc0P48CRBXk5wyJJRBFxhNkCH8AIzZF4CASGVDIEMmm3OjVcEUHojjyJwCODS17Qw==
818818

819-
"@nestjs/cli@^10.1.0":
819+
"@nestjs/cli@^10.1.18":
820820
version "10.1.18"
821821
resolved "https://registry.yarnpkg.com/@nestjs/cli/-/cli-10.1.18.tgz#7aa0099eea5fe60787eb822f9a8a6d47e22d0123"
822822
integrity sha512-jQtG47keLsACt7b4YwJbTBYRm90n82gJpMaiR1HGAyQ9pccbctjSYu592eT4bxqkUWxPgBE3mpNynXj7dWAfrw==
@@ -883,6 +883,11 @@
883883
"@types/jsonwebtoken" "9.0.2"
884884
jsonwebtoken "9.0.0"
885885

886+
887+
version "2.0.2"
888+
resolved "https://registry.yarnpkg.com/@nestjs/mapped-types/-/mapped-types-2.0.2.tgz#c8a090a8d22145b85ed977414c158534210f2e4f"
889+
integrity sha512-V0izw6tWs6fTp9+KiiPUbGHWALy563Frn8X6Bm87ANLRuE46iuBMD5acKBDP5lKL/75QFvrzSJT7HkCbB0jTpg==
890+
886891
"@nestjs/passport@^10.0.2":
887892
version "10.0.2"
888893
resolved "https://registry.yarnpkg.com/@nestjs/passport/-/passport-10.0.2.tgz#42ad193bccec3c332ac8b5e04cf6897bd57500fb"
@@ -921,6 +926,17 @@
921926
jsonc-parser "3.2.0"
922927
pluralize "8.0.0"
923928

929+
"@nestjs/swagger@^7.1.13":
930+
version "7.1.13"
931+
resolved "https://registry.yarnpkg.com/@nestjs/swagger/-/swagger-7.1.13.tgz#5fe1127b159780315f6e827d746b68db7f323e38"
932+
integrity sha512-aHfW0rDZZKTuPVSkxutBCB16lBy5vrsHVoRF5RvPtH7U2cm4Vf+OnfhxKKuG2g2Xocn9sDL+JAyVlY2VN3ytTw==
933+
dependencies:
934+
"@nestjs/mapped-types" "2.0.2"
935+
js-yaml "4.1.0"
936+
lodash "4.17.21"
937+
path-to-regexp "3.2.0"
938+
swagger-ui-dist "5.9.0"
939+
924940
"@nestjs/testing@^10.2.7":
925941
version "10.2.7"
926942
resolved "https://registry.yarnpkg.com/@nestjs/testing/-/testing-10.2.7.tgz#50408ccb4c809d216a12d60ac7932fd6ad7fedf4"
@@ -4579,6 +4595,13 @@ js-tokens@^4.0.0:
45794595
resolved "https://registry.npmjs.org/js-tokens/-/js-tokens-4.0.0.tgz"
45804596
integrity sha512-RdJUflcE3cUzKiMqQgsCu06FPu9UdIJO0beYbPhHN4k6apgJtifcoCtT9bcxOpYBtpD2kCM6Sbzg4CausW/PKQ==
45814597

4598+
[email protected], js-yaml@^4.1.0:
4599+
version "4.1.0"
4600+
resolved "https://registry.npmjs.org/js-yaml/-/js-yaml-4.1.0.tgz"
4601+
integrity sha512-wpxZs9NoxZaJESJGIZTyDEaYpl0FKSA+FB9aJiyemKhMwkxQg63h4T1KJgUGHpTqPDNRcmmYLugrRjJlBtWvRA==
4602+
dependencies:
4603+
argparse "^2.0.1"
4604+
45824605
js-yaml@^3.13.1:
45834606
version "3.14.1"
45844607
resolved "https://registry.npmjs.org/js-yaml/-/js-yaml-3.14.1.tgz"
@@ -4587,13 +4610,6 @@ js-yaml@^3.13.1:
45874610
argparse "^1.0.7"
45884611
esprima "^4.0.0"
45894612

4590-
js-yaml@^4.1.0:
4591-
version "4.1.0"
4592-
resolved "https://registry.npmjs.org/js-yaml/-/js-yaml-4.1.0.tgz"
4593-
integrity sha512-wpxZs9NoxZaJESJGIZTyDEaYpl0FKSA+FB9aJiyemKhMwkxQg63h4T1KJgUGHpTqPDNRcmmYLugrRjJlBtWvRA==
4594-
dependencies:
4595-
argparse "^2.0.1"
4596-
45974613
jsesc@^2.5.1:
45984614
version "2.5.2"
45994615
resolved "https://registry.npmjs.org/jsesc/-/jsesc-2.5.2.tgz"
@@ -7016,6 +7032,11 @@ supports-preserve-symlinks-flag@^1.0.0:
70167032
resolved "https://registry.npmjs.org/supports-preserve-symlinks-flag/-/supports-preserve-symlinks-flag-1.0.0.tgz"
70177033
integrity sha512-ot0WnXS9fgdkgIcePe6RHNk1WA8+muPa6cSjeR3V8K27q9BB1rTE3R1p7Hv0z1ZyAc8s6Vvv8DIyWf681MAt0w==
70187034

7035+
7036+
version "5.9.0"
7037+
resolved "https://registry.yarnpkg.com/swagger-ui-dist/-/swagger-ui-dist-5.9.0.tgz#d52b6cf52fd0a8e6930866c402aaa793fe4e3f76"
7038+
integrity sha512-NUHSYoe5XRTk/Are8jPJ6phzBh3l9l33nEyXosM17QInoV95/jng8+PuSGtbD407QoPf93MH3Bkh773OgesJpA==
7039+
70197040
70207041
version "4.0.0"
70217042
resolved "https://registry.npmjs.org/symbol-observable/-/symbol-observable-4.0.0.tgz"

0 commit comments

Comments
 (0)