typescript-express-starter 8.0.2 → 8.1.7
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 +21 -21
- package/README.md +25 -25
- 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/Makefile +26 -3
- 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/Makefile +26 -3
- package/lib/graphql/package.json +2 -4
- package/lib/graphql/src/app.ts +12 -10
- package/lib/graphql/src/config/index.ts +6 -0
- package/lib/graphql/src/databases/index.ts +6 -8
- package/lib/graphql/src/entities/users.entity.ts +1 -1
- package/lib/graphql/src/middlewares/auth.middleware.ts +2 -2
- package/lib/graphql/src/repositories/auth.repository.ts +3 -3
- package/lib/graphql/src/repositories/users.repository.ts +1 -1
- 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/Makefile +26 -3
- 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/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/Makefile +26 -3
- 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/Makefile +26 -3
- 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/Makefile +26 -3
- 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/Makefile +26 -3
- 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/starter.js +30 -8
- package/lib/typegoose/Makefile +26 -3
- package/lib/typegoose/package.json +3 -3
- 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/Makefile +26 -3
- 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 +1 -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
package/README.kr.md
CHANGED
|
@@ -9,6 +9,12 @@
|
|
|
9
9
|
|
|
10
10
|
<h4 align="center">🚀 타입스크립트 기반의 익스프레스 보일러 플레이트 스타터 패키지</h4>
|
|
11
11
|
|
|
12
|
+
<p align ="center">
|
|
13
|
+
<a href="https://nodei.co/npm/typescript-express-starter" target="_blank">
|
|
14
|
+
<img src="https://nodei.co/npm/typescript-express-starter.png" alt="npm 정보" />
|
|
15
|
+
</a>
|
|
16
|
+
</p>
|
|
17
|
+
|
|
12
18
|
<p align="center">
|
|
13
19
|
<a href="http://npm.im/typescript-express-starter" target="_blank">
|
|
14
20
|
<img src="https://img.shields.io/npm/v/typescript-express-starter.svg" alt="npm 버전" />
|
|
@@ -46,16 +52,6 @@
|
|
|
46
52
|
- [🇺🇸 영어](https://github.com/ljlm0402/typescript-express-starter/blob/master/README.md)
|
|
47
53
|
- [🇰🇷 한국어](https://github.com/ljlm0402/typescript-express-starter/blob/master/README.kr.md)
|
|
48
54
|
|
|
49
|
-
> 번역을 도와주실 분은 [이슈](https://github.com/ljlm0402/typescript-express-starter/issues/new?assignees=ljlm0402&labels=%F0%9F%92%B1+Translations&template=translations-language---.md&title=) 남겨주시기 바랍니다. 💜
|
|
50
|
-
|
|
51
|
-
<br />
|
|
52
|
-
|
|
53
|
-
## 웹 사이트 - 프로젝트 소개 및 홍보
|
|
54
|
-
|
|
55
|
-
- [💁🏻♂️ Dylan Iqbal :: A TypeScript Express Starter App](https://bit.ly/3rrZFZ9)
|
|
56
|
-
|
|
57
|
-
> 웹 사이트 및 블로그에 소개를 원하시는 분은 [이슈](https://github.com/ljlm0402/typescript-express-starter/issues/new?assignees=ljlm0402&labels=%F0%9F%91%80+Introducetion&template=introducetion-project---.md&title=) 남겨주시기 바랍니다. 💙
|
|
58
|
-
|
|
59
55
|
<br />
|
|
60
56
|
|
|
61
57
|
## 😎 프로젝트를 소개합니다.
|
|
@@ -96,17 +92,19 @@ $ npx typescript-express-starter "project name"
|
|
|
96
92
|
|
|
97
93
|
#### 템플릿 종류
|
|
98
94
|
|
|
99
|
-
| 이름
|
|
100
|
-
|
|
|
101
|
-
| Default
|
|
102
|
-
| Routing Controllers
|
|
103
|
-
| Sequelize
|
|
104
|
-
| Mongoose
|
|
105
|
-
| TypeORM
|
|
106
|
-
| Prisma
|
|
107
|
-
| Knex
|
|
108
|
-
| GraphQL
|
|
109
|
-
| Typegoose
|
|
95
|
+
| 이름 | 설명 |
|
|
96
|
+
| :-------------------------------------------------------------------------------------- | :------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ |
|
|
97
|
+
| Default | Express 기본 |
|
|
98
|
+
| [Routing Controllers](https://github.com/typestack/routing-controllers) | 데코레이터 사용량이 많은 구조화되고 선언적이며 아름답게 구성된 클래스 기반 컨트롤러 생성 |
|
|
99
|
+
| [Sequelize](https://github.com/sequelize/sequelize) | PostgreSQL, MySQL, MariaDB, SQLite, Microsoft SQL Server를 지원하는 Promise 패턴 기반의 Node.js ORM |
|
|
100
|
+
| [Mongoose](https://github.com/Automattic/mongoose) | Node.js와 MongoDB를 위한 ODM(Object Data Mapping) 라이브러리 |
|
|
101
|
+
| [TypeORM](https://github.com/typeorm/typeorm) | 자바스크립트, 타입스크립트과 함께 사용되어 Node.js, React Native, Expo에서 실행될 수 있는 ORM |
|
|
102
|
+
| [Prisma](https://github.com/prisma/prisma) | 데이터베이스에 데이터를 프로그래밍 언어의 객체와 매핑하여 기존에 SQL로 작성하던 데이터를 수정, 테이블 구조 변경등의 작업을 객체를 통해 프로그래밍적으로 할 수 있도록 해주는 ORM |
|
|
103
|
+
| [Knex](https://github.com/knex/knex) | 쿼리 빌더를 위한 라이브러리 |
|
|
104
|
+
| [GraphQL](https://github.com/graphql/graphql-js) | API 용 쿼리 언어이며 기존 데이터로 이러한 쿼리를 수행하기위한 런타임 |
|
|
105
|
+
| [Typegoose](https://github.com/typegoose/typegoose) | 타입스크립트 클래스를 사용하여 몽구스 모델 정의 |
|
|
106
|
+
| [Mikro ORM](https://github.com/mikro-orm/mikro-orm) (개발중) | 데이터 매퍼, 작업 단위 및 아이덴티티 맵 패턴을 기반으로 하는 Node.js용 TypeScript ORM. MongoDB, MySQL, MariaDB, PostgreSQL 및 SQLite 데이터베이스를 지원 |
|
|
107
|
+
| [Sequelize Typescript](https://github.com/RobinBuschmann/sequelize-typescript) (개발중) | 데코레이터 및 Sequelize를 위한 몇 가지 기능 |
|
|
110
108
|
|
|
111
109
|
## 🛎 Script 명령어
|
|
112
110
|
|
|
@@ -372,6 +370,8 @@ VSCode Extension에서 [REST Client](https://marketplace.visualstudio.com/items?
|
|
|
372
370
|
|
|
373
371
|
- David Stewart [https://github.com/davidjmstewart](https://github.com/davidjmstewart)
|
|
374
372
|
|
|
373
|
+
- JagTheFriend [JagTheFriend](https://github.com/JagTheFriend)
|
|
374
|
+
|
|
375
375
|
## 💳 라이센스
|
|
376
376
|
|
|
377
377
|
[MIT](LICENSE)
|
package/README.md
CHANGED
|
@@ -9,6 +9,12 @@
|
|
|
9
9
|
|
|
10
10
|
<h4 align="center">🚀 Express RESTful API Boilerplate Using TypeScript</h4>
|
|
11
11
|
|
|
12
|
+
<p align ="center">
|
|
13
|
+
<a href="https://nodei.co/npm/typescript-express-starter" target="_blank">
|
|
14
|
+
<img src="https://nodei.co/npm/typescript-express-starter.png" alt="npm Info" />
|
|
15
|
+
</a>
|
|
16
|
+
</p>
|
|
17
|
+
|
|
12
18
|
<p align="center">
|
|
13
19
|
<a href="http://npm.im/typescript-express-starter" target="_blank">
|
|
14
20
|
<img src="https://img.shields.io/npm/v/typescript-express-starter.svg" alt="npm Version" />
|
|
@@ -46,16 +52,6 @@
|
|
|
46
52
|
- [🇺🇸 English](https://github.com/ljlm0402/typescript-express-starter/blob/master/README.md)
|
|
47
53
|
- [🇰🇷 Korean](https://github.com/ljlm0402/typescript-express-starter/blob/master/README.kr.md)
|
|
48
54
|
|
|
49
|
-
> Want to translate to your own language? please open an [issue](https://github.com/ljlm0402/typescript-express-starter/issues/new?assignees=ljlm0402&labels=%F0%9F%92%B1+Translations&template=translations-language---.md&title=) 💜
|
|
50
|
-
|
|
51
|
-
<br />
|
|
52
|
-
|
|
53
|
-
## Web Site - Project Introduction
|
|
54
|
-
|
|
55
|
-
- [💁🏻♂️ Dylan Iqbal :: A TypeScript Express Starter App](https://bit.ly/3rrZFZ9)
|
|
56
|
-
|
|
57
|
-
> Want to be featured on your blog or site? please open an [issue](https://github.com/ljlm0402/typescript-express-starter/issues/new?assignees=ljlm0402&labels=%F0%9F%91%80+Introducetion&template=introducetion-project---.md&title=) 💙
|
|
58
|
-
|
|
59
55
|
<br />
|
|
60
56
|
|
|
61
57
|
## 😎 Introducing The Project
|
|
@@ -100,17 +96,19 @@ Start your typescript-express-starter app in development mode at `http://localho
|
|
|
100
96
|
|
|
101
97
|
#### Template Type
|
|
102
98
|
|
|
103
|
-
| Name
|
|
104
|
-
|
|
|
105
|
-
| Default
|
|
106
|
-
| Routing Controllers
|
|
107
|
-
| Sequelize
|
|
108
|
-
| Mongoose
|
|
109
|
-
| TypeORM
|
|
110
|
-
| Prisma
|
|
111
|
-
| Knex
|
|
112
|
-
| GraphQL
|
|
113
|
-
| Typegoose
|
|
99
|
+
| Name | Description |
|
|
100
|
+
| :--------------------------------------------------------------------------------------- | :--------------------------------------------------------------------------------------------------------------------------------------------------------- |
|
|
101
|
+
| Default | Express Default |
|
|
102
|
+
| [Routing Controllers](https://github.com/typestack/routing-controllers) | Create structured, declarative and beautifully organized class-based controllers with heavy decorators usage |
|
|
103
|
+
| [Sequelize](https://github.com/sequelize/sequelize) | Easy to use multi SQL dialect ORM for Node.js |
|
|
104
|
+
| [Mongoose](https://github.com/Automattic/mongoose) | MongoDB Object Modeling(ODM) designed to work in an asynchronous environment |
|
|
105
|
+
| [TypeORM](https://github.com/typeorm/typeorm) | An ORM that can run in Node.js and Others |
|
|
106
|
+
| [Prisma](https://github.com/prisma/prisma) | Modern Database Access for TypeScript & Node.js |
|
|
107
|
+
| [Knex](https://github.com/knex/knex) | SQL query builder for Postgres, MySQL, MariaDB, SQLite3 and Oracle |
|
|
108
|
+
| [GraphQL](https://github.com/graphql/graphql-js) | query language for APIs and a runtime for fulfilling those queries with your existing data |
|
|
109
|
+
| [Typegoose](https://github.com/typegoose/typegoose) | Define Mongoose models using TypeScript classes |
|
|
110
|
+
| [Mikro ORM](https://github.com/mikro-orm/mikro-orm) (Develop) | TypeScript ORM for Node.js based on Data Mapper, Unit of Work and Identity Map patterns. Supports MongoDB, MySQL, MariaDB, PostgreSQL and SQLite databases |
|
|
111
|
+
| [Sequelize Typescript](https://github.com/RobinBuschmann/sequelize-typescript) (Develop) | Decorators and some other features for sequelize |
|
|
114
112
|
|
|
115
113
|
## 🛎 Available Commands for the Server
|
|
116
114
|
|
|
@@ -243,9 +241,7 @@ Modify `.swcrc` file to your source code.
|
|
|
243
241
|
│
|
|
244
242
|
├── /src
|
|
245
243
|
│ ├── /configs
|
|
246
|
-
│ │ ├──
|
|
247
|
-
│ │ ├── production.json
|
|
248
|
-
│ │ └── test.json
|
|
244
|
+
│ │ ├── index.ts
|
|
249
245
|
│ │
|
|
250
246
|
│ ├── /controllers
|
|
251
247
|
│ │ ├── auth.controller.ts
|
|
@@ -300,7 +296,9 @@ Modify `.swcrc` file to your source code.
|
|
|
300
296
|
│
|
|
301
297
|
├── .dockerignore
|
|
302
298
|
├── .editorconfig
|
|
303
|
-
├── .env
|
|
299
|
+
├── .env.development.local
|
|
300
|
+
├── .env.production.local
|
|
301
|
+
├── .env.test.local
|
|
304
302
|
├── .eslintignore
|
|
305
303
|
├── .eslintrc
|
|
306
304
|
├── .gitignore
|
|
@@ -377,6 +375,8 @@ Modify `.swcrc` file to your source code.
|
|
|
377
375
|
|
|
378
376
|
- David Stewart [https://github.com/davidjmstewart](https://github.com/davidjmstewart)
|
|
379
377
|
|
|
378
|
+
- JagTheFriend [JagTheFriend](https://github.com/JagTheFriend)
|
|
379
|
+
|
|
380
380
|
## 💳 License
|
|
381
381
|
|
|
382
382
|
[MIT](LICENSE)
|
package/lib/default/.swcrc
CHANGED
package/lib/default/Makefile
CHANGED
|
@@ -1,6 +1,29 @@
|
|
|
1
|
+
# app name should be overridden.
|
|
2
|
+
# ex) production-stage: make build APP_NAME=<APP_NAME>
|
|
3
|
+
# ex) development-stage: make build-dev APP_NAME=<APP_NAME>
|
|
4
|
+
|
|
5
|
+
APP_NAME = typescript-express
|
|
6
|
+
APP_NAME := $(APP_NAME)
|
|
7
|
+
|
|
8
|
+
.PHONY: build
|
|
9
|
+
# Build the container image - Dvelopment
|
|
10
|
+
build-dev:
|
|
11
|
+
docker build -t ${APP_NAME}\
|
|
12
|
+
--target development-build-stage\
|
|
13
|
+
-f Dockerfile .
|
|
14
|
+
|
|
15
|
+
# Build the container image - Production
|
|
1
16
|
build:
|
|
2
|
-
docker build -t ${
|
|
17
|
+
docker build -t ${APP_NAME}\
|
|
18
|
+
--target production-build-stage\
|
|
19
|
+
-f Dockerfile .
|
|
20
|
+
|
|
21
|
+
# Clean the container image
|
|
3
22
|
clean:
|
|
4
|
-
docker rmi -f ${
|
|
23
|
+
docker rmi -f ${APP_NAME}
|
|
24
|
+
|
|
25
|
+
# Run the container image
|
|
5
26
|
run:
|
|
6
|
-
docker run -d -p
|
|
27
|
+
docker run -d -it -p 3000:3000 ${APP_NAME}
|
|
28
|
+
|
|
29
|
+
all: build
|
package/lib/default/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": "swc src -d dist --source-maps --copy-files",
|
|
11
|
+
"build:tsc": "tsc && tsc-alias",
|
|
12
12
|
"test": "jest --forceExit --detectOpenHandles",
|
|
13
13
|
"lint": "eslint --ignore-path .gitignore --ext .ts src/",
|
|
14
14
|
"lint:fix": "npm run lint -- --fix",
|
|
@@ -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",
|
|
@@ -40,7 +39,6 @@
|
|
|
40
39
|
"@swc/core": "^1.2.108",
|
|
41
40
|
"@types/bcrypt": "^5.0.0",
|
|
42
41
|
"@types/compression": "^1.7.1",
|
|
43
|
-
"@types/config": "^0.0.39",
|
|
44
42
|
"@types/cookie-parser": "^1.4.2",
|
|
45
43
|
"@types/cors": "^2.8.11",
|
|
46
44
|
"@types/dotenv": "^8.2.0",
|
package/lib/default/src/app.ts
CHANGED
|
@@ -1,27 +1,26 @@
|
|
|
1
|
-
import '@/index';
|
|
2
1
|
import compression from 'compression';
|
|
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';
|
|
9
7
|
import morgan from 'morgan';
|
|
10
8
|
import swaggerJSDoc from 'swagger-jsdoc';
|
|
11
9
|
import swaggerUi from 'swagger-ui-express';
|
|
10
|
+
import { NODE_ENV, PORT, LOG_FORMAT, ORIGIN, CREDENTIALS } from '@config';
|
|
12
11
|
import { Routes } from '@interfaces/routes.interface';
|
|
13
12
|
import errorMiddleware from '@middlewares/error.middleware';
|
|
14
13
|
import { logger, stream } from '@utils/logger';
|
|
15
14
|
|
|
16
15
|
class App {
|
|
17
16
|
public app: express.Application;
|
|
18
|
-
public port: string | number;
|
|
19
17
|
public env: string;
|
|
18
|
+
public port: string | number;
|
|
20
19
|
|
|
21
20
|
constructor(routes: Routes[]) {
|
|
22
21
|
this.app = express();
|
|
23
|
-
this.
|
|
24
|
-
this.
|
|
22
|
+
this.env = NODE_ENV || 'development';
|
|
23
|
+
this.port = PORT || 3000;
|
|
25
24
|
|
|
26
25
|
this.initializeMiddlewares();
|
|
27
26
|
this.initializeRoutes(routes);
|
|
@@ -43,8 +42,8 @@ class App {
|
|
|
43
42
|
}
|
|
44
43
|
|
|
45
44
|
private initializeMiddlewares() {
|
|
46
|
-
this.app.use(morgan(
|
|
47
|
-
this.app.use(cors({ origin:
|
|
45
|
+
this.app.use(morgan(LOG_FORMAT, { stream }));
|
|
46
|
+
this.app.use(cors({ origin: ORIGIN, credentials: CREDENTIALS }));
|
|
48
47
|
this.app.use(hpp());
|
|
49
48
|
this.app.use(helmet());
|
|
50
49
|
this.app.use(compression());
|
|
@@ -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 { HttpException } from '@exceptions/HttpException';
|
|
5
5
|
import { DataStoredInToken, RequestWithUser } from '@interfaces/auth.interface';
|
|
6
6
|
import userModel from '@models/users.model';
|
|
@@ -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 verificationResponse = (await verify(Authorization, secretKey)) as DataStoredInToken;
|
|
15
15
|
const userId = verificationResponse.id;
|
|
16
16
|
const findUser = userModel.find(user => user.id === userId);
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { hash, compare } from 'bcrypt';
|
|
2
|
-
import config from 'config';
|
|
3
2
|
import { sign } from 'jsonwebtoken';
|
|
3
|
+
import { SECRET_KEY } from '@config';
|
|
4
4
|
import { CreateUserDto } from '@dtos/users.dto';
|
|
5
5
|
import { HttpException } from '@exceptions/HttpException';
|
|
6
6
|
import { DataStoredInToken, TokenData } from '@interfaces/auth.interface';
|
|
@@ -49,7 +49,7 @@ class AuthService {
|
|
|
49
49
|
|
|
50
50
|
public createToken(user: User): TokenData {
|
|
51
51
|
const dataStoredInToken: DataStoredInToken = { id: user.id };
|
|
52
|
-
const secretKey: string =
|
|
52
|
+
const secretKey: string = SECRET_KEY;
|
|
53
53
|
const expiresIn: number = 60 * 60;
|
|
54
54
|
|
|
55
55
|
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);
|
|
@@ -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 = true
|
|
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 = false
|
|
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 = true
|
|
20
|
+
CREDENTIALS = true
|
package/lib/graphql/.swcrc
CHANGED
package/lib/graphql/Makefile
CHANGED
|
@@ -1,6 +1,29 @@
|
|
|
1
|
+
# app name should be overridden.
|
|
2
|
+
# ex) production-stage: make build APP_NAME=<APP_NAME>
|
|
3
|
+
# ex) development-stage: make build-dev APP_NAME=<APP_NAME>
|
|
4
|
+
|
|
5
|
+
APP_NAME = typescript-express
|
|
6
|
+
APP_NAME := $(APP_NAME)
|
|
7
|
+
|
|
8
|
+
.PHONY: build
|
|
9
|
+
# Build the container image - Dvelopment
|
|
10
|
+
build-dev:
|
|
11
|
+
docker build -t ${APP_NAME}\
|
|
12
|
+
--target development-build-stage\
|
|
13
|
+
-f Dockerfile .
|
|
14
|
+
|
|
15
|
+
# Build the container image - Production
|
|
1
16
|
build:
|
|
2
|
-
docker build -t ${
|
|
17
|
+
docker build -t ${APP_NAME}\
|
|
18
|
+
--target production-build-stage\
|
|
19
|
+
-f Dockerfile .
|
|
20
|
+
|
|
21
|
+
# Clean the container image
|
|
3
22
|
clean:
|
|
4
|
-
docker rmi -f ${
|
|
23
|
+
docker rmi -f ${APP_NAME}
|
|
24
|
+
|
|
25
|
+
# Run the container image
|
|
5
26
|
run:
|
|
6
|
-
docker run -d -p
|
|
27
|
+
docker run -d -it -p 3000:3000 ${APP_NAME}
|
|
28
|
+
|
|
29
|
+
all: build
|
package/lib/graphql/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": "swc src -d dist --source-maps --copy-files",
|
|
11
|
+
"build:tsc": "tsc && tsc-alias",
|
|
12
12
|
"test": "jest --forceExit --detectOpenHandles",
|
|
13
13
|
"lint": "eslint --ignore-path .gitignore --ext .ts src/",
|
|
14
14
|
"lint:fix": "npm run lint -- --fix",
|
|
@@ -21,7 +21,6 @@
|
|
|
21
21
|
"bcrypt": "^5.0.1",
|
|
22
22
|
"class-validator": "^0.13.1",
|
|
23
23
|
"compression": "^1.7.4",
|
|
24
|
-
"config": "^3.3.6",
|
|
25
24
|
"cookie-parser": "^1.4.5",
|
|
26
25
|
"cors": "^2.8.5",
|
|
27
26
|
"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/graphql/src/app.ts
CHANGED
|
@@ -1,16 +1,15 @@
|
|
|
1
1
|
import 'reflect-metadata';
|
|
2
|
-
import '@/index';
|
|
3
2
|
import { ApolloServerPluginLandingPageProductionDefault, ApolloServerPluginLandingPageLocalDefault } from 'apollo-server-core';
|
|
4
3
|
import { ApolloServer } from 'apollo-server-express';
|
|
5
4
|
import compression from 'compression';
|
|
6
5
|
import cookieParser from 'cookie-parser';
|
|
7
6
|
import cors from 'cors';
|
|
8
|
-
import config from 'config';
|
|
9
7
|
import express from 'express';
|
|
10
8
|
import helmet from 'helmet';
|
|
11
9
|
import hpp from 'hpp';
|
|
12
10
|
import { buildSchema } from 'type-graphql';
|
|
13
11
|
import { createConnection } from 'typeorm';
|
|
12
|
+
import { NODE_ENV, PORT, ORIGIN, CREDENTIALS } from '@config';
|
|
14
13
|
import { dbConnection } from '@databases';
|
|
15
14
|
import { authMiddleware, authChecker } from '@middlewares/auth.middleware';
|
|
16
15
|
import errorMiddleware from '@middlewares/error.middleware';
|
|
@@ -18,13 +17,13 @@ import { logger, responseLogger, errorLogger } 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(resolvers) {
|
|
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.connectToDatabase();
|
|
30
29
|
this.initializeMiddlewares();
|
|
@@ -51,9 +50,12 @@ class App {
|
|
|
51
50
|
}
|
|
52
51
|
|
|
53
52
|
private initializeMiddlewares() {
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
53
|
+
if (this.env === 'production') {
|
|
54
|
+
this.app.use(hpp());
|
|
55
|
+
this.app.use(helmet());
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
this.app.use(cors({ origin: ORIGIN, credentials: CREDENTIALS }));
|
|
57
59
|
this.app.use(compression());
|
|
58
60
|
this.app.use(express.json());
|
|
59
61
|
this.app.use(express.urlencoded({ extended: true }));
|
|
@@ -69,7 +71,7 @@ class App {
|
|
|
69
71
|
const apolloServer = new ApolloServer({
|
|
70
72
|
schema: schema,
|
|
71
73
|
plugins: [
|
|
72
|
-
|
|
74
|
+
this.env === 'production'
|
|
73
75
|
? ApolloServerPluginLandingPageProductionDefault({ footer: false })
|
|
74
76
|
: ApolloServerPluginLandingPageLocalDefault({ footer: false }),
|
|
75
77
|
],
|
|
@@ -94,7 +96,7 @@ class App {
|
|
|
94
96
|
});
|
|
95
97
|
|
|
96
98
|
await apolloServer.start();
|
|
97
|
-
apolloServer.applyMiddleware({ app: this.app, cors:
|
|
99
|
+
apolloServer.applyMiddleware({ app: this.app, cors: ORIGIN, path: '/graphql' });
|
|
98
100
|
}
|
|
99
101
|
|
|
100
102
|
private initializeErrorHandling() {
|
|
@@ -0,0 +1,6 @@
|
|
|
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 ORIGIN = process.env.ORIGIN === 'true';
|
|
6
|
+
export const { NODE_ENV, PORT, DB_HOST, DB_PORT, DB_USER, DB_PASSWORD, DB_DATABASE, SECRET_KEY, LOG_FORMAT, LOG_DIR } = process.env;
|
|
@@ -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, port, 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}')],
|