typescript-express-starter 6.2.1 → 8.0.1

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 (222) hide show
  1. package/README.kr.md +55 -26
  2. package/README.md +54 -25
  3. package/bin/cli.js +4 -3
  4. package/lib/default/.swcrc +41 -0
  5. package/lib/default/nodemon.json +2 -2
  6. package/lib/default/package.json +12 -8
  7. package/lib/default/src/app.ts +1 -2
  8. package/lib/default/src/http/auth.http +12 -15
  9. package/lib/default/src/http/users.http +12 -16
  10. package/lib/default/src/index.ts +1 -0
  11. package/lib/default/src/middlewares/auth.middleware.ts +3 -3
  12. package/lib/default/src/models/users.model.ts +5 -5
  13. package/lib/default/src/server.ts +1 -2
  14. package/lib/default/src/services/auth.service.ts +5 -5
  15. package/lib/default/src/services/users.service.ts +3 -3
  16. package/lib/default/src/tests/auth.test.ts +4 -4
  17. package/lib/default/src/tests/users.test.ts +4 -4
  18. package/lib/default/src/utils/logger.ts +5 -5
  19. package/lib/default/tsconfig.json +2 -2
  20. package/lib/graphql/.dockerignore +18 -0
  21. package/lib/graphql/.editorconfig +9 -0
  22. package/lib/graphql/.env +1 -0
  23. package/lib/graphql/.eslintignore +1 -0
  24. package/lib/graphql/.eslintrc +18 -0
  25. package/lib/graphql/.huskyrc +5 -0
  26. package/lib/graphql/.lintstagedrc.json +5 -0
  27. package/lib/graphql/.prettierrc +8 -0
  28. package/lib/graphql/.swcrc +39 -0
  29. package/lib/graphql/.vscode/launch.json +35 -0
  30. package/lib/graphql/.vscode/settings.json +6 -0
  31. package/lib/graphql/Dockerfile +24 -0
  32. package/lib/graphql/Makefile +6 -0
  33. package/lib/graphql/docker-compose.yml +50 -0
  34. package/lib/graphql/ecosystem.config.js +59 -0
  35. package/lib/graphql/jest.config.js +12 -0
  36. package/lib/graphql/nginx.conf +40 -0
  37. package/lib/graphql/nodemon.json +12 -0
  38. package/lib/graphql/package.json +79 -0
  39. package/lib/graphql/src/app.ts +105 -0
  40. package/lib/graphql/src/configs/development.json +19 -0
  41. package/lib/graphql/src/configs/production.json +19 -0
  42. package/lib/graphql/src/configs/test.json +19 -0
  43. package/lib/graphql/src/databases/index.ts +24 -0
  44. package/lib/graphql/src/dtos/users.dto.ts +14 -0
  45. package/lib/{typeorm/src/entity → graphql/src/entities}/users.entity.ts +3 -3
  46. package/lib/graphql/src/exceptions/HttpException.ts +10 -0
  47. package/lib/graphql/src/http/auth.http +49 -0
  48. package/lib/graphql/src/http/users.http +78 -0
  49. package/lib/graphql/src/index.ts +1 -0
  50. package/lib/graphql/src/interfaces/auth.interface.ts +14 -0
  51. package/lib/graphql/src/interfaces/db.interface.ts +7 -0
  52. package/lib/graphql/src/interfaces/users.interface.ts +5 -0
  53. package/lib/graphql/src/middlewares/auth.middleware.ts +32 -0
  54. package/lib/graphql/src/middlewares/error.middleware.ts +17 -0
  55. package/lib/graphql/src/repositories/auth.repository.ts +61 -0
  56. package/lib/graphql/src/repositories/users.repository.ts +60 -0
  57. package/lib/graphql/src/resolvers/auth.resolver.ts +32 -0
  58. package/lib/graphql/src/resolvers/users.resolver.ts +47 -0
  59. package/lib/graphql/src/server.ts +14 -0
  60. package/lib/graphql/src/tests/auth.test.ts +52 -0
  61. package/lib/graphql/src/tests/index.test.ts +18 -0
  62. package/lib/graphql/src/tests/users.test.ts +71 -0
  63. package/lib/graphql/src/typedefs/users.type.ts +13 -0
  64. package/lib/graphql/src/utils/logger.ts +75 -0
  65. package/lib/graphql/src/utils/util.ts +19 -0
  66. package/lib/graphql/src/utils/validateEnv.ts +10 -0
  67. package/lib/graphql/tsconfig.json +39 -0
  68. package/lib/knex/.swcrc +39 -0
  69. package/lib/knex/knexfile.ts +6 -6
  70. package/lib/knex/nodemon.json +2 -2
  71. package/lib/knex/package.json +11 -8
  72. package/lib/knex/src/app.ts +2 -3
  73. package/lib/knex/src/databases/index.ts +6 -6
  74. package/lib/knex/src/http/auth.http +12 -15
  75. package/lib/knex/src/http/users.http +12 -16
  76. package/lib/knex/src/index.ts +1 -0
  77. package/lib/knex/src/middlewares/auth.middleware.ts +4 -4
  78. package/lib/knex/src/server.ts +1 -2
  79. package/lib/knex/src/services/auth.service.ts +5 -5
  80. package/lib/knex/src/services/users.service.ts +3 -3
  81. package/lib/knex/src/tests/auth.test.ts +2 -2
  82. package/lib/knex/src/tests/index.test.ts +1 -1
  83. package/lib/knex/src/tests/users.test.ts +2 -2
  84. package/lib/knex/src/utils/logger.ts +5 -5
  85. package/lib/knex/tsconfig.json +2 -2
  86. package/lib/mongoose/.swcrc +39 -0
  87. package/lib/mongoose/docker-compose.yml +0 -4
  88. package/lib/mongoose/nodemon.json +2 -2
  89. package/lib/mongoose/package.json +12 -8
  90. package/lib/mongoose/src/app.ts +2 -3
  91. package/lib/mongoose/src/configs/development.json +1 -1
  92. package/lib/mongoose/src/configs/production.json +1 -1
  93. package/lib/mongoose/src/configs/test.json +1 -1
  94. package/lib/mongoose/src/http/auth.http +32 -0
  95. package/lib/mongoose/src/http/users.http +34 -0
  96. package/lib/mongoose/src/index.ts +1 -0
  97. package/lib/mongoose/src/middlewares/auth.middleware.ts +3 -3
  98. package/lib/mongoose/src/server.ts +1 -2
  99. package/lib/mongoose/src/services/auth.service.ts +5 -5
  100. package/lib/mongoose/src/services/users.service.ts +3 -3
  101. package/lib/mongoose/src/utils/logger.ts +5 -5
  102. package/lib/mongoose/tsconfig.json +2 -2
  103. package/lib/prisma/.env +1 -1
  104. package/lib/prisma/.swcrc +37 -0
  105. package/lib/prisma/docker-compose.yml +1 -6
  106. package/lib/prisma/nodemon.json +2 -2
  107. package/lib/prisma/package.json +14 -10
  108. package/lib/prisma/src/app.ts +2 -3
  109. package/lib/prisma/src/http/auth.http +12 -15
  110. package/lib/prisma/src/http/users.http +12 -16
  111. package/lib/prisma/src/index.ts +1 -0
  112. package/lib/prisma/src/middlewares/auth.middleware.ts +4 -4
  113. package/lib/prisma/src/server.ts +1 -2
  114. package/lib/prisma/src/services/auth.service.ts +5 -5
  115. package/lib/prisma/src/services/users.service.ts +3 -3
  116. package/lib/prisma/src/utils/logger.ts +5 -5
  117. package/lib/prisma/tsconfig.json +2 -2
  118. package/lib/routing-controllers/.swcrc +37 -0
  119. package/lib/routing-controllers/nodemon.json +2 -2
  120. package/lib/routing-controllers/package.json +12 -9
  121. package/lib/routing-controllers/src/app.ts +3 -4
  122. package/lib/routing-controllers/src/http/auth.http +12 -15
  123. package/lib/routing-controllers/src/http/users.http +12 -16
  124. package/lib/routing-controllers/src/index.ts +1 -0
  125. package/lib/routing-controllers/src/middlewares/auth.middleware.ts +3 -3
  126. package/lib/routing-controllers/src/middlewares/validation.middleware.ts +10 -2
  127. package/lib/routing-controllers/src/models/users.model.ts +5 -5
  128. package/lib/routing-controllers/src/server.ts +1 -3
  129. package/lib/routing-controllers/src/services/auth.service.ts +5 -5
  130. package/lib/routing-controllers/src/services/users.service.ts +3 -3
  131. package/lib/routing-controllers/src/utils/logger.ts +5 -5
  132. package/lib/routing-controllers/tsconfig.json +2 -2
  133. package/lib/sequelize/.swcrc +39 -0
  134. package/lib/sequelize/docker-compose.yml +1 -6
  135. package/lib/sequelize/nodemon.json +2 -2
  136. package/lib/sequelize/package.json +12 -8
  137. package/lib/sequelize/src/app.ts +1 -2
  138. package/lib/sequelize/src/configs/development.json +2 -2
  139. package/lib/sequelize/src/configs/production.json +1 -1
  140. package/lib/sequelize/src/configs/test.json +1 -1
  141. package/lib/sequelize/src/http/auth.http +32 -0
  142. package/lib/sequelize/src/http/users.http +34 -0
  143. package/lib/sequelize/src/index.ts +1 -0
  144. package/lib/sequelize/src/middlewares/auth.middleware.ts +4 -4
  145. package/lib/sequelize/src/server.ts +1 -2
  146. package/lib/sequelize/src/services/auth.service.ts +5 -5
  147. package/lib/sequelize/src/services/users.service.ts +3 -3
  148. package/lib/sequelize/src/utils/logger.ts +5 -5
  149. package/lib/sequelize/tsconfig.json +2 -2
  150. package/lib/starter.js +4 -6
  151. package/lib/typegoose/.dockerignore +18 -0
  152. package/lib/typegoose/.editorconfig +9 -0
  153. package/lib/typegoose/.env.development.local +18 -0
  154. package/lib/typegoose/.env.production.local +18 -0
  155. package/lib/typegoose/.env.test.local +18 -0
  156. package/lib/typegoose/.eslintignore +1 -0
  157. package/lib/typegoose/.eslintrc +18 -0
  158. package/lib/typegoose/.huskyrc +5 -0
  159. package/lib/typegoose/.lintstagedrc.json +5 -0
  160. package/lib/typegoose/.prettierrc +8 -0
  161. package/lib/typegoose/.swcrc +40 -0
  162. package/lib/typegoose/.vscode/launch.json +35 -0
  163. package/lib/typegoose/.vscode/settings.json +6 -0
  164. package/lib/typegoose/Dockerfile +24 -0
  165. package/lib/typegoose/Makefile +6 -0
  166. package/lib/typegoose/docker-compose.yml +46 -0
  167. package/lib/typegoose/ecosystem.config.js +57 -0
  168. package/lib/typegoose/jest.config.js +12 -0
  169. package/lib/typegoose/nginx.conf +40 -0
  170. package/lib/typegoose/nodemon.json +12 -0
  171. package/lib/typegoose/package.json +80 -0
  172. package/lib/typegoose/src/app.ts +93 -0
  173. package/lib/typegoose/src/config/index.ts +5 -0
  174. package/lib/typegoose/src/controllers/auth.controller.ts +46 -0
  175. package/lib/typegoose/src/controllers/index.controller.ts +13 -0
  176. package/lib/typegoose/src/controllers/users.controller.ts +65 -0
  177. package/lib/typegoose/src/databases/index.ts +3 -0
  178. package/lib/typegoose/src/dtos/users.dto.ts +9 -0
  179. package/lib/typegoose/src/exceptions/HttpException.ts +10 -0
  180. package/lib/typegoose/src/http/auth.http +32 -0
  181. package/lib/typegoose/src/http/users.http +34 -0
  182. package/lib/typegoose/src/interfaces/auth.interface.ts +15 -0
  183. package/lib/typegoose/src/interfaces/routes.interface.ts +6 -0
  184. package/lib/typegoose/src/interfaces/users.interface.ts +5 -0
  185. package/lib/typegoose/src/middlewares/auth.middleware.ts +32 -0
  186. package/lib/typegoose/src/middlewares/error.middleware.ts +17 -0
  187. package/lib/typegoose/src/middlewares/validation.middleware.ts +25 -0
  188. package/lib/typegoose/src/models/users.model.ts +18 -0
  189. package/lib/typegoose/src/routes/auth.route.ts +24 -0
  190. package/lib/typegoose/src/routes/index.route.ts +19 -0
  191. package/lib/typegoose/src/routes/users.route.ts +25 -0
  192. package/lib/typegoose/src/server.ts +11 -0
  193. package/lib/typegoose/src/services/auth.service.ts +61 -0
  194. package/lib/typegoose/src/services/users.service.ts +64 -0
  195. package/lib/typegoose/src/tests/auth.test.ts +83 -0
  196. package/lib/typegoose/src/tests/index.test.ts +18 -0
  197. package/lib/typegoose/src/tests/users.test.ts +133 -0
  198. package/lib/typegoose/src/utils/logger.ts +65 -0
  199. package/lib/typegoose/src/utils/util.ts +19 -0
  200. package/lib/typegoose/src/utils/validateEnv.ts +10 -0
  201. package/lib/typegoose/swagger.yaml +122 -0
  202. package/lib/typegoose/tsconfig.json +40 -0
  203. package/lib/typeorm/.swcrc +39 -0
  204. package/lib/typeorm/docker-compose.yml +1 -1
  205. package/lib/typeorm/nodemon.json +2 -2
  206. package/lib/typeorm/package.json +12 -8
  207. package/lib/typeorm/src/app.ts +1 -2
  208. package/lib/typeorm/src/configs/development.json +1 -1
  209. package/lib/typeorm/src/configs/production.json +1 -1
  210. package/lib/typeorm/src/configs/test.json +1 -1
  211. package/lib/typeorm/src/databases/index.ts +5 -5
  212. package/lib/typeorm/src/entities/users.entity.ts +26 -0
  213. package/lib/typeorm/src/http/auth.http +12 -15
  214. package/lib/typeorm/src/http/users.http +12 -16
  215. package/lib/typeorm/src/index.ts +1 -0
  216. package/lib/typeorm/src/middlewares/auth.middleware.ts +5 -9
  217. package/lib/typeorm/src/server.ts +1 -2
  218. package/lib/typeorm/src/services/auth.service.ts +13 -17
  219. package/lib/typeorm/src/services/users.service.ts +16 -22
  220. package/lib/typeorm/src/utils/logger.ts +5 -5
  221. package/lib/typeorm/tsconfig.json +3 -3
  222. package/package.json +14 -4
@@ -0,0 +1,39 @@
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
+ "@controllers/*": ["controllers/*"],
25
+ "@databases": ["databases"],
26
+ "@dtos/*": ["dtos/*"],
27
+ "@exceptions/*": ["exceptions/*"],
28
+ "@interfaces/*": ["interfaces/*"],
29
+ "@middlewares/*": ["middlewares/*"],
30
+ "@models/*": ["models/*"],
31
+ "@routes/*": ["routes/*"],
32
+ "@services/*": ["services/*"],
33
+ "@utils/*": ["utils/*"]
34
+ }
35
+ },
36
+ "module": {
37
+ "type": "commonjs"
38
+ }
39
+ }
@@ -19,11 +19,6 @@ services:
19
19
  container_name: server
20
20
  ports:
21
21
  - '3000:3000'
22
- environment:
23
- MYSQL_USER: root
24
- MYSQL_PASSWORD: password
25
- MYSQL_HOST: mysql
26
- MYSQL_DATABASE: sequelize
27
22
  volumes:
28
23
  - ./:/app
29
24
  - /app/node_modules
@@ -40,7 +35,7 @@ services:
40
35
  environment:
41
36
  MYSQL_ROOT_USER: root
42
37
  MYSQL_ROOT_PASSWORD: password
43
- MYSQL_DATABASE: sequelize
38
+ MYSQL_DATABASE: test
44
39
  ports:
45
40
  - '3306:3306'
46
41
  networks:
@@ -5,8 +5,8 @@
5
5
  ],
6
6
  "ext": "js,ts,json",
7
7
  "ignore": [
8
- "src/**/*.spec.ts",
9
- "src/**/*.test.ts"
8
+ "src/logs/*",
9
+ "src/**/*.{spec,test}.ts"
10
10
  ],
11
11
  "exec": "ts-node -r tsconfig-paths/register --transpile-only src/server.ts"
12
12
  }
@@ -7,7 +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 && npx tsc-alias",
10
+ "build": "tsc && tsc-alias",
11
+ "build:swc": "swc src -d dist --source-maps --copy-files",
11
12
  "test": "jest --forceExit --detectOpenHandles",
12
13
  "lint": "eslint --ignore-path .gitignore --ext .ts src/",
13
14
  "lint:fix": "npm run lint -- --fix",
@@ -22,27 +23,23 @@
22
23
  "config": "^3.3.6",
23
24
  "cookie-parser": "^1.4.5",
24
25
  "cors": "^2.8.5",
25
- "cross-env": "^7.0.3",
26
26
  "dotenv": "^10.0.0",
27
27
  "envalid": "^7.1.0",
28
28
  "express": "^4.17.1",
29
29
  "helmet": "^4.6.0",
30
30
  "hpp": "^0.2.3",
31
- "jest": "^27.0.6",
32
31
  "jsonwebtoken": "^8.5.1",
33
32
  "morgan": "^1.10.0",
34
33
  "mysql2": "^2.2.5",
35
- "pm2": "^5.1.0",
36
34
  "sequelize": "^6.6.5",
37
35
  "swagger-jsdoc": "^6.0.0",
38
36
  "swagger-ui-express": "^4.1.6",
39
- "ts-jest": "^27.0.3",
40
- "ts-node": "^10.0.0",
41
- "typescript": "^4.3.5",
42
37
  "winston": "^3.3.3",
43
38
  "winston-daily-rotate-file": "^4.5.5"
44
39
  },
45
40
  "devDependencies": {
41
+ "@swc/cli": "^0.1.51",
42
+ "@swc/core": "^1.2.108",
46
43
  "@types/bcrypt": "^5.0.0",
47
44
  "@types/compression": "^1.7.1",
48
45
  "@types/config": "^0.0.39",
@@ -63,17 +60,24 @@
63
60
  "@types/winston": "^2.4.4",
64
61
  "@typescript-eslint/eslint-plugin": "^4.28.2",
65
62
  "@typescript-eslint/parser": "^4.28.2",
63
+ "cross-env": "^7.0.3",
66
64
  "eslint": "^7.30.0",
67
65
  "eslint-config-prettier": "^8.3.0",
68
66
  "eslint-plugin-prettier": "^3.4.0",
69
67
  "husky": "^7.0.1",
68
+ "jest": "^27.0.6",
70
69
  "lint-staged": "^11.0.0",
71
70
  "node-config": "^0.0.2",
72
71
  "node-gyp": "^8.1.0",
73
72
  "nodemon": "^2.0.9",
73
+ "pm2": "^5.1.0",
74
74
  "prettier": "^2.3.2",
75
75
  "sequelize-cli": "^6.2.0",
76
76
  "supertest": "^6.1.3",
77
- "tsconfig-paths": "^3.10.1"
77
+ "ts-jest": "^27.0.7",
78
+ "ts-node": "^10.4.0",
79
+ "tsc-alias": "^1.4.1",
80
+ "tsconfig-paths": "^3.10.1",
81
+ "typescript": "^4.5.2"
78
82
  }
79
83
  }
@@ -1,5 +1,4 @@
1
- process.env['NODE_CONFIG_DIR'] = __dirname + '/configs';
2
-
1
+ import '@/index';
3
2
  import compression from 'compression';
4
3
  import cookieParser from 'cookie-parser';
5
4
  import cors from 'cors';
@@ -1,10 +1,10 @@
1
1
  {
2
2
  "env": "development",
3
3
  "dbConfig": {
4
- "host": "mysql",
4
+ "host": "localhost",
5
5
  "user": "root",
6
6
  "password": "password",
7
- "database": "sequelize",
7
+ "database": "test",
8
8
  "pool": {
9
9
  "min": 0,
10
10
  "max": 5
@@ -4,7 +4,7 @@
4
4
  "host": "localhost",
5
5
  "user": "root",
6
6
  "password": "password",
7
- "database": "sequelize",
7
+ "database": "test",
8
8
  "pool": {
9
9
  "min": 0,
10
10
  "max": 5
@@ -4,7 +4,7 @@
4
4
  "host": "localhost",
5
5
  "user": "root",
6
6
  "password": "password",
7
- "database": "sequelize",
7
+ "database": "test",
8
8
  "pool": {
9
9
  "min": 0,
10
10
  "max": 5
@@ -0,0 +1,32 @@
1
+ # baseURL
2
+ @baseURL = http://localhost:3000
3
+
4
+ ###
5
+ # User Signup
6
+ POST {{ baseURL }}/signup
7
+ Content-Type: application/json
8
+
9
+ {
10
+ "email": "example@email.com",
11
+ "password": "password"
12
+ }
13
+
14
+ ###
15
+ # User Login
16
+ POST {{ baseURL }}/login
17
+ Content-Type: application/json
18
+
19
+ {
20
+ "email": "example@email.com",
21
+ "password": "password"
22
+ }
23
+
24
+ ###
25
+ # User Logout
26
+ POST {{ baseURL }}/logout
27
+ Content-Type: application/json
28
+
29
+ {
30
+ "email": "example@email.com",
31
+ "password": "password"
32
+ }
@@ -0,0 +1,34 @@
1
+ # baseURL
2
+ @baseURL = http://localhost:3000
3
+
4
+ ###
5
+ # Find All Users
6
+ GET {{ baseURL }}/users
7
+
8
+ ###
9
+ # Find User By Id
10
+ GET {{ baseURL }}/users/1
11
+
12
+ ###
13
+ # Create User
14
+ POST {{ baseURL }}/users
15
+ Content-Type: application/json
16
+
17
+ {
18
+ "email": "example@email.com",
19
+ "password": "password"
20
+ }
21
+
22
+ ###
23
+ # Modify User By Id
24
+ PUT {{ baseURL }}/users/1
25
+ Content-Type: application/json
26
+
27
+ {
28
+ "email": "example@email.com",
29
+ "password": "password"
30
+ }
31
+
32
+ ###
33
+ # Delete User By Id
34
+ DELETE {{ baseURL }}/users/1
@@ -0,0 +1 @@
1
+ process.env['NODE_CONFIG_DIR'] = __dirname + '/configs';
@@ -1,17 +1,17 @@
1
- import { NextFunction, Response } from 'express';
2
1
  import config from 'config';
3
- import jwt from 'jsonwebtoken';
2
+ import { NextFunction, Response } from 'express';
3
+ import { verify } from 'jsonwebtoken';
4
4
  import DB from '@databases';
5
5
  import { HttpException } from '@exceptions/HttpException';
6
6
  import { DataStoredInToken, RequestWithUser } from '@interfaces/auth.interface';
7
7
 
8
8
  const authMiddleware = async (req: RequestWithUser, res: Response, next: NextFunction) => {
9
9
  try {
10
- const Authorization = req.cookies['Authorization'] || req.header('Authorization').split('Bearer ')[1] || null;
10
+ const Authorization = req.cookies['Authorization'] || (req.header('Authorization') ? req.header('Authorization').split('Bearer ')[1] : null);
11
11
 
12
12
  if (Authorization) {
13
13
  const secretKey: string = config.get('secretKey');
14
- const verificationResponse = jwt.verify(Authorization, secretKey) as DataStoredInToken;
14
+ const verificationResponse = verify(Authorization, secretKey) as DataStoredInToken;
15
15
  const userId = verificationResponse.id;
16
16
  const findUser = await DB.Users.findByPk(userId);
17
17
 
@@ -1,6 +1,5 @@
1
- process.env['NODE_CONFIG_DIR'] = __dirname + '/configs';
2
-
3
1
  import 'dotenv/config';
2
+ import '@/index';
4
3
  import App from '@/app';
5
4
  import AuthRoute from '@routes/auth.route';
6
5
  import IndexRoute from '@routes/index.route';
@@ -1,6 +1,6 @@
1
- import bcrypt from 'bcrypt';
1
+ import { compare, hash } from 'bcrypt';
2
2
  import config from 'config';
3
- import jwt from 'jsonwebtoken';
3
+ import { sign } from 'jsonwebtoken';
4
4
  import DB from '@databases';
5
5
  import { CreateUserDto } from '@dtos/users.dto';
6
6
  import { HttpException } from '@exceptions/HttpException';
@@ -17,7 +17,7 @@ class AuthService {
17
17
  const findUser: User = await this.users.findOne({ where: { email: userData.email } });
18
18
  if (findUser) throw new HttpException(409, `You're email ${userData.email} already exists`);
19
19
 
20
- const hashedPassword = await bcrypt.hash(userData.password, 10);
20
+ const hashedPassword = await hash(userData.password, 10);
21
21
  const createUserData: User = await this.users.create({ ...userData, password: hashedPassword });
22
22
 
23
23
  return createUserData;
@@ -29,7 +29,7 @@ class AuthService {
29
29
  const findUser: User = await this.users.findOne({ where: { email: userData.email } });
30
30
  if (!findUser) throw new HttpException(409, `You're email ${userData.email} not found`);
31
31
 
32
- const isPasswordMatching: boolean = await bcrypt.compare(userData.password, findUser.password);
32
+ const isPasswordMatching: boolean = await compare(userData.password, findUser.password);
33
33
  if (!isPasswordMatching) throw new HttpException(409, "You're password not matching");
34
34
 
35
35
  const tokenData = this.createToken(findUser);
@@ -52,7 +52,7 @@ class AuthService {
52
52
  const secretKey: string = config.get('secretKey');
53
53
  const expiresIn: number = 60 * 60;
54
54
 
55
- return { expiresIn, token: jwt.sign(dataStoredInToken, secretKey, { expiresIn }) };
55
+ return { expiresIn, token: sign(dataStoredInToken, secretKey, { expiresIn }) };
56
56
  }
57
57
 
58
58
  public createCookie(tokenData: TokenData): string {
@@ -1,4 +1,4 @@
1
- import bcrypt from 'bcrypt';
1
+ import { hash } from 'bcrypt';
2
2
  import DB from '@databases';
3
3
  import { CreateUserDto } from '@dtos/users.dto';
4
4
  import { HttpException } from '@exceptions/HttpException';
@@ -28,7 +28,7 @@ class UserService {
28
28
  const findUser: User = await this.users.findOne({ where: { email: userData.email } });
29
29
  if (findUser) throw new HttpException(409, `You're email ${userData.email} already exists`);
30
30
 
31
- const hashedPassword = await bcrypt.hash(userData.password, 10);
31
+ const hashedPassword = await hash(userData.password, 10);
32
32
  const createUserData: User = await this.users.create({ ...userData, password: hashedPassword });
33
33
  return createUserData;
34
34
  }
@@ -39,7 +39,7 @@ class UserService {
39
39
  const findUser: User = await this.users.findByPk(userId);
40
40
  if (!findUser) throw new HttpException(409, "You're not user");
41
41
 
42
- const hashedPassword = await bcrypt.hash(userData.password, 10);
42
+ const hashedPassword = await hash(userData.password, 10);
43
43
  await this.users.update({ ...userData, password: hashedPassword }, { where: { id: userId } });
44
44
 
45
45
  const updateUser: User = await this.users.findByPk(userId);
@@ -1,14 +1,14 @@
1
1
  import config from 'config';
2
- import fs from 'fs';
3
- import path from 'path';
2
+ import { existsSync, mkdirSync } from 'fs';
3
+ import { join } from 'path';
4
4
  import winston from 'winston';
5
5
  import winstonDaily from 'winston-daily-rotate-file';
6
6
 
7
7
  // logs dir
8
- const logDir: string = path.join(__dirname, config.get('log.dir'));
8
+ const logDir: string = join(__dirname, config.get('log.dir'));
9
9
 
10
- if (!fs.existsSync(logDir)) {
11
- fs.mkdirSync(logDir);
10
+ if (!existsSync(logDir)) {
11
+ mkdirSync(logDir);
12
12
  }
13
13
 
14
14
  // Define log format
@@ -13,7 +13,7 @@
13
13
  "pretty": true,
14
14
  "sourceMap": true,
15
15
  "declaration": true,
16
- "outDir": "./dist",
16
+ "outDir": "dist",
17
17
  "allowJs": true,
18
18
  "noEmit": false,
19
19
  "esModuleInterop": true,
@@ -35,5 +35,5 @@
35
35
  }
36
36
  },
37
37
  "include": ["src/**/*.ts", "src/**/*.json", ".env"],
38
- "exclude": ["node_modules"]
38
+ "exclude": ["node_modules", "src/http", "src/logs", "src/tests"]
39
39
  }
package/lib/starter.js CHANGED
@@ -1,7 +1,8 @@
1
1
  /*****************************************************************
2
- * Create new typescript-express-starter project.
3
- * By AGUMON <ljlm0402@gmail.com>
4
- * December 18, 2019.
2
+ * Create Typescript Express Starter
3
+ * 2019.12.18 ~ 🎮
4
+ * Made By AGUMON 🦖
5
+ * https://github.com/ljlm0402/typescript-express-starter
5
6
  *****************************************************************/
6
7
 
7
8
  const chalk = require("chalk");
@@ -44,14 +45,11 @@ const createProject = async (projectName) => {
44
45
  spinner = ora();
45
46
  spinner.start();
46
47
 
47
- // manage node_modules
48
48
  await installNodeModules(projectName, spinner);
49
49
  isUpdated && (await updateNodeModules(projectName, spinner));
50
50
  isDeduped && (await dedupeNodeModules(projectName, spinner));
51
-
52
51
  await postInstallScripts(projectName, template, spinner);
53
52
 
54
- // set gitignore
55
53
  await createGitignore(projectName, spinner);
56
54
  await initGit(projectName);
57
55
 
@@ -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 = 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,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 = 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,40 @@
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
+ "@exceptions/*": ["exceptions/*"],
29
+ "@interfaces/*": ["interfaces/*"],
30
+ "@middlewares/*": ["middlewares/*"],
31
+ "@models/*": ["models/*"],
32
+ "@routes/*": ["routes/*"],
33
+ "@services/*": ["services/*"],
34
+ "@utils/*": ["utils/*"]
35
+ }
36
+ },
37
+ "module": {
38
+ "type": "commonjs"
39
+ }
40
+ }
@@ -0,0 +1,35 @@
1
+ {
2
+ "version": "0.2.0",
3
+ "configurations": [
4
+ {
5
+ "type": "node-terminal",
6
+ "request": "launch",
7
+ "name": "Dev typescript-express-starter",
8
+ "command": "npm run dev"
9
+ },
10
+ {
11
+ "type": "node-terminal",
12
+ "request": "launch",
13
+ "name": "Start typescript-express-starter",
14
+ "command": "npm run start"
15
+ },
16
+ {
17
+ "type": "node-terminal",
18
+ "request": "launch",
19
+ "name": "Test typescript-express-starter",
20
+ "command": "npm run test"
21
+ },
22
+ {
23
+ "type": "node-terminal",
24
+ "request": "launch",
25
+ "name": "Lint typescript-express-starter",
26
+ "command": "npm run lint"
27
+ },
28
+ {
29
+ "type": "node-terminal",
30
+ "request": "launch",
31
+ "name": "Lint:Fix typescript-express-starter",
32
+ "command": "npm run lint:fix"
33
+ }
34
+ ]
35
+ }
@@ -0,0 +1,6 @@
1
+ {
2
+ "editor.codeActionsOnSave": {
3
+ "source.fixAll.eslint": true
4
+ },
5
+ "editor.formatOnSave": false
6
+ }
@@ -0,0 +1,24 @@
1
+ # Common build stage
2
+ FROM node:14.14.0-alpine3.12 as common-build-stage
3
+
4
+ COPY . ./app
5
+
6
+ WORKDIR /app
7
+
8
+ RUN npm install
9
+
10
+ EXPOSE 3000
11
+
12
+ # Development build stage
13
+ FROM common-build-stage as development-build-stage
14
+
15
+ ENV NODE_ENV development
16
+
17
+ CMD ["npm", "run", "dev"]
18
+
19
+ # Production build stage
20
+ FROM common-build-stage as production-build-stage
21
+
22
+ ENV NODE_ENV production
23
+
24
+ CMD ["npm", "run", "start"]
@@ -0,0 +1,6 @@
1
+ build:
2
+ docker build -t ${tag} .
3
+ clean:
4
+ docker rmi -f ${tag}
5
+ run:
6
+ docker run -d -p ${port}:${port} --name ${name} ${tag}