typescript-express-starter 6.2.1 → 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.
- package/README.kr.md +35 -12
- package/README.md +36 -13
- package/bin/cli.js +4 -3
- package/lib/default/.swcrc +41 -0
- package/lib/default/nodemon.json +2 -2
- package/lib/default/package.json +12 -8
- package/lib/default/src/app.ts +1 -2
- package/lib/default/src/http/auth.http +12 -15
- package/lib/default/src/http/users.http +12 -16
- package/lib/default/src/index.ts +1 -0
- package/lib/default/src/middlewares/auth.middleware.ts +3 -3
- package/lib/default/src/models/users.model.ts +5 -5
- package/lib/default/src/server.ts +1 -2
- package/lib/default/src/services/auth.service.ts +5 -5
- package/lib/default/src/services/users.service.ts +3 -3
- package/lib/default/src/tests/auth.test.ts +4 -4
- package/lib/default/src/tests/users.test.ts +4 -4
- package/lib/default/src/utils/logger.ts +5 -5
- package/lib/default/tsconfig.json +2 -2
- package/lib/knex/.swcrc +39 -0
- package/lib/knex/knexfile.ts +6 -6
- package/lib/knex/nodemon.json +2 -2
- package/lib/knex/package.json +11 -8
- package/lib/knex/src/app.ts +2 -3
- package/lib/knex/src/databases/index.ts +6 -6
- package/lib/knex/src/http/auth.http +12 -15
- package/lib/knex/src/http/users.http +12 -16
- package/lib/knex/src/index.ts +1 -0
- package/lib/knex/src/middlewares/auth.middleware.ts +4 -4
- package/lib/knex/src/server.ts +1 -2
- package/lib/knex/src/services/auth.service.ts +5 -5
- package/lib/knex/src/services/users.service.ts +3 -3
- package/lib/knex/src/tests/auth.test.ts +2 -2
- package/lib/knex/src/tests/index.test.ts +1 -1
- package/lib/knex/src/tests/users.test.ts +2 -2
- package/lib/knex/src/utils/logger.ts +5 -5
- package/lib/knex/tsconfig.json +2 -2
- package/lib/mongoose/.swcrc +39 -0
- package/lib/mongoose/docker-compose.yml +0 -4
- package/lib/mongoose/nodemon.json +2 -2
- package/lib/mongoose/package.json +12 -8
- package/lib/mongoose/src/app.ts +2 -3
- package/lib/mongoose/src/configs/development.json +1 -1
- package/lib/mongoose/src/configs/production.json +1 -1
- package/lib/mongoose/src/configs/test.json +1 -1
- package/lib/mongoose/src/http/auth.http +32 -0
- package/lib/mongoose/src/http/users.http +34 -0
- package/lib/mongoose/src/index.ts +1 -0
- package/lib/mongoose/src/middlewares/auth.middleware.ts +3 -3
- package/lib/mongoose/src/server.ts +1 -2
- package/lib/mongoose/src/services/auth.service.ts +5 -5
- package/lib/mongoose/src/services/users.service.ts +3 -3
- package/lib/mongoose/src/utils/logger.ts +5 -5
- package/lib/mongoose/tsconfig.json +2 -2
- package/lib/prisma/.env +1 -1
- package/lib/prisma/.swcrc +37 -0
- package/lib/prisma/docker-compose.yml +1 -6
- package/lib/prisma/nodemon.json +2 -2
- package/lib/prisma/package.json +14 -10
- package/lib/prisma/src/app.ts +2 -3
- package/lib/prisma/src/http/auth.http +12 -15
- package/lib/prisma/src/http/users.http +12 -16
- package/lib/prisma/src/index.ts +1 -0
- package/lib/prisma/src/middlewares/auth.middleware.ts +4 -4
- package/lib/prisma/src/server.ts +1 -2
- package/lib/prisma/src/services/auth.service.ts +5 -5
- package/lib/prisma/src/services/users.service.ts +3 -3
- package/lib/prisma/src/utils/logger.ts +5 -5
- package/lib/prisma/tsconfig.json +2 -2
- package/lib/routing-controllers/.swcrc +37 -0
- package/lib/routing-controllers/nodemon.json +2 -2
- package/lib/routing-controllers/package.json +12 -9
- package/lib/routing-controllers/src/app.ts +3 -4
- package/lib/routing-controllers/src/http/auth.http +12 -15
- package/lib/routing-controllers/src/http/users.http +12 -16
- package/lib/routing-controllers/src/index.ts +1 -0
- package/lib/routing-controllers/src/middlewares/auth.middleware.ts +3 -3
- package/lib/routing-controllers/src/middlewares/validation.middleware.ts +10 -2
- package/lib/routing-controllers/src/models/users.model.ts +5 -5
- package/lib/routing-controllers/src/server.ts +1 -3
- package/lib/routing-controllers/src/services/auth.service.ts +5 -5
- package/lib/routing-controllers/src/services/users.service.ts +3 -3
- package/lib/routing-controllers/src/utils/logger.ts +5 -5
- package/lib/routing-controllers/tsconfig.json +2 -2
- package/lib/sequelize/.swcrc +39 -0
- package/lib/sequelize/docker-compose.yml +1 -6
- package/lib/sequelize/nodemon.json +2 -2
- package/lib/sequelize/package.json +12 -8
- package/lib/sequelize/src/app.ts +1 -2
- package/lib/sequelize/src/configs/development.json +2 -2
- package/lib/sequelize/src/configs/production.json +1 -1
- package/lib/sequelize/src/configs/test.json +1 -1
- package/lib/sequelize/src/http/auth.http +32 -0
- package/lib/sequelize/src/http/users.http +34 -0
- package/lib/sequelize/src/index.ts +1 -0
- package/lib/sequelize/src/middlewares/auth.middleware.ts +4 -4
- package/lib/sequelize/src/server.ts +1 -2
- package/lib/sequelize/src/services/auth.service.ts +5 -5
- package/lib/sequelize/src/services/users.service.ts +3 -3
- package/lib/sequelize/src/utils/logger.ts +5 -5
- package/lib/sequelize/tsconfig.json +2 -2
- package/lib/starter.js +4 -6
- package/lib/typeorm/.swcrc +39 -0
- package/lib/typeorm/docker-compose.yml +1 -1
- package/lib/typeorm/nodemon.json +2 -2
- package/lib/typeorm/package.json +12 -8
- package/lib/typeorm/src/app.ts +1 -2
- package/lib/typeorm/src/configs/development.json +1 -1
- package/lib/typeorm/src/configs/production.json +1 -1
- package/lib/typeorm/src/configs/test.json +1 -1
- package/lib/typeorm/src/databases/index.ts +5 -5
- package/lib/typeorm/src/{entity → entities}/users.entity.ts +3 -3
- package/lib/typeorm/src/http/auth.http +12 -15
- package/lib/typeorm/src/http/users.http +12 -16
- package/lib/typeorm/src/index.ts +1 -0
- package/lib/typeorm/src/middlewares/auth.middleware.ts +5 -9
- package/lib/typeorm/src/server.ts +1 -2
- package/lib/typeorm/src/services/auth.service.ts +13 -17
- package/lib/typeorm/src/services/users.service.ts +16 -22
- package/lib/typeorm/src/utils/logger.ts +5 -5
- package/lib/typeorm/tsconfig.json +3 -3
- package/package.json +11 -4
package/README.kr.md
CHANGED
|
@@ -215,6 +215,17 @@ VSCode Extension에서 [REST Client](https://marketplace.visualstudio.com/items?
|
|
|
215
215
|
|
|
216
216
|
수정을 원하시면 `ecosystem.config.js` 파일을 수정해주시면 됩니다.
|
|
217
217
|
|
|
218
|
+
### 🏎 SWC :: 강하고 빠른 자바스크립트 / 타입스크립트 컴파일러
|
|
219
|
+
|
|
220
|
+
[SWC](https://swc.rs/)는 차세대 고속 개발자 도구를 위한 확장 가능한 Rust 기반 플랫폼입니다.
|
|
221
|
+
|
|
222
|
+
`SWC는 단일 스레드에서 Babel보다 20배, 4개 코어에서 70배 빠릅니다.`
|
|
223
|
+
|
|
224
|
+
- swc 빌드 :: `npm run build`
|
|
225
|
+
- tsc 빌드 :: `npm run build:tsc`
|
|
226
|
+
|
|
227
|
+
수정을 원하시면 `.swcrc` 파일을 수정해주시면 됩니다.
|
|
228
|
+
|
|
218
229
|
## 🗂 코드 구조 (default)
|
|
219
230
|
|
|
220
231
|
```bash
|
|
@@ -277,6 +288,7 @@ VSCode Extension에서 [REST Client](https://marketplace.visualstudio.com/items?
|
|
|
277
288
|
│ │ └── vaildateEnv.ts
|
|
278
289
|
│ │
|
|
279
290
|
│ ├── app.ts
|
|
291
|
+
│ ├── index.ts
|
|
280
292
|
│ └── server.ts
|
|
281
293
|
│
|
|
282
294
|
├── .dockerignore
|
|
@@ -288,6 +300,7 @@ VSCode Extension에서 [REST Client](https://marketplace.visualstudio.com/items?
|
|
|
288
300
|
├── .huskyrc
|
|
289
301
|
├── .lintstagedrc.json
|
|
290
302
|
├── .prettierrc
|
|
303
|
+
├── .swcrc
|
|
291
304
|
├── docker-compose.yml
|
|
292
305
|
├── Dockerfile
|
|
293
306
|
├── ecosystem.config.js
|
|
@@ -301,21 +314,13 @@ VSCode Extension에서 [REST Client](https://marketplace.visualstudio.com/items?
|
|
|
301
314
|
└── tsconfig.json
|
|
302
315
|
```
|
|
303
316
|
|
|
304
|
-
##
|
|
317
|
+
## ⭐️ 주신분들
|
|
305
318
|
|
|
306
|
-
|
|
307
|
-
| :----------------- | :-------------------- |
|
|
308
|
-
| 기능 추가 | ✨ 기능 추가 |
|
|
309
|
-
| 버그 수정 | 🐞 버그 수정 |
|
|
310
|
-
| 코드 개선 | 🛠 코드 개선 |
|
|
311
|
-
| 패키지 설치 | 📦 패키지 설치 |
|
|
312
|
-
| 문서 수정 | 📚 문서 수정 |
|
|
313
|
-
| 버전 업데이트 | 🌼 버전 업데이트 |
|
|
314
|
-
| 새로운 템플릿 추가 | 🎉 새로운 템플릿 추가 |
|
|
319
|
+
[](https://github.com/ljlm0402/typescript-express-starter/stargazers)
|
|
315
320
|
|
|
316
|
-
##
|
|
321
|
+
## 🍴 해주신분들
|
|
317
322
|
|
|
318
|
-
[
|
|
323
|
+
[](https://github.com/ljlm0402/typescript-express-starter/network/members)
|
|
319
324
|
|
|
320
325
|
## 🤝 도움을 주신분들
|
|
321
326
|
|
|
@@ -357,6 +362,24 @@ VSCode Extension에서 [REST Client](https://marketplace.visualstudio.com/items?
|
|
|
357
362
|
|
|
358
363
|
- Amrik Singh [https://github.com/AmrikSD](https://github.com/AmrikSD)
|
|
359
364
|
|
|
365
|
+
- oricc [https://github.com/oricc](https://github.com/oricc)
|
|
366
|
+
|
|
367
|
+
## 💳 라이센스
|
|
368
|
+
|
|
369
|
+
[MIT](LICENSE)
|
|
370
|
+
|
|
371
|
+
## 📬 커밋 메시지 정의
|
|
372
|
+
|
|
373
|
+
| 언제 | 메시지 |
|
|
374
|
+
| :----------------- | :-------------------- |
|
|
375
|
+
| 기능 추가 | ✨ 기능 추가 |
|
|
376
|
+
| 버그 수정 | 🐞 버그 수정 |
|
|
377
|
+
| 코드 개선 | 🛠 코드 개선 |
|
|
378
|
+
| 패키지 설치 | 📦 패키지 설치 |
|
|
379
|
+
| 문서 수정 | 📚 문서 수정 |
|
|
380
|
+
| 버전 업데이트 | 🌼 버전 업데이트 |
|
|
381
|
+
| 새로운 템플릿 추가 | 🎉 새로운 템플릿 추가 |
|
|
382
|
+
|
|
360
383
|
## 📬 이슈를 남겨주세요
|
|
361
384
|
|
|
362
385
|
추후 추가하고자하는 템플릿, 질문, 기능을 적어 주시면 최선을 다해 답변하고 반영하겠습니다.
|
package/README.md
CHANGED
|
@@ -104,7 +104,7 @@ Start your typescript-express-starter app in development mode at `http://localho
|
|
|
104
104
|
| :------------------- | :----------------------------------------------------------------------------------------------------------- |
|
|
105
105
|
| Default | Express Default |
|
|
106
106
|
| Routing Controllers | Create structured, declarative and beautifully organized class-based controllers with heavy decorators usage |
|
|
107
|
-
|
|
|
107
|
+
| Sequelize | Easy to use multi SQL dialect ORM for Node.js |
|
|
108
108
|
| Mongoose | MongoDB Object Modeling(ODM) designed to work in an asynchronous environment |
|
|
109
109
|
| TypeORM | An ORM that can run in Node.js and Others |
|
|
110
110
|
| Prisma | Modern Database Access for TypeScript & Node.js |
|
|
@@ -220,6 +220,17 @@ Modify `*.http` file in src/http folder to your source code.
|
|
|
220
220
|
|
|
221
221
|
Modify `ecosystem.config.js` file to your source code.
|
|
222
222
|
|
|
223
|
+
### 🏎 SWC :: a super-fast JavaScript / TypeScript compiler
|
|
224
|
+
|
|
225
|
+
[SWC](https://swc.rs/) is an extensible Rust-based platform for the next generation of fast developer tools.
|
|
226
|
+
|
|
227
|
+
`SWC is 20x faster than Babel on a single thread and 70x faster on four cores.`
|
|
228
|
+
|
|
229
|
+
- swc build :: `npm run build`
|
|
230
|
+
- tsc build :: `npm run build:tsc`
|
|
231
|
+
|
|
232
|
+
Modify `.swcrc` file to your source code.
|
|
233
|
+
|
|
223
234
|
## 🗂 Code Structure (default)
|
|
224
235
|
|
|
225
236
|
```bash
|
|
@@ -282,6 +293,7 @@ Modify `ecosystem.config.js` file to your source code.
|
|
|
282
293
|
│ │ └── vaildateEnv.ts
|
|
283
294
|
│ │
|
|
284
295
|
│ ├── app.ts
|
|
296
|
+
│ ├── index.ts
|
|
285
297
|
│ └── server.ts
|
|
286
298
|
│
|
|
287
299
|
├── .dockerignore
|
|
@@ -293,6 +305,7 @@ Modify `ecosystem.config.js` file to your source code.
|
|
|
293
305
|
├── .huskyrc
|
|
294
306
|
├── .lintstagedrc.json
|
|
295
307
|
├── .prettierrc
|
|
308
|
+
├── .swcrc
|
|
296
309
|
├── docker-compose.yml
|
|
297
310
|
├── Dockerfile
|
|
298
311
|
├── ecosystem.config.js
|
|
@@ -306,21 +319,13 @@ Modify `ecosystem.config.js` file to your source code.
|
|
|
306
319
|
└── tsconfig.json
|
|
307
320
|
```
|
|
308
321
|
|
|
309
|
-
##
|
|
322
|
+
## ⭐️ Stargazers
|
|
310
323
|
|
|
311
|
-
|
|
312
|
-
| :--------------- | :----------------- |
|
|
313
|
-
| Add Feature | ✨ Add Feature |
|
|
314
|
-
| Fix Bug | 🐞 Fix Bug |
|
|
315
|
-
| Refactoring Code | 🛠 Refactoring Code |
|
|
316
|
-
| Install Package | 📦 Install Package |
|
|
317
|
-
| Fix Readme | 📚 Fix Readme |
|
|
318
|
-
| Update Version | 🌼 Update Version |
|
|
319
|
-
| New Template | 🎉 New Template |
|
|
324
|
+
[](https://github.com/ljlm0402/typescript-express-starter/stargazers)
|
|
320
325
|
|
|
321
|
-
##
|
|
326
|
+
## 🍴 Forkers
|
|
322
327
|
|
|
323
|
-
[
|
|
328
|
+
[](https://github.com/ljlm0402/typescript-express-starter/network/members)
|
|
324
329
|
|
|
325
330
|
## 🤝 Contributors
|
|
326
331
|
|
|
@@ -362,6 +367,24 @@ Modify `ecosystem.config.js` file to your source code.
|
|
|
362
367
|
|
|
363
368
|
- Amrik Singh [https://github.com/AmrikSD](https://github.com/AmrikSD)
|
|
364
369
|
|
|
370
|
+
- oricc [https://github.com/oricc](https://github.com/oricc)
|
|
371
|
+
|
|
372
|
+
## 💳 License
|
|
373
|
+
|
|
374
|
+
[MIT](LICENSE)
|
|
375
|
+
|
|
376
|
+
## 📬 Recommended Commit Message
|
|
377
|
+
|
|
378
|
+
| When | Commit Message |
|
|
379
|
+
| :--------------- | :----------------- |
|
|
380
|
+
| Add Feature | ✨ Add Feature |
|
|
381
|
+
| Fix Bug | 🐞 Fix Bug |
|
|
382
|
+
| Refactoring Code | 🛠 Refactoring Code |
|
|
383
|
+
| Install Package | 📦 Install Package |
|
|
384
|
+
| Fix Readme | 📚 Fix Readme |
|
|
385
|
+
| Update Version | 🌼 Update Version |
|
|
386
|
+
| New Template | 🎉 New Template |
|
|
387
|
+
|
|
365
388
|
## 📬 Please request an issue
|
|
366
389
|
|
|
367
390
|
In the future, please write down your desired template, questions, and features to be added, and we will try our best to answer and reflect them.
|
package/bin/cli.js
CHANGED
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
|
|
3
3
|
/*****************************************************************
|
|
4
|
-
*
|
|
5
|
-
*
|
|
6
|
-
*
|
|
4
|
+
* Typescript Express Starter
|
|
5
|
+
* 2019.12.18 ~ 🎮
|
|
6
|
+
* Made By AGUMON 🦖
|
|
7
|
+
* https://github.com/ljlm0402/typescript-express-starter
|
|
7
8
|
*****************************************************************/
|
|
8
9
|
|
|
9
10
|
const path = require("path");
|
|
@@ -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
|
+
"@controllers/*": ["controllers/*"],
|
|
25
|
+
"@dtos/*": ["dtos/*"],
|
|
26
|
+
"@exceptions/*": ["exceptions/*"],
|
|
27
|
+
"@interfaces/*": ["interfaces/*"],
|
|
28
|
+
"@middlewares/*": ["middlewares/*"],
|
|
29
|
+
"@models/*": ["models/*"],
|
|
30
|
+
"@routes/*": ["routes/*"],
|
|
31
|
+
"@services/*": ["services/*"],
|
|
32
|
+
"@utils/*": ["utils/*"]
|
|
33
|
+
}
|
|
34
|
+
},
|
|
35
|
+
"module": {
|
|
36
|
+
"type": "commonjs"
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
|
|
41
|
+
|
package/lib/default/nodemon.json
CHANGED
package/lib/default/package.json
CHANGED
|
@@ -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": "
|
|
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
14
|
"lint:fix": "npm run lint -- --fix",
|
|
@@ -22,25 +23,21 @@
|
|
|
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
|
-
"pm2": "^5.1.0",
|
|
35
33
|
"swagger-jsdoc": "^6.0.0",
|
|
36
34
|
"swagger-ui-express": "^4.1.6",
|
|
37
|
-
"ts-jest": "^27.0.3",
|
|
38
|
-
"ts-node": "^10.0.0",
|
|
39
|
-
"typescript": "^4.3.5",
|
|
40
35
|
"winston": "^3.3.3",
|
|
41
36
|
"winston-daily-rotate-file": "^4.5.5"
|
|
42
37
|
},
|
|
43
38
|
"devDependencies": {
|
|
39
|
+
"@swc/cli": "^0.1.51",
|
|
40
|
+
"@swc/core": "^1.2.108",
|
|
44
41
|
"@types/bcrypt": "^5.0.0",
|
|
45
42
|
"@types/compression": "^1.7.1",
|
|
46
43
|
"@types/config": "^0.0.39",
|
|
@@ -60,16 +57,23 @@
|
|
|
60
57
|
"@types/winston": "^2.4.4",
|
|
61
58
|
"@typescript-eslint/eslint-plugin": "^4.28.2",
|
|
62
59
|
"@typescript-eslint/parser": "^4.28.2",
|
|
60
|
+
"cross-env": "^7.0.3",
|
|
63
61
|
"eslint": "^7.30.0",
|
|
64
62
|
"eslint-config-prettier": "^8.3.0",
|
|
65
63
|
"eslint-plugin-prettier": "^3.4.0",
|
|
66
64
|
"husky": "^7.0.1",
|
|
65
|
+
"jest": "^27.0.6",
|
|
67
66
|
"lint-staged": "^11.0.0",
|
|
68
67
|
"node-config": "^0.0.2",
|
|
69
68
|
"node-gyp": "^8.1.0",
|
|
70
69
|
"nodemon": "^2.0.9",
|
|
70
|
+
"pm2": "^5.1.0",
|
|
71
71
|
"prettier": "^2.3.2",
|
|
72
72
|
"supertest": "^6.1.3",
|
|
73
|
-
"
|
|
73
|
+
"tsc-alias": "^1.4.1",
|
|
74
|
+
"tsconfig-paths": "^3.10.1",
|
|
75
|
+
"ts-jest": "^27.0.3",
|
|
76
|
+
"ts-node": "^10.0.0",
|
|
77
|
+
"typescript": "^4.3.5"
|
|
74
78
|
}
|
|
75
79
|
}
|
package/lib/default/src/app.ts
CHANGED
|
@@ -1,35 +1,32 @@
|
|
|
1
|
-
# auth API
|
|
2
|
-
|
|
3
|
-
###
|
|
4
1
|
# baseURL
|
|
5
2
|
@baseURL = http://localhost:3000
|
|
6
3
|
|
|
7
4
|
###
|
|
8
|
-
#
|
|
9
|
-
POST {{baseURL}}/signup
|
|
5
|
+
# User Signup
|
|
6
|
+
POST {{ baseURL }}/signup
|
|
10
7
|
Content-Type: application/json
|
|
11
8
|
|
|
12
9
|
{
|
|
13
|
-
"email": "example@
|
|
14
|
-
"password": "
|
|
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": "
|
|
24
|
-
"password": "
|
|
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": "
|
|
34
|
-
"password": "
|
|
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
|
-
#
|
|
18
|
-
POST {{baseURL}}/users
|
|
13
|
+
# Create User
|
|
14
|
+
POST {{ baseURL }}/users
|
|
19
15
|
Content-Type: application/json
|
|
20
16
|
|
|
21
17
|
{
|
|
22
|
-
"email": "example@
|
|
23
|
-
"password": "
|
|
18
|
+
"email": "example@email.com",
|
|
19
|
+
"password": "password"
|
|
24
20
|
}
|
|
25
21
|
|
|
26
22
|
###
|
|
27
|
-
#
|
|
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@
|
|
33
|
-
"password": "
|
|
28
|
+
"email": "example@email.com",
|
|
29
|
+
"password": "password"
|
|
34
30
|
}
|
|
35
31
|
|
|
36
32
|
###
|
|
37
|
-
#
|
|
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,17 +1,17 @@
|
|
|
1
1
|
import config from 'config';
|
|
2
2
|
import { NextFunction, Response } from 'express';
|
|
3
|
-
import
|
|
3
|
+
import { verify } from 'jsonwebtoken';
|
|
4
4
|
import { HttpException } from '@exceptions/HttpException';
|
|
5
5
|
import { DataStoredInToken, RequestWithUser } from '@interfaces/auth.interface';
|
|
6
6
|
import userModel from '@models/users.model';
|
|
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]
|
|
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 = (await
|
|
14
|
+
const verificationResponse = (await verify(Authorization, secretKey)) as DataStoredInToken;
|
|
15
15
|
const userId = verificationResponse.id;
|
|
16
16
|
const findUser = userModel.find(user => user.id === userId);
|
|
17
17
|
|
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
import { User } from '@interfaces/users.interface';
|
|
2
2
|
|
|
3
|
-
// password:
|
|
3
|
+
// password: password
|
|
4
4
|
const userModel: User[] = [
|
|
5
|
-
{ id: 1, email: '
|
|
6
|
-
{ id: 2, email: '
|
|
7
|
-
{ id: 3, email: '
|
|
8
|
-
{ id: 4, email: '
|
|
5
|
+
{ id: 1, email: 'example1@email.com', password: '$2b$10$TBEfaCe1oo.2jfkBDWcj/usBj4oECsW2wOoDXpCa2IH9xqCpEK/hC' },
|
|
6
|
+
{ id: 2, email: 'example2@email.com', password: '$2b$10$TBEfaCe1oo.2jfkBDWcj/usBj4oECsW2wOoDXpCa2IH9xqCpEK/hC' },
|
|
7
|
+
{ id: 3, email: 'example3@email.com', password: '$2b$10$TBEfaCe1oo.2jfkBDWcj/usBj4oECsW2wOoDXpCa2IH9xqCpEK/hC' },
|
|
8
|
+
{ id: 4, email: 'example4@email.com', password: '$2b$10$TBEfaCe1oo.2jfkBDWcj/usBj4oECsW2wOoDXpCa2IH9xqCpEK/hC' },
|
|
9
9
|
];
|
|
10
10
|
|
|
11
11
|
export default userModel;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import
|
|
1
|
+
import { hash, compare } from 'bcrypt';
|
|
2
2
|
import config from 'config';
|
|
3
|
-
import
|
|
3
|
+
import { sign } from 'jsonwebtoken';
|
|
4
4
|
import { CreateUserDto } from '@dtos/users.dto';
|
|
5
5
|
import { HttpException } from '@exceptions/HttpException';
|
|
6
6
|
import { DataStoredInToken, TokenData } from '@interfaces/auth.interface';
|
|
@@ -17,7 +17,7 @@ class AuthService {
|
|
|
17
17
|
const findUser: User = this.users.find(user => user.email === userData.email);
|
|
18
18
|
if (findUser) throw new HttpException(409, `You're email ${userData.email} already exists`);
|
|
19
19
|
|
|
20
|
-
const hashedPassword = await
|
|
20
|
+
const hashedPassword = await hash(userData.password, 10);
|
|
21
21
|
const createUserData: User = { id: this.users.length + 1, ...userData, password: hashedPassword };
|
|
22
22
|
|
|
23
23
|
return createUserData;
|
|
@@ -29,7 +29,7 @@ class AuthService {
|
|
|
29
29
|
const findUser: User = this.users.find(user => user.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
|
|
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:
|
|
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
|
|
1
|
+
import { hash } from 'bcrypt';
|
|
2
2
|
import { CreateUserDto } from '@dtos/users.dto';
|
|
3
3
|
import { HttpException } from '@exceptions/HttpException';
|
|
4
4
|
import { User } from '@interfaces/users.interface';
|
|
@@ -26,7 +26,7 @@ class UserService {
|
|
|
26
26
|
const findUser: User = this.users.find(user => user.email === userData.email);
|
|
27
27
|
if (findUser) throw new HttpException(409, `Your email ${userData.email} already exists`);
|
|
28
28
|
|
|
29
|
-
const hashedPassword = await
|
|
29
|
+
const hashedPassword = await hash(userData.password, 10);
|
|
30
30
|
const createUserData: User = { id: this.users.length + 1, ...userData, password: hashedPassword };
|
|
31
31
|
this.users = [...this.users, createUserData];
|
|
32
32
|
|
|
@@ -39,7 +39,7 @@ class UserService {
|
|
|
39
39
|
const findUser: User = this.users.find(user => user.id === userId);
|
|
40
40
|
if (!findUser) throw new HttpException(409, "You're not user");
|
|
41
41
|
|
|
42
|
-
const hashedPassword = await
|
|
42
|
+
const hashedPassword = await hash(userData.password, 10);
|
|
43
43
|
const updateUserData: User[] = this.users.map((user: User) => {
|
|
44
44
|
if (user.id === findUser.id) user = { id: userId, ...userData, password: hashedPassword };
|
|
45
45
|
return user;
|
|
@@ -11,8 +11,8 @@ describe('Testing Auth', () => {
|
|
|
11
11
|
describe('[POST] /signup', () => {
|
|
12
12
|
it('response should have the Create userData', () => {
|
|
13
13
|
const userData: CreateUserDto = {
|
|
14
|
-
email: '
|
|
15
|
-
password: '
|
|
14
|
+
email: 'example@email.com',
|
|
15
|
+
password: 'password',
|
|
16
16
|
};
|
|
17
17
|
const authRoute = new AuthRoute();
|
|
18
18
|
const app = new App([authRoute]);
|
|
@@ -24,8 +24,8 @@ describe('Testing Auth', () => {
|
|
|
24
24
|
describe('[POST] /login', () => {
|
|
25
25
|
it('response should have the Set-Cookie header with the Authorization token', async () => {
|
|
26
26
|
const userData: CreateUserDto = {
|
|
27
|
-
email: '
|
|
28
|
-
password: '
|
|
27
|
+
email: 'example1@email.com',
|
|
28
|
+
password: 'password',
|
|
29
29
|
};
|
|
30
30
|
|
|
31
31
|
const authRoute = new AuthRoute();
|
|
@@ -34,8 +34,8 @@ describe('Testing Users', () => {
|
|
|
34
34
|
describe('[POST] /users', () => {
|
|
35
35
|
it('response statusCode 201 / created', async () => {
|
|
36
36
|
const userData: CreateUserDto = {
|
|
37
|
-
email: '
|
|
38
|
-
password: '
|
|
37
|
+
email: 'example@email.com',
|
|
38
|
+
password: 'password',
|
|
39
39
|
};
|
|
40
40
|
const usersRoute = new UserRoute();
|
|
41
41
|
const app = new App([usersRoute]);
|
|
@@ -48,8 +48,8 @@ describe('Testing Users', () => {
|
|
|
48
48
|
it('response statusCode 200 / updated', async () => {
|
|
49
49
|
const userId = 1;
|
|
50
50
|
const userData: CreateUserDto = {
|
|
51
|
-
email: '
|
|
52
|
-
password: '
|
|
51
|
+
email: 'example@email.com',
|
|
52
|
+
password: 'password',
|
|
53
53
|
};
|
|
54
54
|
const usersRoute = new UserRoute();
|
|
55
55
|
const app = new App([usersRoute]);
|
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
import config from 'config';
|
|
2
|
-
import
|
|
3
|
-
import
|
|
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 =
|
|
8
|
+
const logDir: string = join(__dirname, config.get('log.dir'));
|
|
9
9
|
|
|
10
|
-
if (!
|
|
11
|
-
|
|
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": "
|
|
16
|
+
"outDir": "dist",
|
|
17
17
|
"allowJs": true,
|
|
18
18
|
"noEmit": false,
|
|
19
19
|
"esModuleInterop": true,
|
|
@@ -34,5 +34,5 @@
|
|
|
34
34
|
}
|
|
35
35
|
},
|
|
36
36
|
"include": ["src/**/*.ts", "src/**/*.json", ".env"],
|
|
37
|
-
"exclude": ["node_modules"]
|
|
37
|
+
"exclude": ["node_modules", "src/http", "src/logs", "src/tests"]
|
|
38
38
|
}
|
package/lib/knex/.swcrc
ADDED
|
@@ -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
|
+
}
|