typescript-express-starter 6.0.0 → 6.3.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 (143) hide show
  1. package/README.kr.md +133 -52
  2. package/README.md +134 -54
  3. package/bin/cli.js +4 -3
  4. package/lib/default/.swcrc +41 -0
  5. package/lib/default/Dockerfile +1 -1
  6. package/lib/default/ecosystem.config.js +40 -24
  7. package/lib/default/nodemon.json +2 -2
  8. package/lib/default/package.json +15 -8
  9. package/lib/default/src/app.ts +1 -2
  10. package/lib/default/src/http/auth.http +12 -15
  11. package/lib/default/src/http/users.http +12 -16
  12. package/lib/default/src/index.ts +1 -0
  13. package/lib/default/src/middlewares/auth.middleware.ts +3 -3
  14. package/lib/default/src/models/users.model.ts +5 -5
  15. package/lib/default/src/server.ts +1 -2
  16. package/lib/default/src/services/auth.service.ts +5 -5
  17. package/lib/default/src/services/users.service.ts +3 -3
  18. package/lib/default/src/tests/auth.test.ts +4 -4
  19. package/lib/default/src/tests/users.test.ts +4 -4
  20. package/lib/default/src/utils/logger.ts +5 -5
  21. package/lib/default/src/utils/util.ts +1 -1
  22. package/lib/default/tsconfig.json +2 -2
  23. package/lib/knex/.swcrc +39 -0
  24. package/lib/knex/Dockerfile +1 -1
  25. package/lib/knex/ecosystem.config.js +57 -43
  26. package/lib/knex/knexfile.ts +6 -6
  27. package/lib/knex/nodemon.json +2 -2
  28. package/lib/knex/package.json +14 -8
  29. package/lib/knex/src/app.ts +2 -3
  30. package/lib/knex/src/databases/index.ts +6 -6
  31. package/lib/knex/src/http/auth.http +12 -15
  32. package/lib/knex/src/http/users.http +12 -16
  33. package/lib/knex/src/index.ts +1 -0
  34. package/lib/knex/src/middlewares/auth.middleware.ts +4 -4
  35. package/lib/knex/src/server.ts +1 -2
  36. package/lib/knex/src/services/auth.service.ts +5 -5
  37. package/lib/knex/src/services/users.service.ts +3 -3
  38. package/lib/knex/src/tests/auth.test.ts +2 -2
  39. package/lib/knex/src/tests/index.test.ts +1 -1
  40. package/lib/knex/src/tests/users.test.ts +2 -2
  41. package/lib/knex/src/utils/logger.ts +5 -5
  42. package/lib/knex/src/utils/util.ts +1 -1
  43. package/lib/knex/tsconfig.json +2 -2
  44. package/lib/mongoose/.swcrc +39 -0
  45. package/lib/mongoose/Dockerfile +1 -1
  46. package/lib/mongoose/docker-compose.yml +0 -4
  47. package/lib/mongoose/ecosystem.config.js +42 -27
  48. package/lib/mongoose/nodemon.json +2 -2
  49. package/lib/mongoose/package.json +15 -8
  50. package/lib/mongoose/src/app.ts +2 -3
  51. package/lib/mongoose/src/configs/development.json +1 -1
  52. package/lib/mongoose/src/configs/production.json +1 -1
  53. package/lib/mongoose/src/configs/test.json +1 -1
  54. package/lib/mongoose/src/http/auth.http +32 -0
  55. package/lib/mongoose/src/http/users.http +34 -0
  56. package/lib/mongoose/src/index.ts +1 -0
  57. package/lib/mongoose/src/middlewares/auth.middleware.ts +3 -3
  58. package/lib/mongoose/src/server.ts +1 -2
  59. package/lib/mongoose/src/services/auth.service.ts +5 -5
  60. package/lib/mongoose/src/services/users.service.ts +3 -3
  61. package/lib/mongoose/src/utils/logger.ts +5 -5
  62. package/lib/mongoose/src/utils/util.ts +1 -1
  63. package/lib/mongoose/tsconfig.json +2 -2
  64. package/lib/prisma/.env +1 -1
  65. package/lib/prisma/.swcrc +37 -0
  66. package/lib/prisma/Dockerfile +1 -1
  67. package/lib/prisma/docker-compose.yml +1 -6
  68. package/lib/prisma/ecosystem.config.js +40 -24
  69. package/lib/prisma/nodemon.json +2 -2
  70. package/lib/prisma/package.json +17 -10
  71. package/lib/prisma/src/app.ts +2 -3
  72. package/lib/prisma/src/http/auth.http +12 -15
  73. package/lib/prisma/src/http/users.http +12 -16
  74. package/lib/prisma/src/index.ts +1 -0
  75. package/lib/prisma/src/middlewares/auth.middleware.ts +4 -4
  76. package/lib/prisma/src/server.ts +1 -2
  77. package/lib/prisma/src/services/auth.service.ts +5 -5
  78. package/lib/prisma/src/services/users.service.ts +3 -3
  79. package/lib/prisma/src/utils/logger.ts +5 -5
  80. package/lib/prisma/src/utils/util.ts +1 -1
  81. package/lib/prisma/tsconfig.json +2 -2
  82. package/lib/routing-controllers/.swcrc +37 -0
  83. package/lib/routing-controllers/Dockerfile +1 -1
  84. package/lib/routing-controllers/ecosystem.config.js +40 -24
  85. package/lib/routing-controllers/nodemon.json +2 -2
  86. package/lib/routing-controllers/package.json +18 -11
  87. package/lib/routing-controllers/src/app.ts +33 -6
  88. package/lib/routing-controllers/src/http/auth.http +12 -15
  89. package/lib/routing-controllers/src/http/users.http +12 -16
  90. package/lib/routing-controllers/src/index.ts +1 -0
  91. package/lib/routing-controllers/src/middlewares/auth.middleware.ts +3 -3
  92. package/lib/routing-controllers/src/middlewares/validation.middleware.ts +10 -2
  93. package/lib/routing-controllers/src/models/users.model.ts +5 -5
  94. package/lib/routing-controllers/src/server.ts +1 -3
  95. package/lib/routing-controllers/src/services/auth.service.ts +5 -5
  96. package/lib/routing-controllers/src/services/users.service.ts +3 -3
  97. package/lib/routing-controllers/src/utils/logger.ts +5 -5
  98. package/lib/routing-controllers/src/utils/util.ts +1 -1
  99. package/lib/routing-controllers/tsconfig.json +2 -2
  100. package/lib/sequelize/.swcrc +39 -0
  101. package/lib/sequelize/Dockerfile +1 -1
  102. package/lib/sequelize/docker-compose.yml +1 -6
  103. package/lib/sequelize/ecosystem.config.js +42 -27
  104. package/lib/sequelize/nodemon.json +2 -2
  105. package/lib/sequelize/package.json +15 -8
  106. package/lib/sequelize/src/app.ts +1 -2
  107. package/lib/sequelize/src/configs/development.json +2 -2
  108. package/lib/sequelize/src/configs/production.json +1 -1
  109. package/lib/sequelize/src/configs/test.json +1 -1
  110. package/lib/sequelize/src/http/auth.http +32 -0
  111. package/lib/sequelize/src/http/users.http +34 -0
  112. package/lib/sequelize/src/index.ts +1 -0
  113. package/lib/sequelize/src/middlewares/auth.middleware.ts +4 -4
  114. package/lib/sequelize/src/server.ts +1 -2
  115. package/lib/sequelize/src/services/auth.service.ts +5 -5
  116. package/lib/sequelize/src/services/users.service.ts +3 -3
  117. package/lib/sequelize/src/utils/logger.ts +5 -5
  118. package/lib/sequelize/src/utils/util.ts +1 -1
  119. package/lib/sequelize/tsconfig.json +2 -2
  120. package/lib/starter.js +8 -12
  121. package/lib/typeorm/.swcrc +39 -0
  122. package/lib/typeorm/Dockerfile +1 -1
  123. package/lib/typeorm/docker-compose.yml +1 -1
  124. package/lib/typeorm/ecosystem.config.js +42 -27
  125. package/lib/typeorm/nodemon.json +2 -2
  126. package/lib/typeorm/package.json +15 -8
  127. package/lib/typeorm/src/app.ts +1 -2
  128. package/lib/typeorm/src/configs/development.json +1 -1
  129. package/lib/typeorm/src/configs/production.json +1 -1
  130. package/lib/typeorm/src/configs/test.json +1 -1
  131. package/lib/typeorm/src/databases/index.ts +5 -5
  132. package/lib/typeorm/src/{entity → entities}/users.entity.ts +3 -3
  133. package/lib/typeorm/src/http/auth.http +12 -15
  134. package/lib/typeorm/src/http/users.http +12 -16
  135. package/lib/typeorm/src/index.ts +1 -0
  136. package/lib/typeorm/src/middlewares/auth.middleware.ts +5 -9
  137. package/lib/typeorm/src/server.ts +1 -2
  138. package/lib/typeorm/src/services/auth.service.ts +13 -17
  139. package/lib/typeorm/src/services/users.service.ts +16 -22
  140. package/lib/typeorm/src/utils/logger.ts +5 -5
  141. package/lib/typeorm/src/utils/util.ts +1 -1
  142. package/lib/typeorm/tsconfig.json +3 -3
  143. package/package.json +12 -4
@@ -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
@@ -9,7 +9,7 @@ export const isEmpty = (value: string | number | object): boolean => {
9
9
  return true;
10
10
  } else if (typeof value !== 'number' && value === '') {
11
11
  return true;
12
- } else if (value === 'undefined' || value === undefined) {
12
+ } else if (typeof value === 'undefined' || value === undefined) {
13
13
  return true;
14
14
  } else if (value !== null && typeof value === 'object' && !Object.keys(value).length) {
15
15
  return true;
@@ -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
 
@@ -153,7 +151,7 @@ const updatePackageJson = async (destination) => {
153
151
  */
154
152
  const installNodeModules = async (destination, spinner) => {
155
153
  spinner.text = "Install node_modules...\n";
156
- await asyncExec("npm install", { cwd: destination });
154
+ await asyncExec("npm install --legacy-peer-deps", { cwd: destination });
157
155
  };
158
156
 
159
157
  /**
@@ -162,7 +160,7 @@ const installNodeModules = async (destination, spinner) => {
162
160
  */
163
161
  const updateNodeModules = async (destination, spinner) => {
164
162
  spinner.text = "Update node_modules...\n";
165
- await asyncExec("npm update", { cwd: destination });
163
+ await asyncExec("npm update --legacy-peer-deps", { cwd: destination });
166
164
  };
167
165
 
168
166
  /**
@@ -171,7 +169,7 @@ const updateNodeModules = async (destination, spinner) => {
171
169
  */
172
170
  const dedupeNodeModules = async (destination, spinner) => {
173
171
  spinner.text = "Dedupe node_modules...\n";
174
- await asyncExec("npm dedupe", { cwd: destination });
172
+ await asyncExec("npm dedupe --legacy-peer-deps", { cwd: destination });
175
173
  };
176
174
 
177
175
  /**
@@ -183,9 +181,7 @@ const postInstallScripts = async (destination, template, spinner) => {
183
181
  case "prisma":
184
182
  {
185
183
  spinner.text = "Run prisma generate...";
186
- await asyncExec("./node_modules/.bin/prisma generate", {
187
- cwd: destination,
188
- });
184
+ await asyncExec("npm run prisma:generate", { cwd: destination });
189
185
  }
190
186
  break;
191
187
  }
@@ -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
+ "@entities/*": ["entities/*"],
28
+ "@exceptions/*": ["exceptions/*"],
29
+ "@interfaces/*": ["interfaces/*"],
30
+ "@middlewares/*": ["middlewares/*"],
31
+ "@routes/*": ["routes/*"],
32
+ "@services/*": ["services/*"],
33
+ "@utils/*": ["utils/*"]
34
+ }
35
+ },
36
+ "module": {
37
+ "type": "commonjs"
38
+ }
39
+ }
@@ -9,7 +9,7 @@ RUN npm install
9
9
 
10
10
  EXPOSE 3000
11
11
 
12
- # Dvelopment build stage
12
+ # Development build stage
13
13
  FROM common-build-stage as development-build-stage
14
14
 
15
15
  ENV NODE_ENV development
@@ -35,7 +35,7 @@ services:
35
35
  environment:
36
36
  POSTGRESQL_USERNAME: root
37
37
  POSTGRESQL_PASSWORD: password
38
- POSTGRESQL_DATABASE: typeorm
38
+ POSTGRESQL_DATABASE: test
39
39
  ports:
40
40
  - '5432:5432'
41
41
  networks:
@@ -1,42 +1,57 @@
1
- module.exports = {
1
+ /**
2
+ * @description pm2 configuration file.
3
+ * @example
4
+ * production mode :: pm2 start ecosystem.config.js --only prod
5
+ * development mode :: pm2 start ecosystem.config.js --only dev
6
+ */
7
+ module.exports = {
2
8
  apps: [
3
9
  {
4
- name: 'myapp',
5
- // package.json에 정의된 npm run start를 실행하게 해서 PM2로 관리하게 한다.
6
- script: 'npm',
7
- args: 'run dev',
8
- instances: 2,
9
- autorestart: true,
10
- watch: false,
11
- max_memory_restart: '1G',
12
- // development mode
13
- // pm2 start ecosystem.config.js
14
- env: {
15
- HOST: '0.0.0.0',
10
+ name: 'prod', // pm2 start App name
11
+ script: 'dist/server.js',
12
+ exec_mode: 'cluster', // 'cluster' or 'fork'
13
+ instance_var: 'INSTANCE_ID', // instance variable
14
+ instances: 2, // pm2 instance count
15
+ autorestart: true, // auto restart if process crash
16
+ watch: false, // files change automatic restart
17
+ ignore_watch: ['node_modules', 'logs'], // ignore files change
18
+ max_memory_restart: '1G', // restart if process use more than 1G memory
19
+ merge_logs: true, // if true, stdout and stderr will be merged and sent to pm2 log
20
+ output: './logs/access.log', // pm2 log file
21
+ error: './logs/error.log', // pm2 error log file
22
+ env: { // environment variable
16
23
  PORT: 3000,
17
- NODE_ENV: 'development',
24
+ NODE_ENV: 'production',
18
25
  },
19
- // production mode
20
- // pm2 start ecosystem.config.js --env production
21
- env_production: {
22
- HOST: '0.0.0.0',
26
+ },
27
+ {
28
+ name: 'dev', // pm2 start App name
29
+ script: 'ts-node', // ts-node
30
+ args: '-r tsconfig-paths/register --transpile-only src/server.ts', // ts-node args
31
+ exec_mode: 'cluster', // 'cluster' or 'fork'
32
+ instance_var: 'INSTANCE_ID', // instance variable
33
+ instances: 2, // pm2 instance count
34
+ autorestart: true, // auto restart if process crash
35
+ watch: false, // files change automatic restart
36
+ ignore_watch: ['node_modules', 'logs'], // ignore files change
37
+ max_memory_restart: '1G', // restart if process use more than 1G memory
38
+ merge_logs: true, // if true, stdout and stderr will be merged and sent to pm2 log
39
+ output: './logs/access.log', // pm2 log file
40
+ error: './logs/error.log', // pm2 error log file
41
+ env: { // environment variable
23
42
  PORT: 3000,
24
- NODE_ENV: 'production',
43
+ NODE_ENV: 'development',
25
44
  },
26
- output: './logs/console.log',
27
- error: './logs/consoleError.log',
28
45
  },
29
46
  ],
30
-
31
47
  deploy: {
32
48
  production: {
33
- // sample
34
- user: 'node',
35
- host: '123.12.123.1',
49
+ user: 'user',
50
+ host: '0.0.0.0',
36
51
  ref: 'origin/master',
37
52
  repo: 'git@github.com:repo.git',
38
- path: '/var/www/production',
39
- 'post-deploy': 'npm install && pm2 reload ecosystem.config.js --env production',
53
+ path: 'dist/server.js',
54
+ 'post-deploy': 'npm install && npm run build && pm2 reload ecosystem.config.js --only prod',
40
55
  },
41
56
  },
42
57
  };
@@ -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,10 +7,13 @@
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": "swc src -d dist --source-maps --copy-files",
11
+ "build:tsc": "tsc && tsc-alias",
11
12
  "test": "jest --forceExit --detectOpenHandles",
12
13
  "lint": "eslint --ignore-path .gitignore --ext .ts src/",
13
- "lint:fix": "npm run lint -- --fix"
14
+ "lint:fix": "npm run lint -- --fix",
15
+ "deploy:prod": "npm run build && pm2 start ecosystem.config.js --only prod",
16
+ "deploy:dev": "pm2 start ecosystem.config.js --only dev"
14
17
  },
15
18
  "dependencies": {
16
19
  "bcrypt": "^5.0.1",
@@ -20,27 +23,24 @@
20
23
  "config": "^3.3.6",
21
24
  "cookie-parser": "^1.4.5",
22
25
  "cors": "^2.8.5",
23
- "cross-env": "^7.0.3",
24
26
  "dotenv": "^10.0.0",
25
27
  "envalid": "^7.1.0",
26
28
  "express": "^4.17.1",
27
29
  "helmet": "^4.6.0",
28
30
  "hpp": "^0.2.3",
29
- "jest": "^27.0.6",
30
31
  "jsonwebtoken": "^8.5.1",
31
32
  "morgan": "^1.10.0",
32
33
  "pg": "^8.6.0",
33
34
  "reflect-metadata": "^0.1.13",
34
35
  "swagger-jsdoc": "^6.0.0",
35
36
  "swagger-ui-express": "^4.1.6",
36
- "ts-jest": "^27.0.3",
37
- "ts-node": "^10.0.0",
38
37
  "typeorm": "^0.2.34",
39
- "typescript": "^4.3.5",
40
38
  "winston": "^3.3.3",
41
39
  "winston-daily-rotate-file": "^4.5.5"
42
40
  },
43
41
  "devDependencies": {
42
+ "@swc/cli": "^0.1.51",
43
+ "@swc/core": "^1.2.108",
44
44
  "@types/bcrypt": "^5.0.0",
45
45
  "@types/compression": "^1.7.1",
46
46
  "@types/config": "^0.0.39",
@@ -60,16 +60,23 @@
60
60
  "@types/winston": "^2.4.4",
61
61
  "@typescript-eslint/eslint-plugin": "^4.28.2",
62
62
  "@typescript-eslint/parser": "^4.28.2",
63
+ "cross-env": "^7.0.3",
63
64
  "eslint": "^7.30.0",
64
65
  "eslint-config-prettier": "^8.3.0",
65
66
  "eslint-plugin-prettier": "^3.4.0",
66
67
  "husky": "^7.0.1",
68
+ "jest": "^27.0.6",
67
69
  "lint-staged": "^11.0.0",
68
70
  "node-config": "^0.0.2",
69
71
  "node-gyp": "^8.1.0",
70
72
  "nodemon": "^2.0.9",
73
+ "pm2": "^5.1.0",
71
74
  "prettier": "^2.3.2",
72
75
  "supertest": "^6.1.3",
73
- "tsconfig-paths": "^3.10.1"
76
+ "ts-jest": "^27.0.7",
77
+ "ts-node": "^10.4.0",
78
+ "tsc-alias": "^1.4.1",
79
+ "tsconfig-paths": "^3.10.1",
80
+ "typescript": "^4.5.2"
74
81
  }
75
82
  }
@@ -1,6 +1,5 @@
1
- process.env['NODE_CONFIG_DIR'] = __dirname + '/configs';
2
-
3
1
  import 'reflect-metadata';
2
+ import '@/index';
4
3
  import cookieParser from 'cookie-parser';
5
4
  import cors from 'cors';
6
5
  import config from 'config';
@@ -4,7 +4,7 @@
4
4
  "host": "localhost",
5
5
  "user": "root",
6
6
  "password": "password",
7
- "database": "typeorm"
7
+ "database": "test"
8
8
  },
9
9
  "secretKey": "secretKey",
10
10
  "log": {
@@ -4,7 +4,7 @@
4
4
  "host": "localhost",
5
5
  "user": "root",
6
6
  "password": "password",
7
- "database": "typeorm"
7
+ "database": "test"
8
8
  },
9
9
  "secretKey": "secretKey",
10
10
  "log": {
@@ -4,7 +4,7 @@
4
4
  "host": "localhost",
5
5
  "user": "root",
6
6
  "password": "password",
7
- "database": "typeorm"
7
+ "database": "test"
8
8
  },
9
9
  "secretKey": "secretKey",
10
10
  "log": {
@@ -1,5 +1,5 @@
1
1
  import config from 'config';
2
- import path from 'path';
2
+ import { join } from 'path';
3
3
  import { ConnectionOptions } from 'typeorm';
4
4
  import { dbConfig } from '@interfaces/db.interface';
5
5
 
@@ -13,11 +13,11 @@ export const dbConnection: ConnectionOptions = {
13
13
  database: database,
14
14
  synchronize: true,
15
15
  logging: false,
16
- entities: [path.join(__dirname, '../**/*.entity{.ts,.js}')],
17
- migrations: [path.join(__dirname, '../**/*.migration{.ts,.js}')],
18
- subscribers: [path.join(__dirname, '../**/*.subscriber{.ts,.js}')],
16
+ entities: [join(__dirname, '../**/*.entity{.ts,.js}')],
17
+ migrations: [join(__dirname, '../**/*.migration{.ts,.js}')],
18
+ subscribers: [join(__dirname, '../**/*.subscriber{.ts,.js}')],
19
19
  cli: {
20
- entitiesDir: 'src/entity',
20
+ entitiesDir: 'src/entities',
21
21
  migrationsDir: 'src/migration',
22
22
  subscribersDir: 'src/subscriber',
23
23
  },
@@ -1,15 +1,15 @@
1
1
  import { IsNotEmpty } from 'class-validator';
2
- import { Entity, PrimaryGeneratedColumn, Column, Unique, CreateDateColumn, UpdateDateColumn } from 'typeorm';
2
+ import { BaseEntity, Entity, PrimaryGeneratedColumn, Column, Unique, CreateDateColumn, UpdateDateColumn } from 'typeorm';
3
3
  import { User } from '@interfaces/users.interface';
4
4
 
5
5
  @Entity()
6
- @Unique(['email'])
7
- export class UserEntity implements User {
6
+ export class UserEntity extends BaseEntity implements User {
8
7
  @PrimaryGeneratedColumn()
9
8
  id: number;
10
9
 
11
10
  @Column()
12
11
  @IsNotEmpty()
12
+ @Unique(['email'])
13
13
  email: string;
14
14
 
15
15
  @Column()
@@ -1,35 +1,32 @@
1
- # auth API
2
-
3
- ###
4
1
  # baseURL
5
2
  @baseURL = http://localhost:3000
6
3
 
7
4
  ###
8
- # signup
9
- POST {{baseURL}}/signup
5
+ # User Signup
6
+ POST {{ baseURL }}/signup
10
7
  Content-Type: application/json
11
8
 
12
9
  {
13
- "email": "example@gmail.com",
14
- "password": "qwer1234"
10
+ "email": "example@email.com",
11
+ "password": "password"
15
12
  }
16
13
 
17
14
  ###
18
- # Login
19
- POST {{baseURL}}/login
15
+ # User Login
16
+ POST {{ baseURL }}/login
20
17
  Content-Type: application/json
21
18
 
22
19
  {
23
- "email": "lim@gmail.com",
24
- "password": "q1w2e3r4"
20
+ "email": "example@email.com",
21
+ "password": "password"
25
22
  }
26
23
 
27
24
  ###
28
- # Logout
29
- POST {{baseURL}}/logout
25
+ # User Logout
26
+ POST {{ baseURL }}/logout
30
27
  Content-Type: application/json
31
28
 
32
29
  {
33
- "email": "lim@gmail.com",
34
- "password": "q1w2e3r4"
30
+ "email": "example@email.com",
31
+ "password": "password"
35
32
  }
@@ -1,38 +1,34 @@
1
- # users API
2
-
3
- ###
4
1
  # baseURL
5
2
  @baseURL = http://localhost:3000
6
3
 
7
4
  ###
8
5
  # Find All Users
9
- GET {{baseURL}}/users
6
+ GET {{ baseURL }}/users
10
7
 
11
8
  ###
12
9
  # Find User By Id
13
- GET {{baseURL}}/users/1
14
-
10
+ GET {{ baseURL }}/users/1
15
11
 
16
12
  ###
17
- # Add User
18
- POST {{baseURL}}/users
13
+ # Create User
14
+ POST {{ baseURL }}/users
19
15
  Content-Type: application/json
20
16
 
21
17
  {
22
- "email": "example@gmail.com",
23
- "password": "qwer1234"
18
+ "email": "example@email.com",
19
+ "password": "password"
24
20
  }
25
21
 
26
22
  ###
27
- # Edit User By Id
28
- PUT {{baseURL}}/users/1
23
+ # Modify User By Id
24
+ PUT {{ baseURL }}/users/1
29
25
  Content-Type: application/json
30
26
 
31
27
  {
32
- "email": "example@gmail.com",
33
- "password": "qwer1234"
28
+ "email": "example@email.com",
29
+ "password": "password"
34
30
  }
35
31
 
36
32
  ###
37
- # Del User By Id
38
- DELETE {{baseURL}}/users/1
33
+ # Delete User By Id
34
+ DELETE {{ baseURL }}/users/1
@@ -0,0 +1 @@
1
+ process.env['NODE_CONFIG_DIR'] = __dirname + '/configs';
@@ -1,22 +1,18 @@
1
1
  import config from 'config';
2
2
  import { NextFunction, Response } from 'express';
3
- import jwt from 'jsonwebtoken';
4
- import { getRepository } from 'typeorm';
5
- import { UserEntity } from '@entity/users.entity';
3
+ import { verify } from 'jsonwebtoken';
4
+ import { UserEntity } from '@entities/users.entity';
6
5
  import { HttpException } from '@exceptions/HttpException';
7
6
  import { DataStoredInToken, RequestWithUser } from '@interfaces/auth.interface';
8
7
 
9
8
  const authMiddleware = async (req: RequestWithUser, res: Response, next: NextFunction) => {
10
9
  try {
11
- 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);
12
11
 
13
12
  if (Authorization) {
14
13
  const secretKey: string = config.get('secretKey');
15
- const verificationResponse = (await jwt.verify(Authorization, secretKey)) as DataStoredInToken;
16
- const userId = verificationResponse.id;
17
-
18
- const userRepository = getRepository(UserEntity);
19
- const findUser = await userRepository.findOne(userId, { select: ['id', 'email', 'password'] });
14
+ const { id } = (await verify(Authorization, secretKey)) as DataStoredInToken;
15
+ const findUser = await UserEntity.findOne(id, { select: ['id', 'email', 'password'] });
20
16
 
21
17
  if (findUser) {
22
18
  req.user = findUser;
@@ -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';