typescript-express-starter 7.0.0 → 8.1.2
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 +12 -6
- package/README.md +12 -6
- package/lib/default/.env.development.local +13 -0
- package/lib/default/.env.production.local +13 -0
- package/lib/default/.env.test.local +13 -0
- package/lib/default/.swcrc +1 -0
- package/lib/default/package.json +2 -4
- package/lib/default/src/app.ts +6 -7
- package/lib/default/src/config/index.ts +5 -0
- package/lib/default/src/middlewares/auth.middleware.ts +2 -2
- package/lib/default/src/server.ts +0 -2
- package/lib/default/src/services/auth.service.ts +2 -2
- package/lib/default/src/utils/logger.ts +2 -2
- package/lib/default/tsconfig.json +1 -0
- package/lib/graphql/.env.development.local +20 -0
- package/lib/graphql/.env.production.local +20 -0
- package/lib/graphql/.env.test.local +20 -0
- package/lib/graphql/.swcrc +1 -0
- package/lib/graphql/package.json +2 -4
- package/lib/graphql/src/app.ts +7 -8
- package/lib/graphql/src/config/index.ts +5 -0
- package/lib/graphql/src/databases/index.ts +6 -8
- package/lib/graphql/src/middlewares/auth.middleware.ts +2 -2
- package/lib/graphql/src/repositories/auth.repository.ts +2 -2
- package/lib/graphql/src/server.ts +0 -3
- package/lib/graphql/src/utils/logger.ts +2 -2
- package/lib/graphql/tsconfig.json +1 -0
- package/lib/knex/.env.development.local +20 -0
- package/lib/knex/.env.production.local +20 -0
- package/lib/knex/.env.test.local +20 -0
- package/lib/knex/.swcrc +1 -0
- package/lib/knex/knexfile.ts +6 -10
- package/lib/knex/package.json +2 -4
- package/lib/knex/src/app.ts +6 -7
- package/lib/knex/src/config/index.ts +5 -0
- package/lib/knex/src/controllers/users.controller.ts +2 -2
- package/lib/knex/src/databases/index.ts +6 -8
- package/lib/knex/src/middlewares/auth.middleware.ts +2 -2
- package/lib/knex/src/server.ts +0 -2
- package/lib/knex/src/services/auth.service.ts +2 -2
- package/lib/knex/src/utils/logger.ts +2 -2
- package/lib/knex/tsconfig.json +1 -0
- package/lib/mongoose/.env.development.local +18 -0
- package/lib/mongoose/.env.production.local +18 -0
- package/lib/mongoose/.env.test.local +18 -0
- package/lib/mongoose/.swcrc +1 -0
- package/lib/mongoose/package.json +2 -4
- package/lib/mongoose/src/app.ts +6 -7
- package/lib/mongoose/src/config/index.ts +5 -0
- package/lib/mongoose/src/databases/index.ts +2 -5
- package/lib/mongoose/src/middlewares/auth.middleware.ts +2 -2
- package/lib/mongoose/src/server.ts +0 -2
- package/lib/mongoose/src/services/auth.service.ts +2 -2
- package/lib/mongoose/src/utils/logger.ts +2 -2
- package/lib/mongoose/tsconfig.json +1 -0
- package/lib/prisma/.env.development.local +16 -0
- package/lib/prisma/.env.production.local +16 -0
- package/lib/prisma/.env.test.local +16 -0
- package/lib/prisma/.swcrc +1 -0
- package/lib/prisma/package.json +2 -4
- package/lib/prisma/src/app.ts +6 -7
- package/lib/prisma/src/config/index.ts +5 -0
- package/lib/prisma/src/middlewares/auth.middleware.ts +2 -2
- package/lib/prisma/src/server.ts +0 -2
- package/lib/prisma/src/services/auth.service.ts +2 -2
- package/lib/prisma/src/utils/logger.ts +2 -2
- package/lib/prisma/tsconfig.json +1 -0
- package/lib/routing-controllers/.env.development.local +13 -0
- package/lib/routing-controllers/.env.production.local +13 -0
- package/lib/routing-controllers/.env.test.local +13 -0
- package/lib/routing-controllers/.swcrc +1 -0
- package/lib/routing-controllers/package.json +2 -4
- package/lib/routing-controllers/src/app.ts +7 -8
- package/lib/routing-controllers/src/config/index.ts +5 -0
- package/lib/routing-controllers/src/middlewares/auth.middleware.ts +2 -2
- package/lib/routing-controllers/src/server.ts +0 -2
- package/lib/routing-controllers/src/services/auth.service.ts +2 -2
- package/lib/routing-controllers/src/utils/logger.ts +2 -2
- package/lib/routing-controllers/tsconfig.json +1 -0
- package/lib/sequelize/.env.development.local +20 -0
- package/lib/sequelize/.env.production.local +20 -0
- package/lib/sequelize/.env.test.local +20 -0
- package/lib/sequelize/.swcrc +1 -0
- package/lib/sequelize/package.json +2 -4
- package/lib/sequelize/src/app.ts +6 -7
- package/lib/sequelize/src/config/index.ts +5 -0
- package/lib/sequelize/src/databases/index.ts +7 -8
- package/lib/sequelize/src/middlewares/auth.middleware.ts +2 -2
- package/lib/sequelize/src/server.ts +0 -2
- package/lib/sequelize/src/services/auth.service.ts +2 -2
- package/lib/sequelize/src/utils/logger.ts +2 -2
- package/lib/sequelize/tsconfig.json +1 -0
- package/lib/typegoose/.dockerignore +18 -0
- package/lib/typegoose/.editorconfig +9 -0
- package/lib/typegoose/.env.development.local +18 -0
- package/lib/typegoose/.env.production.local +18 -0
- package/lib/typegoose/.env.test.local +18 -0
- package/lib/typegoose/.eslintignore +1 -0
- package/lib/typegoose/.eslintrc +18 -0
- package/lib/typegoose/.huskyrc +5 -0
- package/lib/typegoose/.lintstagedrc.json +5 -0
- package/lib/typegoose/.prettierrc +8 -0
- package/lib/typegoose/.swcrc +40 -0
- package/lib/typegoose/.vscode/launch.json +35 -0
- package/lib/typegoose/.vscode/settings.json +6 -0
- package/lib/typegoose/Dockerfile +24 -0
- package/lib/typegoose/Makefile +6 -0
- package/lib/typegoose/docker-compose.yml +46 -0
- package/lib/typegoose/ecosystem.config.js +57 -0
- package/lib/typegoose/jest.config.js +12 -0
- package/lib/typegoose/nginx.conf +40 -0
- package/lib/typegoose/nodemon.json +12 -0
- package/lib/typegoose/package.json +80 -0
- package/lib/typegoose/src/app.ts +93 -0
- package/lib/typegoose/src/config/index.ts +5 -0
- package/lib/typegoose/src/controllers/auth.controller.ts +46 -0
- package/lib/typegoose/src/controllers/index.controller.ts +13 -0
- package/lib/typegoose/src/controllers/users.controller.ts +65 -0
- package/lib/typegoose/src/databases/index.ts +3 -0
- package/lib/typegoose/src/dtos/users.dto.ts +9 -0
- package/lib/typegoose/src/exceptions/HttpException.ts +10 -0
- package/lib/typegoose/src/http/auth.http +32 -0
- package/lib/typegoose/src/http/users.http +34 -0
- package/lib/typegoose/src/interfaces/auth.interface.ts +15 -0
- package/lib/typegoose/src/interfaces/routes.interface.ts +6 -0
- package/lib/typegoose/src/interfaces/users.interface.ts +5 -0
- package/lib/typegoose/src/middlewares/auth.middleware.ts +32 -0
- package/lib/typegoose/src/middlewares/error.middleware.ts +17 -0
- package/lib/typegoose/src/middlewares/validation.middleware.ts +25 -0
- package/lib/typegoose/src/models/users.model.ts +18 -0
- package/lib/typegoose/src/routes/auth.route.ts +24 -0
- package/lib/typegoose/src/routes/index.route.ts +19 -0
- package/lib/typegoose/src/routes/users.route.ts +25 -0
- package/lib/typegoose/src/server.ts +11 -0
- package/lib/typegoose/src/services/auth.service.ts +61 -0
- package/lib/typegoose/src/services/users.service.ts +64 -0
- package/lib/typegoose/src/tests/auth.test.ts +83 -0
- package/lib/typegoose/src/tests/index.test.ts +18 -0
- package/lib/typegoose/src/tests/users.test.ts +133 -0
- package/lib/typegoose/src/utils/logger.ts +65 -0
- package/lib/typegoose/src/utils/util.ts +19 -0
- package/lib/typegoose/src/utils/validateEnv.ts +10 -0
- package/lib/typegoose/swagger.yaml +122 -0
- package/lib/typegoose/tsconfig.json +40 -0
- package/lib/typeorm/.env.development.local +20 -0
- package/lib/typeorm/.env.production.local +20 -0
- package/lib/typeorm/.env.test.local +20 -0
- package/lib/typeorm/.swcrc +1 -0
- package/lib/typeorm/package.json +2 -4
- package/lib/typeorm/src/app.ts +6 -7
- package/lib/typeorm/src/config/index.ts +5 -0
- package/lib/typeorm/src/databases/index.ts +6 -8
- package/lib/typeorm/src/middlewares/auth.middleware.ts +2 -2
- package/lib/typeorm/src/server.ts +0 -2
- package/lib/typeorm/src/services/auth.service.ts +2 -2
- package/lib/typeorm/src/utils/logger.ts +2 -2
- package/lib/typeorm/tsconfig.json +1 -0
- package/package.json +2 -1
- package/lib/default/.env +0 -1
- package/lib/default/src/configs/development.json +0 -12
- package/lib/default/src/configs/production.json +0 -12
- package/lib/default/src/configs/test.json +0 -12
- package/lib/default/src/index.ts +0 -1
- package/lib/graphql/.env +0 -1
- package/lib/graphql/src/configs/development.json +0 -19
- package/lib/graphql/src/configs/production.json +0 -19
- package/lib/graphql/src/configs/test.json +0 -19
- package/lib/graphql/src/index.ts +0 -1
- package/lib/graphql/src/interfaces/db.interface.ts +0 -7
- package/lib/knex/.env +0 -1
- package/lib/knex/src/configs/development.json +0 -19
- package/lib/knex/src/configs/production.json +0 -19
- package/lib/knex/src/configs/test.json +0 -19
- package/lib/knex/src/index.ts +0 -1
- package/lib/knex/src/interfaces/db.interface.ts +0 -7
- package/lib/mongoose/.env +0 -1
- package/lib/mongoose/src/configs/development.json +0 -17
- package/lib/mongoose/src/configs/production.json +0 -17
- package/lib/mongoose/src/configs/test.json +0 -17
- package/lib/mongoose/src/index.ts +0 -1
- package/lib/mongoose/src/interfaces/db.interface.ts +0 -5
- package/lib/prisma/.env +0 -10
- package/lib/prisma/src/configs/development.json +0 -12
- package/lib/prisma/src/configs/production.json +0 -12
- package/lib/prisma/src/configs/test.json +0 -12
- package/lib/prisma/src/index.ts +0 -1
- package/lib/routing-controllers/.env +0 -1
- package/lib/routing-controllers/src/configs/development.json +0 -12
- package/lib/routing-controllers/src/configs/production.json +0 -12
- package/lib/routing-controllers/src/configs/test.json +0 -12
- package/lib/routing-controllers/src/index.ts +0 -1
- package/lib/sequelize/.env +0 -1
- package/lib/sequelize/src/configs/development.json +0 -22
- package/lib/sequelize/src/configs/production.json +0 -22
- package/lib/sequelize/src/configs/test.json +0 -22
- package/lib/sequelize/src/index.ts +0 -1
- package/lib/sequelize/src/interfaces/db.interface.ts +0 -10
- package/lib/typeorm/.env +0 -1
- package/lib/typeorm/src/configs/development.json +0 -18
- package/lib/typeorm/src/configs/production.json +0 -18
- package/lib/typeorm/src/configs/test.json +0 -18
- package/lib/typeorm/src/index.ts +0 -1
- package/lib/typeorm/src/interfaces/db.interface.ts +0 -6
|
@@ -0,0 +1,122 @@
|
|
|
1
|
+
tags:
|
|
2
|
+
- name: users
|
|
3
|
+
description: users API
|
|
4
|
+
|
|
5
|
+
paths:
|
|
6
|
+
# [GET] users
|
|
7
|
+
/users:
|
|
8
|
+
get:
|
|
9
|
+
tags:
|
|
10
|
+
- users
|
|
11
|
+
summary: Find All Users
|
|
12
|
+
responses:
|
|
13
|
+
200:
|
|
14
|
+
description: 'OK'
|
|
15
|
+
500:
|
|
16
|
+
description: 'Server Error'
|
|
17
|
+
|
|
18
|
+
# [POST] users
|
|
19
|
+
post:
|
|
20
|
+
tags:
|
|
21
|
+
- users
|
|
22
|
+
summary: Add User
|
|
23
|
+
parameters:
|
|
24
|
+
- name: body
|
|
25
|
+
in: body
|
|
26
|
+
description: user Data
|
|
27
|
+
required: true
|
|
28
|
+
schema:
|
|
29
|
+
$ref: '#/definitions/users'
|
|
30
|
+
responses:
|
|
31
|
+
201:
|
|
32
|
+
description: 'Created'
|
|
33
|
+
400:
|
|
34
|
+
description: 'Bad Request'
|
|
35
|
+
409:
|
|
36
|
+
description: 'Conflict'
|
|
37
|
+
500:
|
|
38
|
+
description: 'Server Error'
|
|
39
|
+
|
|
40
|
+
# [GET] users/id
|
|
41
|
+
/users/{id}:
|
|
42
|
+
get:
|
|
43
|
+
tags:
|
|
44
|
+
- users
|
|
45
|
+
summary: Find User By Id
|
|
46
|
+
parameters:
|
|
47
|
+
- name: id
|
|
48
|
+
in: path
|
|
49
|
+
description: User Id
|
|
50
|
+
required: true
|
|
51
|
+
responses:
|
|
52
|
+
200:
|
|
53
|
+
description: 'OK'
|
|
54
|
+
409:
|
|
55
|
+
description: 'Conflict'
|
|
56
|
+
500:
|
|
57
|
+
description: 'Server Error'
|
|
58
|
+
|
|
59
|
+
# [PUT] users/id
|
|
60
|
+
put:
|
|
61
|
+
tags:
|
|
62
|
+
- users
|
|
63
|
+
summary: Update User By Id
|
|
64
|
+
parameters:
|
|
65
|
+
- name: id
|
|
66
|
+
in: path
|
|
67
|
+
description: user Id
|
|
68
|
+
required: true
|
|
69
|
+
- name: body
|
|
70
|
+
in: body
|
|
71
|
+
description: user Data
|
|
72
|
+
required: true
|
|
73
|
+
schema:
|
|
74
|
+
$ref: '#/definitions/users'
|
|
75
|
+
responses:
|
|
76
|
+
200:
|
|
77
|
+
description: 'OK'
|
|
78
|
+
400:
|
|
79
|
+
description: 'Bad Request'
|
|
80
|
+
409:
|
|
81
|
+
description: 'Conflict'
|
|
82
|
+
500:
|
|
83
|
+
description: 'Server Error'
|
|
84
|
+
|
|
85
|
+
# [DELETE] users/id
|
|
86
|
+
delete:
|
|
87
|
+
tags:
|
|
88
|
+
- users
|
|
89
|
+
summary: Delete User By Id
|
|
90
|
+
parameters:
|
|
91
|
+
- name: id
|
|
92
|
+
in: path
|
|
93
|
+
description: user Id
|
|
94
|
+
required: true
|
|
95
|
+
responses:
|
|
96
|
+
200:
|
|
97
|
+
description: 'OK'
|
|
98
|
+
409:
|
|
99
|
+
description: 'Conflict'
|
|
100
|
+
500:
|
|
101
|
+
description: 'Server Error'
|
|
102
|
+
|
|
103
|
+
# definitions
|
|
104
|
+
definitions:
|
|
105
|
+
users:
|
|
106
|
+
type: object
|
|
107
|
+
required:
|
|
108
|
+
- email
|
|
109
|
+
- password
|
|
110
|
+
properties:
|
|
111
|
+
id:
|
|
112
|
+
description: user Id
|
|
113
|
+
email:
|
|
114
|
+
type: string
|
|
115
|
+
description: user Email
|
|
116
|
+
password:
|
|
117
|
+
type: string
|
|
118
|
+
description: user Password
|
|
119
|
+
|
|
120
|
+
schemes:
|
|
121
|
+
- https
|
|
122
|
+
- http
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
{
|
|
2
|
+
"compileOnSave": false,
|
|
3
|
+
"compilerOptions": {
|
|
4
|
+
"target": "es2017",
|
|
5
|
+
"lib": ["es2017", "esnext.asynciterable"],
|
|
6
|
+
"typeRoots": ["node_modules/@types"],
|
|
7
|
+
"allowSyntheticDefaultImports": true,
|
|
8
|
+
"experimentalDecorators": true,
|
|
9
|
+
"emitDecoratorMetadata": true,
|
|
10
|
+
"forceConsistentCasingInFileNames": true,
|
|
11
|
+
"moduleResolution": "node",
|
|
12
|
+
"module": "commonjs",
|
|
13
|
+
"pretty": true,
|
|
14
|
+
"sourceMap": true,
|
|
15
|
+
"declaration": true,
|
|
16
|
+
"outDir": "dist",
|
|
17
|
+
"allowJs": true,
|
|
18
|
+
"noEmit": false,
|
|
19
|
+
"esModuleInterop": true,
|
|
20
|
+
"resolveJsonModule": true,
|
|
21
|
+
"importHelpers": true,
|
|
22
|
+
"baseUrl": "src",
|
|
23
|
+
"paths": {
|
|
24
|
+
"@/*": ["*"],
|
|
25
|
+
"@config": ["config"],
|
|
26
|
+
"@controllers/*": ["controllers/*"],
|
|
27
|
+
"@databases": ["databases"],
|
|
28
|
+
"@dtos/*": ["dtos/*"],
|
|
29
|
+
"@exceptions/*": ["exceptions/*"],
|
|
30
|
+
"@interfaces/*": ["interfaces/*"],
|
|
31
|
+
"@middlewares/*": ["middlewares/*"],
|
|
32
|
+
"@models/*": ["models/*"],
|
|
33
|
+
"@routes/*": ["routes/*"],
|
|
34
|
+
"@services/*": ["services/*"],
|
|
35
|
+
"@utils/*": ["utils/*"]
|
|
36
|
+
}
|
|
37
|
+
},
|
|
38
|
+
"include": ["src/**/*.ts", "src/**/*.json", ".env"],
|
|
39
|
+
"exclude": ["node_modules", "src/http", "src/logs", "src/tests"]
|
|
40
|
+
}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
# PORT
|
|
2
|
+
PORT = 3000
|
|
3
|
+
|
|
4
|
+
# DATABASE
|
|
5
|
+
DB_HOST = localhost
|
|
6
|
+
DB_PORT = 5432
|
|
7
|
+
DB_USER = root
|
|
8
|
+
DB_PASSWORD = password
|
|
9
|
+
DB_DATABASE = test
|
|
10
|
+
|
|
11
|
+
# TOKEN
|
|
12
|
+
SECRET_KEY = secretKey
|
|
13
|
+
|
|
14
|
+
# LOG
|
|
15
|
+
LOG_FORMAT = dev
|
|
16
|
+
LOG_DIR = ../logs
|
|
17
|
+
|
|
18
|
+
# CORS
|
|
19
|
+
ORIGIN = *
|
|
20
|
+
CREDENTIALS = true
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
# PORT
|
|
2
|
+
PORT = 3000
|
|
3
|
+
|
|
4
|
+
# DATABASE
|
|
5
|
+
DB_HOST = localhost
|
|
6
|
+
DB_PORT = 5432
|
|
7
|
+
DB_USER = root
|
|
8
|
+
DB_PASSWORD = password
|
|
9
|
+
DB_DATABASE = test
|
|
10
|
+
|
|
11
|
+
# TOKEN
|
|
12
|
+
SECRET_KEY = secretKey
|
|
13
|
+
|
|
14
|
+
# LOG
|
|
15
|
+
LOG_FORMAT = combined
|
|
16
|
+
LOG_DIR = ../logs
|
|
17
|
+
|
|
18
|
+
# CORS
|
|
19
|
+
ORIGIN = your.domain.com
|
|
20
|
+
CREDENTIALS = true
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
# PORT
|
|
2
|
+
PORT = 3000
|
|
3
|
+
|
|
4
|
+
# DATABASE
|
|
5
|
+
DB_HOST = localhost
|
|
6
|
+
DB_PORT = 5432
|
|
7
|
+
DB_USER = root
|
|
8
|
+
DB_PASSWORD = password
|
|
9
|
+
DB_DATABASE = test
|
|
10
|
+
|
|
11
|
+
# TOKEN
|
|
12
|
+
SECRET_KEY = secretKey
|
|
13
|
+
|
|
14
|
+
# LOG
|
|
15
|
+
LOG_FORMAT = dev
|
|
16
|
+
LOG_DIR = ../logs
|
|
17
|
+
|
|
18
|
+
# CORS
|
|
19
|
+
ORIGIN = *
|
|
20
|
+
CREDENTIALS = true
|
package/lib/typeorm/.swcrc
CHANGED
package/lib/typeorm/package.json
CHANGED
|
@@ -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": "
|
|
11
|
-
"build:
|
|
10
|
+
"build": "tsc && tsc-alias",
|
|
11
|
+
"build:swc": "swc src -d dist --source-maps --copy-files",
|
|
12
12
|
"test": "jest --forceExit --detectOpenHandles",
|
|
13
13
|
"lint": "eslint --ignore-path .gitignore --ext .ts src/",
|
|
14
14
|
"lint:fix": "npm run lint -- --fix",
|
|
@@ -20,7 +20,6 @@
|
|
|
20
20
|
"class-transformer": "^0.4.0",
|
|
21
21
|
"class-validator": "^0.13.1",
|
|
22
22
|
"compression": "^1.7.4",
|
|
23
|
-
"config": "^3.3.6",
|
|
24
23
|
"cookie-parser": "^1.4.5",
|
|
25
24
|
"cors": "^2.8.5",
|
|
26
25
|
"dotenv": "^10.0.0",
|
|
@@ -43,7 +42,6 @@
|
|
|
43
42
|
"@swc/core": "^1.2.108",
|
|
44
43
|
"@types/bcrypt": "^5.0.0",
|
|
45
44
|
"@types/compression": "^1.7.1",
|
|
46
|
-
"@types/config": "^0.0.39",
|
|
47
45
|
"@types/cookie-parser": "^1.4.2",
|
|
48
46
|
"@types/cors": "^2.8.11",
|
|
49
47
|
"@types/dotenv": "^8.2.0",
|
package/lib/typeorm/src/app.ts
CHANGED
|
@@ -1,8 +1,6 @@
|
|
|
1
1
|
import 'reflect-metadata';
|
|
2
|
-
import '@/index';
|
|
3
2
|
import cookieParser from 'cookie-parser';
|
|
4
3
|
import cors from 'cors';
|
|
5
|
-
import config from 'config';
|
|
6
4
|
import express from 'express';
|
|
7
5
|
import helmet from 'helmet';
|
|
8
6
|
import hpp from 'hpp';
|
|
@@ -11,6 +9,7 @@ import compression from 'compression';
|
|
|
11
9
|
import swaggerUi from 'swagger-ui-express';
|
|
12
10
|
import swaggerJSDoc from 'swagger-jsdoc';
|
|
13
11
|
import { createConnection } from 'typeorm';
|
|
12
|
+
import { NODE_ENV, PORT, LOG_FORMAT, ORIGIN, CREDENTIALS } from '@config';
|
|
14
13
|
import { dbConnection } from '@databases';
|
|
15
14
|
import { Routes } from '@interfaces/routes.interface';
|
|
16
15
|
import errorMiddleware from '@middlewares/error.middleware';
|
|
@@ -18,13 +17,13 @@ import { logger, stream } from '@utils/logger';
|
|
|
18
17
|
|
|
19
18
|
class App {
|
|
20
19
|
public app: express.Application;
|
|
21
|
-
public port: string | number;
|
|
22
20
|
public env: string;
|
|
21
|
+
public port: string | number;
|
|
23
22
|
|
|
24
23
|
constructor(routes: Routes[]) {
|
|
25
24
|
this.app = express();
|
|
26
|
-
this.
|
|
27
|
-
this.
|
|
25
|
+
this.env = NODE_ENV || 'development';
|
|
26
|
+
this.port = PORT || 3000;
|
|
28
27
|
|
|
29
28
|
this.env !== 'test' && this.connectToDatabase();
|
|
30
29
|
this.initializeMiddlewares();
|
|
@@ -51,8 +50,8 @@ class App {
|
|
|
51
50
|
}
|
|
52
51
|
|
|
53
52
|
private initializeMiddlewares() {
|
|
54
|
-
this.app.use(morgan(
|
|
55
|
-
this.app.use(cors({ origin:
|
|
53
|
+
this.app.use(morgan(LOG_FORMAT, { stream }));
|
|
54
|
+
this.app.use(cors({ origin: ORIGIN, credentials: CREDENTIALS }));
|
|
56
55
|
this.app.use(hpp());
|
|
57
56
|
this.app.use(helmet());
|
|
58
57
|
this.app.use(compression());
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import { config } from 'dotenv';
|
|
2
|
+
config({ path: `.env.${process.env.NODE_ENV || 'development'}.local` });
|
|
3
|
+
|
|
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;
|
|
@@ -1,16 +1,14 @@
|
|
|
1
|
-
import config from 'config';
|
|
2
1
|
import { join } from 'path';
|
|
3
2
|
import { ConnectionOptions } from 'typeorm';
|
|
4
|
-
import {
|
|
3
|
+
import { DB_HOST, DB_PORT, DB_USER, DB_PASSWORD, DB_DATABASE } from '@config';
|
|
5
4
|
|
|
6
|
-
const { host, user, password, database }: dbConfig = config.get('dbConfig');
|
|
7
5
|
export const dbConnection: ConnectionOptions = {
|
|
8
6
|
type: 'postgres',
|
|
9
|
-
host:
|
|
10
|
-
port:
|
|
11
|
-
username:
|
|
12
|
-
password:
|
|
13
|
-
database:
|
|
7
|
+
host: DB_HOST,
|
|
8
|
+
port: DB_PORT,
|
|
9
|
+
username: DB_USER,
|
|
10
|
+
password: DB_PASSWORD,
|
|
11
|
+
database: DB_DATABASE,
|
|
14
12
|
synchronize: true,
|
|
15
13
|
logging: false,
|
|
16
14
|
entities: [join(__dirname, '../**/*.entity{.ts,.js}')],
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import config from 'config';
|
|
2
1
|
import { NextFunction, Response } from 'express';
|
|
3
2
|
import { verify } from 'jsonwebtoken';
|
|
3
|
+
import { SECRET_KEY } from '@config';
|
|
4
4
|
import { UserEntity } from '@entities/users.entity';
|
|
5
5
|
import { HttpException } from '@exceptions/HttpException';
|
|
6
6
|
import { DataStoredInToken, RequestWithUser } from '@interfaces/auth.interface';
|
|
@@ -10,7 +10,7 @@ const authMiddleware = async (req: RequestWithUser, res: Response, next: NextFun
|
|
|
10
10
|
const Authorization = req.cookies['Authorization'] || (req.header('Authorization') ? req.header('Authorization').split('Bearer ')[1] : null);
|
|
11
11
|
|
|
12
12
|
if (Authorization) {
|
|
13
|
-
const secretKey: string =
|
|
13
|
+
const secretKey: string = SECRET_KEY;
|
|
14
14
|
const { id } = (await verify(Authorization, secretKey)) as DataStoredInToken;
|
|
15
15
|
const findUser = await UserEntity.findOne(id, { select: ['id', 'email', 'password'] });
|
|
16
16
|
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { compare, hash } from 'bcrypt';
|
|
2
|
-
import config from 'config';
|
|
3
2
|
import { sign } from 'jsonwebtoken';
|
|
4
3
|
import { EntityRepository, Repository } from 'typeorm';
|
|
4
|
+
import { SECRET_KEY } from '@config';
|
|
5
5
|
import { CreateUserDto } from '@dtos/users.dto';
|
|
6
6
|
import { UserEntity } from '@entities/users.entity';
|
|
7
7
|
import { HttpException } from '@exceptions/HttpException';
|
|
@@ -48,7 +48,7 @@ class AuthService extends Repository<UserEntity> {
|
|
|
48
48
|
|
|
49
49
|
public createToken(user: User): TokenData {
|
|
50
50
|
const dataStoredInToken: DataStoredInToken = { id: user.id };
|
|
51
|
-
const secretKey: string =
|
|
51
|
+
const secretKey: string = SECRET_KEY;
|
|
52
52
|
const expiresIn: number = 60 * 60;
|
|
53
53
|
|
|
54
54
|
return { expiresIn, token: sign(dataStoredInToken, secretKey, { expiresIn }) };
|
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
import config from 'config';
|
|
2
1
|
import { existsSync, mkdirSync } from 'fs';
|
|
3
2
|
import { join } from 'path';
|
|
4
3
|
import winston from 'winston';
|
|
5
4
|
import winstonDaily from 'winston-daily-rotate-file';
|
|
5
|
+
import { LOG_DIR } from '@config';
|
|
6
6
|
|
|
7
7
|
// logs dir
|
|
8
|
-
const logDir: string = join(__dirname,
|
|
8
|
+
const logDir: string = join(__dirname, LOG_DIR);
|
|
9
9
|
|
|
10
10
|
if (!existsSync(logDir)) {
|
|
11
11
|
mkdirSync(logDir);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "typescript-express-starter",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "8.1.2",
|
|
4
4
|
"description": "Quick and Easy TypeScript Express Starter",
|
|
5
5
|
"author": "AGUMON <ljlm0402@gmail.com>",
|
|
6
6
|
"license": "MIT",
|
|
@@ -11,6 +11,7 @@
|
|
|
11
11
|
"routing-controllers-openapi",
|
|
12
12
|
"sequelize",
|
|
13
13
|
"mongoose",
|
|
14
|
+
"typegoose",
|
|
14
15
|
"typeorm",
|
|
15
16
|
"knex",
|
|
16
17
|
"prisma",
|
package/lib/default/.env
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
PORT=3000
|
package/lib/default/src/index.ts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
process.env['NODE_CONFIG_DIR'] = __dirname + '/configs';
|
package/lib/graphql/.env
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
PORT=3000
|
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"env": "development",
|
|
3
|
-
"dbConfig": {
|
|
4
|
-
"host": "localhost",
|
|
5
|
-
"user": "root",
|
|
6
|
-
"port": 5432,
|
|
7
|
-
"password": "password",
|
|
8
|
-
"database": "test"
|
|
9
|
-
},
|
|
10
|
-
"secretKey": "secretKey",
|
|
11
|
-
"log": {
|
|
12
|
-
"format": "dev",
|
|
13
|
-
"dir": "../logs"
|
|
14
|
-
},
|
|
15
|
-
"cors": {
|
|
16
|
-
"origin": true,
|
|
17
|
-
"credentials": true
|
|
18
|
-
}
|
|
19
|
-
}
|
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"env": "production",
|
|
3
|
-
"dbConfig": {
|
|
4
|
-
"host": "localhost",
|
|
5
|
-
"user": "root",
|
|
6
|
-
"port": 5432,
|
|
7
|
-
"password": "password",
|
|
8
|
-
"database": "test"
|
|
9
|
-
},
|
|
10
|
-
"secretKey": "secretKey",
|
|
11
|
-
"log": {
|
|
12
|
-
"format": "combined",
|
|
13
|
-
"dir": "../logs"
|
|
14
|
-
},
|
|
15
|
-
"cors": {
|
|
16
|
-
"origin": "your.domain.com",
|
|
17
|
-
"credentials": true
|
|
18
|
-
}
|
|
19
|
-
}
|
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"env": "test",
|
|
3
|
-
"dbConfig": {
|
|
4
|
-
"host": "localhost",
|
|
5
|
-
"user": "root",
|
|
6
|
-
"port": 5432,
|
|
7
|
-
"password": "password",
|
|
8
|
-
"database": "test"
|
|
9
|
-
},
|
|
10
|
-
"secretKey": "secretKey",
|
|
11
|
-
"log": {
|
|
12
|
-
"format": "dev",
|
|
13
|
-
"dir": "../logs"
|
|
14
|
-
},
|
|
15
|
-
"cors": {
|
|
16
|
-
"origin": true,
|
|
17
|
-
"credentials": true
|
|
18
|
-
}
|
|
19
|
-
}
|
package/lib/graphql/src/index.ts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
process.env['NODE_CONFIG_DIR'] = __dirname + '/configs';
|
package/lib/knex/.env
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
PORT=3000
|
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"env": "development",
|
|
3
|
-
"dbConfig": {
|
|
4
|
-
"host": "localhost",
|
|
5
|
-
"user": "root",
|
|
6
|
-
"password": "password",
|
|
7
|
-
"database": "test",
|
|
8
|
-
"port": 3306
|
|
9
|
-
},
|
|
10
|
-
"secretKey": "secretKey",
|
|
11
|
-
"log": {
|
|
12
|
-
"format": "dev",
|
|
13
|
-
"dir": "../logs"
|
|
14
|
-
},
|
|
15
|
-
"cors": {
|
|
16
|
-
"origin": true,
|
|
17
|
-
"credentials": true
|
|
18
|
-
}
|
|
19
|
-
}
|
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"env": "production",
|
|
3
|
-
"dbConfig": {
|
|
4
|
-
"host": "localhost",
|
|
5
|
-
"user": "root",
|
|
6
|
-
"password": "password",
|
|
7
|
-
"database": "test",
|
|
8
|
-
"port": 3306
|
|
9
|
-
},
|
|
10
|
-
"secretKey": "secretKey",
|
|
11
|
-
"log": {
|
|
12
|
-
"format": "combined",
|
|
13
|
-
"dir": "../logs"
|
|
14
|
-
},
|
|
15
|
-
"cors": {
|
|
16
|
-
"origin": "your.domain.com",
|
|
17
|
-
"credentials": true
|
|
18
|
-
}
|
|
19
|
-
}
|
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"env": "test",
|
|
3
|
-
"dbConfig": {
|
|
4
|
-
"host": "localhost",
|
|
5
|
-
"user": "root",
|
|
6
|
-
"password": "password",
|
|
7
|
-
"database": "test",
|
|
8
|
-
"port": 3306
|
|
9
|
-
},
|
|
10
|
-
"secretKey": "secretKey",
|
|
11
|
-
"log": {
|
|
12
|
-
"format": "dev",
|
|
13
|
-
"dir": "../logs"
|
|
14
|
-
},
|
|
15
|
-
"cors": {
|
|
16
|
-
"origin": true,
|
|
17
|
-
"credentials": true
|
|
18
|
-
}
|
|
19
|
-
}
|
package/lib/knex/src/index.ts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
process.env['NODE_CONFIG_DIR'] = __dirname + '/configs';
|
package/lib/mongoose/.env
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
PORT=3000
|
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"env": "development",
|
|
3
|
-
"dbConfig": {
|
|
4
|
-
"host": "localhost",
|
|
5
|
-
"database": "test",
|
|
6
|
-
"port": 27017
|
|
7
|
-
},
|
|
8
|
-
"secretKey": "secretKey",
|
|
9
|
-
"log": {
|
|
10
|
-
"format": "dev",
|
|
11
|
-
"dir": "../logs"
|
|
12
|
-
},
|
|
13
|
-
"cors": {
|
|
14
|
-
"origin": true,
|
|
15
|
-
"credentials": true
|
|
16
|
-
}
|
|
17
|
-
}
|
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"env": "production",
|
|
3
|
-
"dbConfig": {
|
|
4
|
-
"host": "localhost",
|
|
5
|
-
"database": "test",
|
|
6
|
-
"port": 27017
|
|
7
|
-
},
|
|
8
|
-
"secretKey": "secretKey",
|
|
9
|
-
"log": {
|
|
10
|
-
"format": "combined",
|
|
11
|
-
"dir": "../logs"
|
|
12
|
-
},
|
|
13
|
-
"cors": {
|
|
14
|
-
"origin": "your.domain.com",
|
|
15
|
-
"credentials": true
|
|
16
|
-
}
|
|
17
|
-
}
|