Skip to content

Commit c68476d

Browse files
chore: merge pull request #168 from vndevteam/develop
chore: merge branch develop into main
2 parents 794392d + abbc8b4 commit c68476d

32 files changed

+2817
-437
lines changed

.env.docker

+6-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
##== Environment
22
NODE_ENV=development
3+
MODULES_SET=monolith
34

45
##== Application
56
APP_NAME="NestJS Boilerplate API"
@@ -10,7 +11,7 @@ API_PREFIX=api
1011
APP_FALLBACK_LANGUAGE=en
1112
APP_LOG_LEVEL=debug
1213
APP_LOG_SERVICE=console
13-
APP_CORS_ORIGIN=http://localhost:3000,https://ngockhuong.com
14+
APP_CORS_ORIGIN=http://localhost:3000,https://example.com
1415

1516
##== Database
1617
DATABASE_TYPE=postgres
@@ -28,14 +29,17 @@ DATABASE_CA=
2829
DATABASE_KEY=
2930
DATABASE_CERT=
3031

32+
##== Mailer
3133
MAIL_HOST=maildev
3234
MAIL_PORT=1025
3335
MAIL_USER=
3436
MAIL_PASSWORD=
3537
MAIL_IGNORE_TLS=true
3638
MAIL_SECURE=false
39+
MAIL_REQUIRE_TLS=false
3740
38-
MAIL_DEFAULT_NAME=Example
41+
MAIL_DEFAULT_NAME=No Reply
42+
MAIL_CLIENT_PORT=1080
3943

4044
##== Authentication
4145
AUTH_JWT_SECRET=secret

.env.example

+13-1
Original file line numberDiff line numberDiff line change
@@ -29,9 +29,21 @@ DATABASE_CA=
2929
DATABASE_KEY=
3030
DATABASE_CERT=
3131

32+
##== Mailer
33+
MAIL_HOST=localhost
34+
MAIL_PORT=1025
35+
MAIL_USER=
36+
MAIL_PASSWORD=
37+
MAIL_IGNORE_TLS=true
38+
MAIL_SECURE=false
39+
MAIL_REQUIRE_TLS=false
40+
MAIL_DEFAULT_EMAIL=[email protected]
41+
MAIL_DEFAULT_NAME=No Reply
42+
MAIL_CLIENT_PORT=1080
43+
3244
##== Authentication
3345
AUTH_JWT_SECRET=secret
34-
AUTH_JWT_TOKEN_EXPIRES_IN=15m
46+
AUTH_JWT_TOKEN_EXPIRES_IN=1d
3547
AUTH_REFRESH_SECRET=secret_for_refresh
3648
AUTH_REFRESH_TOKEN_EXPIRES_IN=365d
3749
AUTH_FORGOT_SECRET=secret_for_forgot

.vscode/settings.json

+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
{
2+
"sqltools.connections": [
3+
{
4+
"previewLimit": 50,
5+
"server": "localhost",
6+
"port": 25432,
7+
"driver": "PostgreSQL",
8+
"name": "nestjs_boilerplate",
9+
"database": "nestjs_boilerplate",
10+
"username": "postgres",
11+
"password": "postgres"
12+
}
13+
]
14+
}

Dockerfile

+4-1
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,12 @@ RUN npm install -g pnpm
1414
FROM base AS builder
1515
WORKDIR /app
1616

17-
COPY . .
1817
COPY package*.json pnpm-lock.yaml ./
1918

19+
RUN pnpm install
20+
21+
COPY . .
22+
2023
RUN pnpm build
2124

2225
######################

README.md

+3-3
Original file line numberDiff line numberDiff line change
@@ -59,10 +59,10 @@ $ pnpm start:prod
5959
## Features
6060

6161
- [x] Database. Support [TypeORM](https://www.npmjs.com/package/typeorm)
62-
- [x] Seeding.
62+
- [x] Seeding ([Typeorm Extension](https://www.npmjs.com/package/typeorm-extension)).
6363
- [x] Config Service ([@nestjs/config](https://www.npmjs.com/package/@nestjs/config)).
64-
- [ ] Mailing ([nodemailer](https://www.npmjs.com/package/nodemailer)).
65-
- [ ] Sign in and sign up via email.
64+
- [x] Mailing ([@nestjs-modules/mailer](https://www.npmjs.com/package/@nestjs-modules/mailer) & [nodemailer](https://www.npmjs.com/package/nodemailer)).
65+
- [x] Sign in and sign up via email.
6666
- [ ] Social sign in (Apple, Facebook, Google, Twitter).
6767
- [ ] Admin and User roles.
6868
- [x] Pagination: Offset and Cursor (Clone from [typeorm-cursor-pagination](https://github.com/benjamin658/typeorm-cursor-pagination) and add more features).

docker-compose.yml

+14-2
Original file line numberDiff line numberDiff line change
@@ -28,15 +28,27 @@ services:
2828
- "25432:5432"
2929
networks:
3030
- nestjs-boilerplate-network
31+
32+
maildev:
33+
build:
34+
context: .
35+
dockerfile: maildev.Dockerfile
36+
ports:
37+
- ${MAIL_CLIENT_PORT}:1080
38+
- ${MAIL_PORT}:1025
39+
3140
pgadmin:
3241
container_name: pgadmin
3342
image: dpage/pgadmin4
3443
ports:
3544
- "18080:80"
3645
volumes:
3746
- pgadmin_data:/root/.pgadmin
38-
env_file:
39-
- .env
47+
environment:
48+
PGADMIN_DEFAULT_EMAIL: [email protected]
49+
PGADMIN_DEFAULT_PASSWORD: 12345678
50+
PGADMIN_CONFIG_WTF_CSRF_ENABLED: "False"
51+
PGADMIN_CONFIG_ENHANCED_COOKIE_PROTECTION: "False"
4052
networks:
4153
- nestjs-boilerplate-network
4254

docs/README.md

+16-1
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,20 @@ This is a boilerplate for NestJS projects. It is a starting point for building a
2222

2323
## Features
2424

25-
// TODO: Add features
25+
- [x] Database. Support [TypeORM](https://www.npmjs.com/package/typeorm)
26+
- [x] Seeding ([Typeorm Extension](https://www.npmjs.com/package/typeorm-extension)).
27+
- [x] Config Service ([@nestjs/config](https://www.npmjs.com/package/@nestjs/config)).
28+
- [x] Mailing ([@nestjs-modules/mailer](https://www.npmjs.com/package/@nestjs-modules/mailer) & [nodemailer](https://www.npmjs.com/package/nodemailer)).
29+
- [x] Sign in and sign up via email.
30+
- [ ] Social sign in (Apple, Facebook, Google, Twitter).
31+
- [ ] Admin and User roles.
32+
- [x] Pagination: Offset and Cursor (Clone from [typeorm-cursor-pagination](https://github.com/benjamin658/typeorm-cursor-pagination) and add more features).
33+
- [x] Internationalization/Translations (I18N) ([nestjs-i18n](https://www.npmjs.com/package/nestjs-i18n)).
34+
- [ ] File uploads. Support local and Amazon S3 drivers.
35+
- [x] Swagger.
36+
- [ ] E2E and units tests.
37+
- [x] Docker.
38+
- [x] CI (Github Actions).
2639

2740
## References
2841

@@ -31,6 +44,8 @@ This is a boilerplate for NestJS projects. It is a starting point for building a
3144
- [NestJS I18n](https://nestjs-i18n.com/)
3245
- [TypeORM](https://typeorm.io/)
3346
- [TypeORM Extension](https://typeorm-extension.tada5hi.net/)
47+
- [Nodemailer](https://nodemailer.com/)
48+
- [NestJS Mailer](https://nest-modules.github.io/mailer/)
3449
- [Jest](https://jestjs.io/)
3550
- [PNPM](https://pnpm.io/)
3651
- [ESLint](https://eslint.org/)

docs/troubleshooting.md

+59-13
Original file line numberDiff line numberDiff line change
@@ -6,25 +6,71 @@ This page contains common issues and solutions for the project.
66

77
[[toc]]
88

9-
## Error when running the application: `An instance of EnvironmentVariablesValidator has failed the validation`
9+
## Issues when running the application
10+
11+
### An instance of EnvironmentVariablesValidator has failed the validation
1012

1113
When running the application, you may encounter an error similar to the following:
1214

13-
```bash
14-
An instance of EnvironmentVariablesValidator has failed the validation:
15-
- property NODE_ENV has failed the following constraints: isEnum
16-
,An instance of EnvironmentVariablesValidator has failed the validation:
17-
- property APP_LOG_SERVICE has failed the following constraints: isEnum
15+
```bash
16+
An instance of EnvironmentVariablesValidator has failed the validation:
17+
- property NODE_ENV has failed the following constraints: isEnum
18+
,An instance of EnvironmentVariablesValidator has failed the validation:
19+
- property APP_LOG_SERVICE has failed the following constraints: isEnum
1820

19-
[Nest] 19929 - 07/20/2024, 12:24:53 PM LOG [NestFactory] Starting Nest application...
20-
[Nest] 19929 - 07/20/2024, 12:24:53 PM ERROR [ExceptionHandler]
21-
Error in NODE_ENV:
22-
+ isEnum: NODE_ENV must be one of the following values: local, development, staging, production, test
21+
[Nest] 19929 - 07/20/2024, 12:24:53 PM LOG [NestFactory] Starting Nest application...
22+
[Nest] 19929 - 07/20/2024, 12:24:53 PM ERROR [ExceptionHandler]
23+
Error in NODE_ENV:
24+
+ isEnum: NODE_ENV must be one of the following values: local, development, staging, production, test
2325

24-
Error in APP_LOG_SERVICE:
25-
+ isEnum: APP_LOG_SERVICE must be one of the following values: console, google_logging, aws_cloudwatch
26-
```
26+
Error in APP_LOG_SERVICE:
27+
+ isEnum: APP_LOG_SERVICE must be one of the following values: console, google_logging, aws_cloudwatch
28+
```
2729

2830
This error occurs when the environment variables are not set correctly. Ensure that the `.env` file is correctly set up with the required environment variables. You can copy the `.env.example` file and rename it to `.env` to set up the environment variables.
2931

32+
### Unable to connect to the database. Retrying
33+
34+
```bash
35+
❯ pnpm start
36+
37+
> [email protected] start /Users/lamngockhuong/develop/projects/vndevteam/nestjs-boilerplate
38+
> nest start
39+
40+
✔ TSC Initializing type checker...
41+
> TSC Found 0 issues.
42+
> SWC Running...
43+
Successfully compiled: 108 files with swc (77.67ms)
44+
[Nest] 73686 - 07/31/2024, 7:25:23 AM LOG [NestFactory] Starting Nest application...
45+
[Nest] 73686 - 07/31/2024, 7:25:23 AM LOG [InstanceLoader] AppModule dependencies initialized +2ms
46+
[Nest] 73686 - 07/31/2024, 7:25:23 AM LOG [InstanceLoader] ApiModule dependencies initialized +0ms
47+
[Nest] 73686 - 07/31/2024, 7:25:23 AM LOG [InstanceLoader] TypeOrmModule dependencies initialized +0ms
48+
[Nest] 73686 - 07/31/2024, 7:25:23 AM LOG [InstanceLoader] HttpModule dependencies initialized +0ms
49+
[Nest] 73686 - 07/31/2024, 7:25:23 AM LOG [InstanceLoader] JwtModule dependencies initialized +0ms
50+
[Nest] 73686 - 07/31/2024, 7:25:23 AM LOG [InstanceLoader] HomeModule dependencies initialized +0ms
51+
[Nest] 73686 - 07/31/2024, 7:25:23 AM LOG [InstanceLoader] ConfigHostModule dependencies initialized +0ms
52+
[Nest] 73686 - 07/31/2024, 7:25:23 AM LOG [InstanceLoader] TerminusModule dependencies initialized +0ms
53+
[Nest] 73686 - 07/31/2024, 7:25:23 AM LOG [InstanceLoader] ConfigModule dependencies initialized +0ms
54+
[Nest] 73686 - 07/31/2024, 7:25:23 AM LOG [InstanceLoader] ConfigModule dependencies initialized +0ms
55+
[Nest] 73686 - 07/31/2024, 7:25:23 AM LOG [InstanceLoader] PostModule dependencies initialized +0ms
56+
[Nest] 73686 - 07/31/2024, 7:25:23 AM LOG [InstanceLoader] HealthModule dependencies initialized +0ms
57+
[Nest] 73686 - 07/31/2024, 7:25:23 AM LOG [InstanceLoader] LoggerModule dependencies initialized +1ms
58+
[Nest] 73686 - 07/31/2024, 7:25:23 AM ERROR [TypeOrmModule] Unable to connect to the database. Retrying (1)...
59+
AggregateError
60+
at __node_internal_ (node:internal/errors:174:15)
61+
at internalConnectMultiple (node:net:1114:18)
62+
at afterConnectMultiple (node:net:1667:5)
63+
[Nest] 73686 - 07/31/2024, 7:25:23 AM LOG [InstanceLoader] I18nModule dependencies initialized +0ms
64+
[Nest] 73686 - 07/31/2024, 7:25:23 AM ERROR [TypeOrmModule] Unable to connect to the database. Retrying (2)...
65+
AggregateError
66+
at __node_internal_ (node:internal/errors:174:15)
67+
at internalConnectMultiple (node:net:1114:18)
68+
at afterConnectMultiple (node:net:1667:5)
69+
...
70+
```
71+
72+
This error occurs when the application is unable to connect to the database. Ensure that the database is running and the connection details are correctly set up in the `.env` file.
73+
74+
---
75+
3076
Please refer to the [Configuration](./development.md#configuration) section for more information on setting up the environment variables.

jest.config.json

+1
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
"^@/guards(.*)$": "<rootDir>/guards$1",
2929
"^@/interceptors(.*)$": "<rootDir>/interceptors$1",
3030
"^@/libs(.*)$": "<rootDir>/libs$1",
31+
"^@/mail(.*)$": "<rootDir>/mail$1",
3132
"^@/shared(.*)$": "<rootDir>/shared$1",
3233
"^@/utils(.*)$": "<rootDir>/utils$1"
3334
},

maildev.Dockerfile

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
FROM node:20.16.0-alpine
2+
3+
RUN npm i -g [email protected]
4+
5+
CMD maildev

nest-cli.json

+4-1
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,9 @@
66
"builder": "swc",
77
"typeCheck": true,
88
"deleteOutDir": true,
9-
"assets": [{ "include": "i18n/**/*", "watchAssets": true }]
9+
"assets": [
10+
{ "include": "i18n/**/*", "watchAssets": true },
11+
{ "include": "**/*.hbs", "watchAssets": true }
12+
]
1013
}
1114
}

package.json

+7-6
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333
"docs:build": "vuepress build docs"
3434
},
3535
"dependencies": {
36+
"@nestjs-modules/mailer": "2.0.2",
3637
"@nestjs/axios": "3.0.2",
3738
"@nestjs/common": "10.3.10",
3839
"@nestjs/config": "3.2.3",
@@ -44,7 +45,7 @@
4445
"@nestjs/terminus": "10.2.3",
4546
"@nestjs/typeorm": "10.0.2",
4647
"argon2": "0.40.3",
47-
"axios": "1.7.2",
48+
"axios": "1.7.3",
4849
"class-transformer": "0.5.1",
4950
"class-validator": "0.14.1",
5051
"compression": "1.7.4",
@@ -71,13 +72,13 @@
7172
"@nestjs/schematics": "10.1.3",
7273
"@nestjs/testing": "10.3.10",
7374
"@swc/cli": "0.4.0",
74-
"@swc/core": "1.7.3",
75+
"@swc/core": "1.7.5",
7576
"@types/compression": "1.7.5",
7677
"@types/eslint__js": "8.42.3",
7778
"@types/express": "4.17.21",
7879
"@types/jest": "29.5.12",
7980
"@types/ms": "0.7.34",
80-
"@types/node": "20.14.13",
81+
"@types/node": "20.14.14",
8182
"@types/nodemailer": "6.4.15",
8283
"@types/supertest": "6.0.2",
8384
"@types/uuid": "10.0.0",
@@ -95,14 +96,14 @@
9596
"prettier-plugin-organize-imports": "4.0.0",
9697
"source-map-support": "0.5.21",
9798
"supertest": "7.0.0",
98-
"ts-jest": "29.2.3",
99+
"ts-jest": "29.2.4",
99100
"ts-loader": "9.5.1",
100101
"ts-node": "10.9.2",
101102
"tsconfig-paths": "4.2.0",
102103
"tslib": "2.6.3",
103104
"typescript": "5.5.4",
104-
"typescript-eslint": "7.18.0",
105-
"vue": "3.4.34",
105+
"typescript-eslint": "8.0.0",
106+
"vue": "3.4.35",
106107
"vuepress": "2.0.0-rc.14"
107108
}
108109
}

0 commit comments

Comments
 (0)