typescript-express-starter 8.1.2 → 9.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (83) hide show
  1. package/README.kr.md +25 -26
  2. package/README.md +28 -27
  3. package/lib/default/Makefile +26 -3
  4. package/lib/default/package.json +2 -2
  5. package/lib/graphql/.env.development.local +2 -2
  6. package/lib/graphql/.env.production.local +2 -2
  7. package/lib/graphql/.env.test.local +2 -2
  8. package/lib/graphql/Makefile +26 -3
  9. package/lib/graphql/package.json +2 -2
  10. package/lib/graphql/src/app.ts +6 -3
  11. package/lib/graphql/src/config/index.ts +2 -1
  12. package/lib/graphql/src/entities/users.entity.ts +1 -1
  13. package/lib/graphql/src/repositories/auth.repository.ts +1 -1
  14. package/lib/graphql/src/repositories/users.repository.ts +1 -1
  15. package/lib/knex/Makefile +26 -3
  16. package/lib/knex/package.json +2 -2
  17. package/lib/mikro-orm/.dockerignore +18 -0
  18. package/lib/mikro-orm/.editorconfig +9 -0
  19. package/lib/mikro-orm/.env.development.local +18 -0
  20. package/lib/mikro-orm/.env.production.local +18 -0
  21. package/lib/mikro-orm/.env.test.local +18 -0
  22. package/lib/mikro-orm/.eslintignore +1 -0
  23. package/lib/mikro-orm/.eslintrc +18 -0
  24. package/lib/mikro-orm/.huskyrc +5 -0
  25. package/lib/mikro-orm/.lintstagedrc.json +5 -0
  26. package/lib/mikro-orm/.prettierrc +8 -0
  27. package/lib/mikro-orm/.swcrc +41 -0
  28. package/lib/mikro-orm/.vscode/launch.json +35 -0
  29. package/lib/mikro-orm/.vscode/settings.json +6 -0
  30. package/lib/mikro-orm/Dockerfile +24 -0
  31. package/lib/mikro-orm/Makefile +29 -0
  32. package/lib/mikro-orm/docker-compose.yml +46 -0
  33. package/lib/mikro-orm/ecosystem.config.js +57 -0
  34. package/lib/mikro-orm/jest.config.js +12 -0
  35. package/lib/mikro-orm/nginx.conf +40 -0
  36. package/lib/mikro-orm/nodemon.json +12 -0
  37. package/lib/mikro-orm/package.json +77 -0
  38. package/lib/mikro-orm/src/app.ts +98 -0
  39. package/lib/mikro-orm/src/config/index.ts +5 -0
  40. package/lib/mikro-orm/src/controllers/auth.controller.ts +46 -0
  41. package/lib/mikro-orm/src/controllers/index.controller.ts +13 -0
  42. package/lib/mikro-orm/src/controllers/users.controller.ts +65 -0
  43. package/lib/mikro-orm/src/databases/index.ts +19 -0
  44. package/lib/mikro-orm/src/dtos/users.dto.ts +9 -0
  45. package/lib/mikro-orm/src/entities/base.entity.ts +16 -0
  46. package/lib/mikro-orm/src/entities/users.entity.ts +17 -0
  47. package/lib/mikro-orm/src/exceptions/HttpException.ts +10 -0
  48. package/lib/mikro-orm/src/http/auth.http +32 -0
  49. package/lib/mikro-orm/src/http/users.http +34 -0
  50. package/lib/mikro-orm/src/interfaces/auth.interface.ts +15 -0
  51. package/lib/mikro-orm/src/interfaces/routes.interface.ts +6 -0
  52. package/lib/mikro-orm/src/interfaces/users.interface.ts +5 -0
  53. package/lib/mikro-orm/src/middlewares/auth.middleware.ts +32 -0
  54. package/lib/mikro-orm/src/middlewares/error.middleware.ts +17 -0
  55. package/lib/mikro-orm/src/middlewares/validation.middleware.ts +25 -0
  56. package/lib/mikro-orm/src/routes/auth.route.ts +24 -0
  57. package/lib/mikro-orm/src/routes/index.route.ts +19 -0
  58. package/lib/mikro-orm/src/routes/users.route.ts +25 -0
  59. package/lib/mikro-orm/src/server.ts +11 -0
  60. package/lib/mikro-orm/src/services/auth.service.ts +63 -0
  61. package/lib/mikro-orm/src/services/users.service.ts +68 -0
  62. package/lib/mikro-orm/src/tests/auth.test.ts +66 -0
  63. package/lib/mikro-orm/src/tests/index.test.ts +18 -0
  64. package/lib/mikro-orm/src/tests/users.test.ts +70 -0
  65. package/lib/mikro-orm/src/utils/logger.ts +65 -0
  66. package/lib/mikro-orm/src/utils/util.ts +19 -0
  67. package/lib/mikro-orm/src/utils/validateEnv.ts +10 -0
  68. package/lib/mikro-orm/swagger.yaml +122 -0
  69. package/lib/mikro-orm/tsconfig.json +41 -0
  70. package/lib/mongoose/Makefile +26 -3
  71. package/lib/mongoose/package.json +2 -2
  72. package/lib/prisma/Makefile +26 -3
  73. package/lib/prisma/package.json +2 -2
  74. package/lib/routing-controllers/Makefile +26 -3
  75. package/lib/routing-controllers/package.json +2 -2
  76. package/lib/sequelize/Makefile +26 -3
  77. package/lib/sequelize/package.json +2 -2
  78. package/lib/starter.js +30 -8
  79. package/lib/typegoose/Makefile +26 -3
  80. package/lib/typegoose/package.json +3 -3
  81. package/lib/typeorm/Makefile +26 -3
  82. package/lib/typeorm/package.json +2 -2
  83. package/package.json +6 -15
package/README.kr.md CHANGED
@@ -9,6 +9,12 @@
9
9
 
10
10
  <h4 align="center">🚀 타입스크립트 기반의 익스프레스 보일러 플레이트 스타터 패키지</h4>
11
11
 
12
+ <p align ="center">
13
+ <a href="https://nodei.co/npm/typescript-express-starter" target="_blank">
14
+ <img src="https://nodei.co/npm/typescript-express-starter.png" alt="npm 정보" />
15
+ </a>
16
+ </p>
17
+
12
18
  <p align="center">
13
19
  <a href="http://npm.im/typescript-express-starter" target="_blank">
14
20
  <img src="https://img.shields.io/npm/v/typescript-express-starter.svg" alt="npm 버전" />
@@ -46,16 +52,6 @@
46
52
  - [🇺🇸 영어](https://github.com/ljlm0402/typescript-express-starter/blob/master/README.md)
47
53
  - [🇰🇷 한국어](https://github.com/ljlm0402/typescript-express-starter/blob/master/README.kr.md)
48
54
 
49
- > 번역을 도와주실 분은 [이슈](https://github.com/ljlm0402/typescript-express-starter/issues/new?assignees=ljlm0402&labels=%F0%9F%92%B1+Translations&template=translations-language---.md&title=) 남겨주시기 바랍니다. 💜
50
-
51
- <br />
52
-
53
- ## 웹 사이트 - 프로젝트 소개 및 홍보
54
-
55
- - [💁🏻‍♂️ Dylan Iqbal :: A TypeScript Express Starter App](https://bit.ly/3rrZFZ9)
56
-
57
- > 웹 사이트 및 블로그에 소개를 원하시는 분은 [이슈](https://github.com/ljlm0402/typescript-express-starter/issues/new?assignees=ljlm0402&labels=%F0%9F%91%80+Introducetion&template=introducetion-project---.md&title=) 남겨주시기 바랍니다. 💙
58
-
59
55
  <br />
60
56
 
61
57
  ## 😎 프로젝트를 소개합니다.
@@ -96,17 +92,19 @@ $ npx typescript-express-starter "project name"
96
92
 
97
93
  #### 템플릿 종류
98
94
 
99
- | 이름 | 설명 |
100
- | :------------------ | :------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ |
101
- | Default | Express 기본 |
102
- | Routing Controllers | 데코레이터 사용량이 많은 구조화되고 선언적이며 아름답게 구성된 클래스 기반 컨트롤러 생성 |
103
- | Sequelize | PostgreSQL, MySQL, MariaDB, SQLite, Microsoft SQL Server를 지원하는 Promise 패턴 기반의 Node.js ORM |
104
- | Mongoose | Node.js와 MongoDB를 위한 ODM(Object Data Mapping) 라이브러리 |
105
- | TypeORM | 자바스크립트, 타입스크립트과 함께 사용되어 Node.js, React Native, Expo에서 실행될 수 있는 ORM |
106
- | Prisma | 데이터베이스에 데이터를 프로그래밍 언어의 객체와 매핑하여 기존에 SQL로 작성하던 데이터를 수정, 테이블 구조 변경등의 작업을 객체를 통해 프로그래밍적으로 할 수 있도록 해주는 ORM |
107
- | Knex | 쿼리 빌더를 위한 라이브러리 |
108
- | GraphQL | API 용 쿼리 언어이며 기존 데이터로 이러한 쿼리를 수행하기위한 런타임 |
109
- | Typegoose | 타입스크립트 클래스를 사용하여 몽구스 모델 정의 |
95
+ | 이름 | 설명 |
96
+ | :-------------------------------------------------------------------------------------- | :------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ |
97
+ | Default | Express 기본 |
98
+ | [Routing Controllers](https://github.com/typestack/routing-controllers) | 데코레이터 사용량이 많은 구조화되고 선언적이며 아름답게 구성된 클래스 기반 컨트롤러 생성 |
99
+ | [Sequelize](https://github.com/sequelize/sequelize) | PostgreSQL, MySQL, MariaDB, SQLite, Microsoft SQL Server를 지원하는 Promise 패턴 기반의 Node.js ORM |
100
+ | [Mongoose](https://github.com/Automattic/mongoose) | Node.js와 MongoDB를 위한 ODM(Object Data Mapping) 라이브러리 |
101
+ | [TypeORM](https://github.com/typeorm/typeorm) | 자바스크립트, 타입스크립트과 함께 사용되어 Node.js, React Native, Expo에서 실행될 수 있는 ORM |
102
+ | [Prisma](https://github.com/prisma/prisma) | 데이터베이스에 데이터를 프로그래밍 언어의 객체와 매핑하여 기존에 SQL로 작성하던 데이터를 수정, 테이블 구조 변경등의 작업을 객체를 통해 프로그래밍적으로 할 수 있도록 해주는 ORM |
103
+ | [Knex](https://github.com/knex/knex) | 쿼리 빌더를 위한 라이브러리 |
104
+ | [GraphQL](https://github.com/graphql/graphql-js) | API 용 쿼리 언어이며 기존 데이터로 이러한 쿼리를 수행하기위한 런타임 |
105
+ | [Typegoose](https://github.com/typegoose/typegoose) | 타입스크립트 클래스를 사용하여 몽구스 모델 정의 |
106
+ | [Mikro ORM](https://github.com/mikro-orm/mikro-orm) | 데이터 매퍼, 작업 단위 및 아이덴티티 맵 패턴을 기반으로 하는 Node.js용 TypeScript ORM. MongoDB, MySQL, MariaDB, PostgreSQL 및 SQLite 데이터베이스를 지원 |
107
+ | [Sequelize Typescript](https://github.com/RobinBuschmann/sequelize-typescript) (개발중) | 데코레이터 및 Sequelize를 위한 몇 가지 기능 |
110
108
 
111
109
  ## 🛎 Script 명령어
112
110
 
@@ -237,10 +235,8 @@ VSCode Extension에서 [REST Client](https://marketplace.visualstudio.com/items?
237
235
  │ └── settings.json
238
236
 
239
237
  ├── /src
240
- │ ├── /configs
241
- │ │ ├── development.json
242
- │ │ ├── production.json
243
- │ │ └── test.json
238
+ │ ├── /config
239
+ │ │ └── index.ts
244
240
  │ │
245
241
  │ ├── /controllers
246
242
  │ │ ├── auth.controller.ts
@@ -290,7 +286,6 @@ VSCode Extension에서 [REST Client](https://marketplace.visualstudio.com/items?
290
286
  │ │ └── vaildateEnv.ts
291
287
  │ │
292
288
  │ ├── app.ts
293
- │ ├── index.ts
294
289
  │ └── server.ts
295
290
 
296
291
  ├── .dockerignore
@@ -372,6 +367,10 @@ VSCode Extension에서 [REST Client](https://marketplace.visualstudio.com/items?
372
367
 
373
368
  - David Stewart [https://github.com/davidjmstewart](https://github.com/davidjmstewart)
374
369
 
370
+ - JagTheFriend [JagTheFriend](https://github.com/JagTheFriend)
371
+
372
+ - Tamzid Karim [Tamzid Karim](https://github.com/tamzidkarim)
373
+
375
374
  ## 💳 라이센스
376
375
 
377
376
  [MIT](LICENSE)
package/README.md CHANGED
@@ -9,6 +9,12 @@
9
9
 
10
10
  <h4 align="center">🚀 Express RESTful API Boilerplate Using TypeScript</h4>
11
11
 
12
+ <p align ="center">
13
+ <a href="https://nodei.co/npm/typescript-express-starter" target="_blank">
14
+ <img src="https://nodei.co/npm/typescript-express-starter.png" alt="npm Info" />
15
+ </a>
16
+ </p>
17
+
12
18
  <p align="center">
13
19
  <a href="http://npm.im/typescript-express-starter" target="_blank">
14
20
  <img src="https://img.shields.io/npm/v/typescript-express-starter.svg" alt="npm Version" />
@@ -46,16 +52,6 @@
46
52
  - [🇺🇸 English](https://github.com/ljlm0402/typescript-express-starter/blob/master/README.md)
47
53
  - [🇰🇷 Korean](https://github.com/ljlm0402/typescript-express-starter/blob/master/README.kr.md)
48
54
 
49
- > Want to translate to your own language? please open an [issue](https://github.com/ljlm0402/typescript-express-starter/issues/new?assignees=ljlm0402&labels=%F0%9F%92%B1+Translations&template=translations-language---.md&title=) 💜
50
-
51
- <br />
52
-
53
- ## Web Site - Project Introduction
54
-
55
- - [💁🏻‍♂️ Dylan Iqbal :: A TypeScript Express Starter App](https://bit.ly/3rrZFZ9)
56
-
57
- > Want to be featured on your blog or site? please open an [issue](https://github.com/ljlm0402/typescript-express-starter/issues/new?assignees=ljlm0402&labels=%F0%9F%91%80+Introducetion&template=introducetion-project---.md&title=) 💙
58
-
59
55
  <br />
60
56
 
61
57
  ## 😎 Introducing The Project
@@ -100,17 +96,19 @@ Start your typescript-express-starter app in development mode at `http://localho
100
96
 
101
97
  #### Template Type
102
98
 
103
- | Name | Description |
104
- | :------------------ | :----------------------------------------------------------------------------------------------------------- |
105
- | Default | Express Default |
106
- | Routing Controllers | Create structured, declarative and beautifully organized class-based controllers with heavy decorators usage |
107
- | Sequelize | Easy to use multi SQL dialect ORM for Node.js |
108
- | Mongoose | MongoDB Object Modeling(ODM) designed to work in an asynchronous environment |
109
- | TypeORM | An ORM that can run in Node.js and Others |
110
- | Prisma | Modern Database Access for TypeScript & Node.js |
111
- | Knex | SQL query builder for Postgres, MySQL, MariaDB, SQLite3 and Oracle |
112
- | GraphQL | query language for APIs and a runtime for fulfilling those queries with your existing data |
113
- | Typegoose | Define Mongoose models using TypeScript classes |
99
+ | Name | Description |
100
+ | :--------------------------------------------------------------------------------------- | :--------------------------------------------------------------------------------------------------------------------------------------------------------- |
101
+ | Default | Express Default |
102
+ | [Routing Controllers](https://github.com/typestack/routing-controllers) | Create structured, declarative and beautifully organized class-based controllers with heavy decorators usage |
103
+ | [Sequelize](https://github.com/sequelize/sequelize) | Easy to use multi SQL dialect ORM for Node.js |
104
+ | [Mongoose](https://github.com/Automattic/mongoose) | MongoDB Object Modeling(ODM) designed to work in an asynchronous environment |
105
+ | [TypeORM](https://github.com/typeorm/typeorm) | An ORM that can run in Node.js and Others |
106
+ | [Prisma](https://github.com/prisma/prisma) | Modern Database Access for TypeScript & Node.js |
107
+ | [Knex](https://github.com/knex/knex) | SQL query builder for Postgres, MySQL, MariaDB, SQLite3 and Oracle |
108
+ | [GraphQL](https://github.com/graphql/graphql-js) | query language for APIs and a runtime for fulfilling those queries with your existing data |
109
+ | [Typegoose](https://github.com/typegoose/typegoose) | Define Mongoose models using TypeScript classes |
110
+ | [Mikro ORM](https://github.com/mikro-orm/mikro-orm) | TypeScript ORM for Node.js based on Data Mapper, Unit of Work and Identity Map patterns. Supports MongoDB, MySQL, MariaDB, PostgreSQL and SQLite databases |
111
+ | [Sequelize Typescript](https://github.com/RobinBuschmann/sequelize-typescript) (Develop) | Decorators and some other features for sequelize |
114
112
 
115
113
  ## 🛎 Available Commands for the Server
116
114
 
@@ -242,10 +240,8 @@ Modify `.swcrc` file to your source code.
242
240
  │ └── settings.json
243
241
 
244
242
  ├── /src
245
- │ ├── /configs
246
- │ │ ├── development.json
247
- │ │ ├── production.json
248
- │ │ └── test.json
243
+ │ ├── /config
244
+ │ │ └── index.ts
249
245
  │ │
250
246
  │ ├── /controllers
251
247
  │ │ ├── auth.controller.ts
@@ -295,12 +291,13 @@ Modify `.swcrc` file to your source code.
295
291
  │ │ └── vaildateEnv.ts
296
292
  │ │
297
293
  │ ├── app.ts
298
- │ ├── index.ts
299
294
  │ └── server.ts
300
295
 
301
296
  ├── .dockerignore
302
297
  ├── .editorconfig
303
- ├── .env
298
+ ├── .env.development.local
299
+ ├── .env.production.local
300
+ ├── .env.test.local
304
301
  ├── .eslintignore
305
302
  ├── .eslintrc
306
303
  ├── .gitignore
@@ -377,6 +374,10 @@ Modify `.swcrc` file to your source code.
377
374
 
378
375
  - David Stewart [https://github.com/davidjmstewart](https://github.com/davidjmstewart)
379
376
 
377
+ - JagTheFriend [JagTheFriend](https://github.com/JagTheFriend)
378
+
379
+ - Tamzid Karim [Tamzid Karim](https://github.com/tamzidkarim)
380
+
380
381
  ## 💳 License
381
382
 
382
383
  [MIT](LICENSE)
@@ -1,6 +1,29 @@
1
+ # app name should be overridden.
2
+ # ex) production-stage: make build APP_NAME=<APP_NAME>
3
+ # ex) development-stage: make build-dev APP_NAME=<APP_NAME>
4
+
5
+ APP_NAME = typescript-express
6
+ APP_NAME := $(APP_NAME)
7
+
8
+ .PHONY: build
9
+ # Build the container image - Dvelopment
10
+ build-dev:
11
+ docker build -t ${APP_NAME}\
12
+ --target development-build-stage\
13
+ -f Dockerfile .
14
+
15
+ # Build the container image - Production
1
16
  build:
2
- docker build -t ${tag} .
17
+ docker build -t ${APP_NAME}\
18
+ --target production-build-stage\
19
+ -f Dockerfile .
20
+
21
+ # Clean the container image
3
22
  clean:
4
- docker rmi -f ${tag}
23
+ docker rmi -f ${APP_NAME}
24
+
25
+ # Run the container image
5
26
  run:
6
- docker run -d -p ${port}:${port} --name ${name} ${tag}
27
+ docker run -d -it -p 3000:3000 ${APP_NAME}
28
+
29
+ all: build
@@ -7,8 +7,8 @@
7
7
  "scripts": {
8
8
  "start": "npm run build && cross-env NODE_ENV=production node dist/server.js",
9
9
  "dev": "cross-env NODE_ENV=development nodemon",
10
- "build": "tsc && tsc-alias",
11
- "build:swc": "swc src -d dist --source-maps --copy-files",
10
+ "build": "swc src -d dist --source-maps --copy-files",
11
+ "build:tsc": "tsc && tsc-alias",
12
12
  "test": "jest --forceExit --detectOpenHandles",
13
13
  "lint": "eslint --ignore-path .gitignore --ext .ts src/",
14
14
  "lint:fix": "npm run lint -- --fix",
@@ -3,7 +3,7 @@ PORT = 3000
3
3
 
4
4
  # DATABASE
5
5
  DB_HOST = localhost
6
- DB_PORT = 3306
6
+ DB_PORT = 5432
7
7
  DB_USER = root
8
8
  DB_PASSWORD = password
9
9
  DB_DATABASE = test
@@ -16,5 +16,5 @@ LOG_FORMAT = dev
16
16
  LOG_DIR = ../logs
17
17
 
18
18
  # CORS
19
- ORIGIN = *
19
+ ORIGIN = true
20
20
  CREDENTIALS = true
@@ -3,7 +3,7 @@ PORT = 3000
3
3
 
4
4
  # DATABASE
5
5
  DB_HOST = localhost
6
- DB_PORT = 3306
6
+ DB_PORT = 5432
7
7
  DB_USER = root
8
8
  DB_PASSWORD = password
9
9
  DB_DATABASE = test
@@ -16,5 +16,5 @@ LOG_FORMAT = combined
16
16
  LOG_DIR = ../logs
17
17
 
18
18
  # CORS
19
- ORIGIN = your.domain.com
19
+ ORIGIN = false
20
20
  CREDENTIALS = true
@@ -3,7 +3,7 @@ PORT = 3000
3
3
 
4
4
  # DATABASE
5
5
  DB_HOST = localhost
6
- DB_PORT = 3306
6
+ DB_PORT = 5432
7
7
  DB_USER = root
8
8
  DB_PASSWORD = password
9
9
  DB_DATABASE = test
@@ -16,5 +16,5 @@ LOG_FORMAT = dev
16
16
  LOG_DIR = ../logs
17
17
 
18
18
  # CORS
19
- ORIGIN = *
19
+ ORIGIN = true
20
20
  CREDENTIALS = true
@@ -1,6 +1,29 @@
1
+ # app name should be overridden.
2
+ # ex) production-stage: make build APP_NAME=<APP_NAME>
3
+ # ex) development-stage: make build-dev APP_NAME=<APP_NAME>
4
+
5
+ APP_NAME = typescript-express
6
+ APP_NAME := $(APP_NAME)
7
+
8
+ .PHONY: build
9
+ # Build the container image - Dvelopment
10
+ build-dev:
11
+ docker build -t ${APP_NAME}\
12
+ --target development-build-stage\
13
+ -f Dockerfile .
14
+
15
+ # Build the container image - Production
1
16
  build:
2
- docker build -t ${tag} .
17
+ docker build -t ${APP_NAME}\
18
+ --target production-build-stage\
19
+ -f Dockerfile .
20
+
21
+ # Clean the container image
3
22
  clean:
4
- docker rmi -f ${tag}
23
+ docker rmi -f ${APP_NAME}
24
+
25
+ # Run the container image
5
26
  run:
6
- docker run -d -p ${port}:${port} --name ${name} ${tag}
27
+ docker run -d -it -p 3000:3000 ${APP_NAME}
28
+
29
+ all: build
@@ -7,8 +7,8 @@
7
7
  "scripts": {
8
8
  "start": "npm run build && cross-env NODE_ENV=production node dist/server.js",
9
9
  "dev": "cross-env NODE_ENV=development nodemon",
10
- "build": "tsc && tsc-alias",
11
- "build:swc": "swc src -d dist --source-maps --copy-files",
10
+ "build": "swc src -d dist --source-maps --copy-files",
11
+ "build:tsc": "tsc && tsc-alias",
12
12
  "test": "jest --forceExit --detectOpenHandles",
13
13
  "lint": "eslint --ignore-path .gitignore --ext .ts src/",
14
14
  "lint:fix": "npm run lint -- --fix",
@@ -50,9 +50,12 @@ class App {
50
50
  }
51
51
 
52
52
  private initializeMiddlewares() {
53
+ if (this.env === 'production') {
54
+ this.app.use(hpp());
55
+ this.app.use(helmet());
56
+ }
57
+
53
58
  this.app.use(cors({ origin: ORIGIN, credentials: CREDENTIALS }));
54
- this.app.use(hpp());
55
- this.app.use(helmet());
56
59
  this.app.use(compression());
57
60
  this.app.use(express.json());
58
61
  this.app.use(express.urlencoded({ extended: true }));
@@ -68,7 +71,7 @@ class App {
68
71
  const apolloServer = new ApolloServer({
69
72
  schema: schema,
70
73
  plugins: [
71
- NODE_ENV === 'production'
74
+ this.env === 'production'
72
75
  ? ApolloServerPluginLandingPageProductionDefault({ footer: false })
73
76
  : ApolloServerPluginLandingPageLocalDefault({ footer: false }),
74
77
  ],
@@ -2,4 +2,5 @@ import { config } from 'dotenv';
2
2
  config({ path: `.env.${process.env.NODE_ENV || 'development'}.local` });
3
3
 
4
4
  export const CREDENTIALS = process.env.CREDENTIALS === 'true';
5
- export const { NODE_ENV, PORT, DB_HOST, DB_PORT, DB_USER, DB_PASSWORD, DB_DATABASE, SECRET_KEY, LOG_FORMAT, LOG_DIR, ORIGIN } = process.env;
5
+ export const ORIGIN = process.env.ORIGIN === 'true';
6
+ export const { NODE_ENV, PORT, DB_HOST, DB_PORT, DB_USER, DB_PASSWORD, DB_DATABASE, SECRET_KEY, LOG_FORMAT, LOG_DIR } = process.env;
@@ -9,7 +9,7 @@ export class UserEntity extends BaseEntity implements User {
9
9
 
10
10
  @Column()
11
11
  @IsNotEmpty()
12
- @Unique()
12
+ @Unique(['email'])
13
13
  email: string;
14
14
 
15
15
  @Column()
@@ -18,7 +18,7 @@ export default class AuthRepository {
18
18
  if (findUser) throw new HttpException(409, `You're email ${userData.email} already exists`);
19
19
 
20
20
  const hashedPassword = await hash(userData.password, 10);
21
- const createUserData: User = await UserEntity.save({ ...userData, password: hashedPassword });
21
+ const createUserData: User = await UserEntity.create({ ...userData, password: hashedPassword }).save();
22
22
 
23
23
  return createUserData;
24
24
  }
@@ -30,7 +30,7 @@ export default class UserRepository {
30
30
  if (findUser) throw new HttpException(409, `You're email ${userData.email} already exists`);
31
31
 
32
32
  const hashedPassword = await hash(userData.password, 10);
33
- const createUserData: User = await UserEntity.save({ ...userData, password: hashedPassword });
33
+ const createUserData: User = await UserEntity.create({ ...userData, password: hashedPassword }).save();
34
34
 
35
35
  return createUserData;
36
36
  }
package/lib/knex/Makefile CHANGED
@@ -1,6 +1,29 @@
1
+ # app name should be overridden.
2
+ # ex) production-stage: make build APP_NAME=<APP_NAME>
3
+ # ex) development-stage: make build-dev APP_NAME=<APP_NAME>
4
+
5
+ APP_NAME = typescript-express
6
+ APP_NAME := $(APP_NAME)
7
+
8
+ .PHONY: build
9
+ # Build the container image - Dvelopment
10
+ build-dev:
11
+ docker build -t ${APP_NAME}\
12
+ --target development-build-stage\
13
+ -f Dockerfile .
14
+
15
+ # Build the container image - Production
1
16
  build:
2
- docker build -t ${tag} .
17
+ docker build -t ${APP_NAME}\
18
+ --target production-build-stage\
19
+ -f Dockerfile .
20
+
21
+ # Clean the container image
3
22
  clean:
4
- docker rmi -f ${tag}
23
+ docker rmi -f ${APP_NAME}
24
+
25
+ # Run the container image
5
26
  run:
6
- docker run -d -p ${port}:${port} --name ${name} ${tag}
27
+ docker run -d -it -p 3000:3000 ${APP_NAME}
28
+
29
+ all: build
@@ -7,8 +7,8 @@
7
7
  "scripts": {
8
8
  "start": "npm run build && cross-env NODE_ENV=production node dist/server.js",
9
9
  "dev": "cross-env NODE_ENV=development nodemon",
10
- "build": "tsc && tsc-alias",
11
- "build:swc": "swc src -d dist --source-maps --copy-files",
10
+ "build": "swc src -d dist --source-maps --copy-files",
11
+ "build:tsc": "tsc && tsc-alias",
12
12
  "test": "jest --forceExit --detectOpenHandles",
13
13
  "lint": "eslint --ignore-path .gitignore --ext .ts src/",
14
14
  "lint:fix": "npm run lint -- --fix",
@@ -0,0 +1,18 @@
1
+ # compiled output
2
+ .vscode
3
+ /node_modules
4
+
5
+ # code formatter
6
+ .eslintrc
7
+ .eslintignore
8
+ .editorconfig
9
+ .huskyrc
10
+ .lintstagedrc.json
11
+ .prettierrc
12
+
13
+ # test
14
+ jest.config.js
15
+
16
+ # docker
17
+ Dockerfile
18
+ docker-compose.yml
@@ -0,0 +1,9 @@
1
+ root = true
2
+
3
+ [*]
4
+ indent_style = space
5
+ indent_size = 2
6
+ end_of_line = lf
7
+ charset = utf-8
8
+ trim_trailing_whitespace = true
9
+ insert_final_newline = true
@@ -0,0 +1,18 @@
1
+ # PORT
2
+ PORT = 3000
3
+
4
+ # DATABASE
5
+ DB_HOST = localhost
6
+ DB_PORT = 27017
7
+ DB_DATABASE = dev
8
+
9
+ # TOKEN
10
+ SECRET_KEY = secretKey
11
+
12
+ # LOG
13
+ LOG_FORMAT = dev
14
+ LOG_DIR = ../logs
15
+
16
+ # CORS
17
+ ORIGIN = *
18
+ CREDENTIALS = true
@@ -0,0 +1,18 @@
1
+ # PORT
2
+ PORT = 3000
3
+
4
+ # DATABASE
5
+ DB_HOST = localhost
6
+ DB_PORT = 27017
7
+ DB_DATABASE = prod
8
+
9
+ # TOKEN
10
+ SECRET_KEY = secretKey
11
+
12
+ # LOG
13
+ LOG_FORMAT = combined
14
+ LOG_DIR = ../logs
15
+
16
+ # CORS
17
+ ORIGIN = your.domain.com
18
+ CREDENTIALS = true
@@ -0,0 +1,18 @@
1
+ # PORT
2
+ PORT = 3000
3
+
4
+ # DATABASE
5
+ DB_HOST = localhost
6
+ DB_PORT = 27017
7
+ DB_DATABASE = test
8
+
9
+ # TOKEN
10
+ SECRET_KEY = secretKey
11
+
12
+ # LOG
13
+ LOG_FORMAT = dev
14
+ LOG_DIR = ../logs
15
+
16
+ # CORS
17
+ ORIGIN = *
18
+ CREDENTIALS = true
@@ -0,0 +1 @@
1
+ /dist
@@ -0,0 +1,18 @@
1
+ {
2
+ "parser": "@typescript-eslint/parser",
3
+ "extends": ["prettier", "plugin:@typescript-eslint/recommended", "plugin:prettier/recommended"],
4
+ "parserOptions": {
5
+ "ecmaVersion": 2018,
6
+ "sourceType": "module"
7
+ },
8
+ "rules": {
9
+ "@typescript-eslint/explicit-member-accessibility": 0,
10
+ "@typescript-eslint/explicit-function-return-type": 0,
11
+ "@typescript-eslint/no-parameter-properties": 0,
12
+ "@typescript-eslint/interface-name-prefix": 0,
13
+ "@typescript-eslint/explicit-module-boundary-types": 0,
14
+ "@typescript-eslint/no-explicit-any": "off",
15
+ "@typescript-eslint/ban-types": "off",
16
+ "@typescript-eslint/no-var-requires": "off"
17
+ }
18
+ }
@@ -0,0 +1,5 @@
1
+ {
2
+ "hooks": {
3
+ "pre-commit": "lint-staged"
4
+ }
5
+ }
@@ -0,0 +1,5 @@
1
+ {
2
+ "*.ts": [
3
+ "npm run lint"
4
+ ]
5
+ }
@@ -0,0 +1,8 @@
1
+ {
2
+ "printWidth": 150,
3
+ "tabWidth": 2,
4
+ "singleQuote": true,
5
+ "trailingComma": "all",
6
+ "semi": true,
7
+ "arrowParens": "avoid"
8
+ }
@@ -0,0 +1,41 @@
1
+ {
2
+ "jsc": {
3
+ "parser": {
4
+ "syntax": "typescript",
5
+ "tsx": false,
6
+ "dynamicImport": true,
7
+ "decorators": true
8
+ },
9
+ "transform": {
10
+ "legacyDecorator": true,
11
+ "decoratorMetadata": true
12
+ },
13
+ "target": "es2017",
14
+ "externalHelpers": false,
15
+ "keepClassNames": true,
16
+ "loose": false,
17
+ "minify": {
18
+ "compress": false,
19
+ "mangle": false
20
+ },
21
+ "baseUrl": "src",
22
+ "paths": {
23
+ "@/*": ["*"],
24
+ "@config": ["config"],
25
+ "@controllers/*": ["controllers/*"],
26
+ "@databases": ["databases"],
27
+ "@dtos/*": ["dtos/*"],
28
+ "@entities/*": ["entities/*"],
29
+ "@exceptions/*": ["exceptions/*"],
30
+ "@interfaces/*": ["interfaces/*"],
31
+ "@middlewares/*": ["middlewares/*"],
32
+ "@models/*": ["models/*"],
33
+ "@routes/*": ["routes/*"],
34
+ "@services/*": ["services/*"],
35
+ "@utils/*": ["utils/*"]
36
+ }
37
+ },
38
+ "module": {
39
+ "type": "commonjs"
40
+ }
41
+ }