typescript-express-starter 10.2.1 → 11.0.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 +136 -287
- package/README.md +134 -274
- package/bin/ast-utils.js +226 -0
- package/bin/common.js +312 -0
- package/bin/config.js +80 -0
- package/bin/db-map.js +169 -0
- package/bin/errors.js +129 -0
- package/bin/performance.js +203 -0
- package/bin/starter.js +359 -0
- package/bin/validators.js +146 -0
- package/devtools/biome/.biome.json +34 -0
- package/devtools/biome/.biomeignore +29 -0
- package/devtools/docker/.dockerignore +27 -0
- package/devtools/docker/Dockerfile.dev +20 -0
- package/devtools/docker/Dockerfile.prod +35 -0
- package/{lib/default → devtools/docker}/Makefile +3 -0
- package/devtools/docker/nginx.conf +67 -0
- package/devtools/eslint/eslint.config.cjs +23 -0
- package/devtools/husky/.husky/commit-msg +4 -0
- package/devtools/husky/.husky/pre-commit +4 -0
- package/devtools/husky/.husky/pre-push +4 -0
- package/devtools/jest/jest.config.cjs +2 -0
- package/devtools/jest/jest.config.ts +25 -0
- package/devtools/jest/src/test/e2e/auth.e2e.spec.ts +40 -0
- package/devtools/jest/src/test/e2e/users.e2e.spec.ts +63 -0
- package/devtools/jest/src/test/setup.ts +31 -0
- package/devtools/jest/src/test/unit/entities/user.entity.spec.ts +279 -0
- package/devtools/jest/src/test/unit/services/auth.service.spec.ts +75 -0
- package/devtools/jest/src/test/unit/services/users.service.spec.ts +109 -0
- package/devtools/oxlint/.oxlintrc.json +57 -0
- package/devtools/pm2/ecosystem.config.js +59 -0
- package/devtools/swagger/swagger.yaml +124 -0
- package/{lib/prisma → devtools/swc}/.swcrc +2 -1
- package/devtools/tsup/tsup.config.ts +15 -0
- package/devtools/vitest/src/test/e2e/auth.e2e.spec.ts +41 -0
- package/devtools/vitest/src/test/e2e/users.e2e.spec.ts +64 -0
- package/devtools/vitest/src/test/setup.ts +31 -0
- package/devtools/vitest/src/test/unit/services/auth.service.spec.ts +70 -0
- package/devtools/vitest/src/test/unit/services/users.service.spec.ts +90 -0
- package/devtools/vitest/vitest.config.ts +22 -0
- package/package.json +24 -11
- package/templates/default/nodemon.json +7 -0
- package/templates/default/package.json +48 -0
- package/templates/default/src/app.ts +118 -0
- package/templates/default/src/config/env.ts +78 -0
- package/templates/default/src/controllers/auth.controller.ts +40 -0
- package/templates/default/src/controllers/users.controller.ts +46 -0
- package/templates/default/src/dtos/users.dto.ts +42 -0
- package/templates/default/src/entities/user.entity.ts +190 -0
- package/templates/default/src/exceptions/httpException.ts +14 -0
- package/{lib/knex → templates/default}/src/interfaces/auth.interface.ts +3 -3
- package/templates/default/src/interfaces/users.interface.ts +9 -0
- package/templates/default/src/middlewares/auth.middleware.ts +49 -0
- package/templates/default/src/middlewares/error.middleware.ts +89 -0
- package/templates/default/src/middlewares/notFound.middleware.ts +6 -0
- package/templates/default/src/middlewares/validation.middleware.ts +15 -0
- package/templates/default/src/repositories/users.repository.ts +55 -0
- package/templates/default/src/routes/auth.route.ts +31 -0
- package/templates/default/src/routes/users.route.ts +32 -0
- package/templates/default/src/server.ts +35 -0
- package/templates/default/src/services/auth.service.ts +67 -0
- package/templates/default/src/services/users.service.ts +48 -0
- package/templates/default/src/utils/asyncHandler.ts +8 -0
- package/templates/default/src/utils/logger.ts +113 -0
- package/{lib/typeorm → templates/default}/tsconfig.json +23 -22
- package/CONTRIBUTORS.md +0 -69
- package/bin/cli.js +0 -18
- package/lib/default/.dockerignore +0 -18
- package/lib/default/.editorconfig +0 -9
- package/lib/default/.env.development.local +0 -13
- package/lib/default/.env.production.local +0 -13
- package/lib/default/.env.test.local +0 -13
- package/lib/default/.eslintignore +0 -1
- package/lib/default/.eslintrc +0 -18
- package/lib/default/.huskyrc +0 -5
- package/lib/default/.lintstagedrc.json +0 -5
- package/lib/default/.prettierrc +0 -8
- package/lib/default/.swcrc +0 -39
- package/lib/default/.vscode/launch.json +0 -35
- package/lib/default/.vscode/settings.json +0 -6
- package/lib/default/Dockerfile.dev +0 -18
- package/lib/default/Dockerfile.prod +0 -18
- package/lib/default/docker-compose.yml +0 -35
- package/lib/default/ecosystem.config.js +0 -57
- package/lib/default/jest.config.js +0 -12
- package/lib/default/nginx.conf +0 -40
- package/lib/default/nodemon.json +0 -12
- package/lib/default/package.json +0 -76
- package/lib/default/src/app.ts +0 -81
- package/lib/default/src/config/index.ts +0 -5
- package/lib/default/src/controllers/auth.controller.ts +0 -44
- package/lib/default/src/controllers/users.controller.ts +0 -63
- package/lib/default/src/dtos/users.dto.ts +0 -20
- package/lib/default/src/exceptions/HttpException.ts +0 -10
- package/lib/default/src/http/auth.http +0 -27
- package/lib/default/src/http/users.http +0 -34
- package/lib/default/src/interfaces/auth.interface.ts +0 -15
- package/lib/default/src/interfaces/users.interface.ts +0 -5
- package/lib/default/src/middlewares/auth.middleware.ts +0 -38
- package/lib/default/src/middlewares/error.middleware.ts +0 -15
- package/lib/default/src/middlewares/validation.middleware.ts +0 -27
- package/lib/default/src/models/users.model.ts +0 -9
- package/lib/default/src/routes/auth.route.ts +0 -21
- package/lib/default/src/routes/users.route.ts +0 -23
- package/lib/default/src/server.ts +0 -10
- package/lib/default/src/services/auth.service.ts +0 -52
- package/lib/default/src/services/users.service.ts +0 -51
- package/lib/default/src/test/auth.test.ts +0 -52
- package/lib/default/src/test/users.test.ts +0 -62
- package/lib/default/src/utils/logger.ts +0 -65
- package/lib/default/src/utils/validateEnv.ts +0 -8
- package/lib/default/swagger.yaml +0 -123
- package/lib/default/tsconfig.json +0 -39
- package/lib/graphql/.dockerignore +0 -18
- package/lib/graphql/.editorconfig +0 -9
- package/lib/graphql/.env.development.local +0 -20
- package/lib/graphql/.env.production.local +0 -20
- package/lib/graphql/.env.test.local +0 -20
- package/lib/graphql/.eslintignore +0 -1
- package/lib/graphql/.eslintrc +0 -18
- package/lib/graphql/.huskyrc +0 -5
- package/lib/graphql/.lintstagedrc.json +0 -5
- package/lib/graphql/.prettierrc +0 -8
- package/lib/graphql/.swcrc +0 -40
- package/lib/graphql/.vscode/launch.json +0 -35
- package/lib/graphql/.vscode/settings.json +0 -6
- package/lib/graphql/Dockerfile.dev +0 -19
- package/lib/graphql/Dockerfile.prod +0 -19
- package/lib/graphql/Makefile +0 -46
- package/lib/graphql/docker-compose.yml +0 -58
- package/lib/graphql/ecosystem.config.js +0 -59
- package/lib/graphql/jest.config.js +0 -12
- package/lib/graphql/nginx.conf +0 -40
- package/lib/graphql/nodemon.json +0 -12
- package/lib/graphql/package.json +0 -75
- package/lib/graphql/src/app.ts +0 -107
- package/lib/graphql/src/config/index.ts +0 -6
- package/lib/graphql/src/database/index.ts +0 -26
- package/lib/graphql/src/dtos/users.dto.ts +0 -27
- package/lib/graphql/src/entities/users.entity.ts +0 -26
- package/lib/graphql/src/exceptions/HttpException.ts +0 -10
- package/lib/graphql/src/http/auth.http +0 -49
- package/lib/graphql/src/http/users.http +0 -78
- package/lib/graphql/src/interfaces/auth.interface.ts +0 -14
- package/lib/graphql/src/interfaces/users.interface.ts +0 -5
- package/lib/graphql/src/middlewares/auth.middleware.ts +0 -42
- package/lib/graphql/src/middlewares/error.middleware.ts +0 -15
- package/lib/graphql/src/repositories/auth.repository.ts +0 -53
- package/lib/graphql/src/repositories/users.repository.ts +0 -51
- package/lib/graphql/src/resolvers/auth.resolver.ts +0 -32
- package/lib/graphql/src/resolvers/users.resolver.ts +0 -47
- package/lib/graphql/src/server.ts +0 -10
- package/lib/graphql/src/test/auth.test.ts +0 -10
- package/lib/graphql/src/test/users.test.ts +0 -11
- package/lib/graphql/src/typedefs/users.type.ts +0 -13
- package/lib/graphql/src/utils/logger.ts +0 -77
- package/lib/graphql/src/utils/validateEnv.ts +0 -8
- package/lib/graphql/tsconfig.json +0 -40
- package/lib/knex/.dockerignore +0 -18
- package/lib/knex/.editorconfig +0 -9
- package/lib/knex/.env.development.local +0 -20
- package/lib/knex/.env.production.local +0 -20
- package/lib/knex/.env.test.local +0 -20
- package/lib/knex/.eslintignore +0 -1
- package/lib/knex/.eslintrc +0 -18
- package/lib/knex/.huskyrc +0 -5
- package/lib/knex/.lintstagedrc.json +0 -5
- package/lib/knex/.prettierrc +0 -8
- package/lib/knex/.swcrc +0 -40
- package/lib/knex/.vscode/launch.json +0 -35
- package/lib/knex/.vscode/settings.json +0 -6
- package/lib/knex/Dockerfile.dev +0 -19
- package/lib/knex/Dockerfile.prod +0 -19
- package/lib/knex/Makefile +0 -46
- package/lib/knex/docker-compose.yml +0 -55
- package/lib/knex/ecosystem.config.js +0 -57
- package/lib/knex/jest.config.js +0 -12
- package/lib/knex/knexfile.ts +0 -23
- package/lib/knex/nginx.conf +0 -40
- package/lib/knex/nodemon.json +0 -12
- package/lib/knex/package.json +0 -85
- package/lib/knex/src/app.ts +0 -87
- package/lib/knex/src/config/index.ts +0 -6
- package/lib/knex/src/controllers/auth.controller.ts +0 -44
- package/lib/knex/src/controllers/users.controller.ts +0 -63
- package/lib/knex/src/database/index.ts +0 -24
- package/lib/knex/src/database/migrations/.gitkeep +0 -0
- package/lib/knex/src/database/migrations/20210713110926_initial.ts +0 -17
- package/lib/knex/src/database/seeds/.gitkeep +0 -0
- package/lib/knex/src/dtos/users.dto.ts +0 -20
- package/lib/knex/src/exceptions/HttpException.ts +0 -10
- package/lib/knex/src/http/auth.http +0 -27
- package/lib/knex/src/http/users.http +0 -34
- package/lib/knex/src/interfaces/routes.interface.ts +0 -6
- package/lib/knex/src/interfaces/users.interface.ts +0 -5
- package/lib/knex/src/middlewares/auth.middleware.ts +0 -40
- package/lib/knex/src/middlewares/error.middleware.ts +0 -15
- package/lib/knex/src/middlewares/validation.middleware.ts +0 -27
- package/lib/knex/src/models/users.model.ts +0 -13
- package/lib/knex/src/routes/auth.route.ts +0 -22
- package/lib/knex/src/routes/users.route.ts +0 -23
- package/lib/knex/src/server.ts +0 -10
- package/lib/knex/src/services/auth.service.ts +0 -60
- package/lib/knex/src/services/users.service.ts +0 -55
- package/lib/knex/src/test/auth.test.ts +0 -51
- package/lib/knex/src/test/users.test.ts +0 -65
- package/lib/knex/src/utils/logger.ts +0 -65
- package/lib/knex/src/utils/validateEnv.ts +0 -8
- package/lib/knex/swagger.yaml +0 -123
- package/lib/knex/tsconfig.json +0 -40
- package/lib/mikro-orm/.dockerignore +0 -18
- package/lib/mikro-orm/.editorconfig +0 -9
- package/lib/mikro-orm/.env.development.local +0 -18
- package/lib/mikro-orm/.env.production.local +0 -18
- package/lib/mikro-orm/.env.test.local +0 -18
- package/lib/mikro-orm/.eslintignore +0 -1
- package/lib/mikro-orm/.eslintrc +0 -18
- package/lib/mikro-orm/.huskyrc +0 -5
- package/lib/mikro-orm/.lintstagedrc.json +0 -5
- package/lib/mikro-orm/.prettierrc +0 -8
- package/lib/mikro-orm/.swcrc +0 -41
- package/lib/mikro-orm/.vscode/launch.json +0 -35
- package/lib/mikro-orm/.vscode/settings.json +0 -6
- package/lib/mikro-orm/Dockerfile.dev +0 -19
- package/lib/mikro-orm/Dockerfile.prod +0 -19
- package/lib/mikro-orm/Makefile +0 -46
- package/lib/mikro-orm/docker-compose.yml +0 -55
- package/lib/mikro-orm/ecosystem.config.js +0 -57
- package/lib/mikro-orm/jest.config.js +0 -12
- package/lib/mikro-orm/nginx.conf +0 -40
- package/lib/mikro-orm/nodemon.json +0 -12
- package/lib/mikro-orm/package.json +0 -79
- package/lib/mikro-orm/src/app.ts +0 -97
- package/lib/mikro-orm/src/config/index.ts +0 -6
- package/lib/mikro-orm/src/controllers/auth.controller.ts +0 -44
- package/lib/mikro-orm/src/controllers/users.controller.ts +0 -63
- package/lib/mikro-orm/src/database/index.ts +0 -19
- package/lib/mikro-orm/src/dtos/users.dto.ts +0 -20
- package/lib/mikro-orm/src/entities/base.entity.ts +0 -16
- package/lib/mikro-orm/src/entities/users.entity.ts +0 -17
- package/lib/mikro-orm/src/exceptions/HttpException.ts +0 -10
- package/lib/mikro-orm/src/http/auth.http +0 -32
- package/lib/mikro-orm/src/http/users.http +0 -34
- package/lib/mikro-orm/src/interfaces/auth.interface.ts +0 -15
- package/lib/mikro-orm/src/interfaces/routes.interface.ts +0 -6
- package/lib/mikro-orm/src/interfaces/users.interface.ts +0 -5
- package/lib/mikro-orm/src/middlewares/auth.middleware.ts +0 -39
- package/lib/mikro-orm/src/middlewares/error.middleware.ts +0 -15
- package/lib/mikro-orm/src/middlewares/validation.middleware.ts +0 -27
- package/lib/mikro-orm/src/routes/auth.route.ts +0 -22
- package/lib/mikro-orm/src/routes/users.route.ts +0 -23
- package/lib/mikro-orm/src/server.ts +0 -10
- package/lib/mikro-orm/src/services/auth.service.ts +0 -53
- package/lib/mikro-orm/src/services/users.service.ts +0 -60
- package/lib/mikro-orm/src/test/auth.test.ts +0 -65
- package/lib/mikro-orm/src/test/users.test.ts +0 -69
- package/lib/mikro-orm/src/utils/logger.ts +0 -65
- package/lib/mikro-orm/src/utils/validateEnv.ts +0 -8
- package/lib/mikro-orm/swagger.yaml +0 -122
- package/lib/mikro-orm/tsconfig.json +0 -41
- package/lib/mongoose/.dockerignore +0 -18
- package/lib/mongoose/.editorconfig +0 -9
- package/lib/mongoose/.env.development.local +0 -18
- package/lib/mongoose/.env.production.local +0 -18
- package/lib/mongoose/.env.test.local +0 -18
- package/lib/mongoose/.eslintignore +0 -1
- package/lib/mongoose/.eslintrc +0 -18
- package/lib/mongoose/.huskyrc +0 -5
- package/lib/mongoose/.lintstagedrc.json +0 -5
- package/lib/mongoose/.prettierrc +0 -8
- package/lib/mongoose/.swcrc +0 -40
- package/lib/mongoose/.vscode/launch.json +0 -35
- package/lib/mongoose/.vscode/settings.json +0 -6
- package/lib/mongoose/Dockerfile.dev +0 -19
- package/lib/mongoose/Dockerfile.prod +0 -19
- package/lib/mongoose/Makefile +0 -46
- package/lib/mongoose/docker-compose.yml +0 -55
- package/lib/mongoose/ecosystem.config.js +0 -57
- package/lib/mongoose/jest.config.js +0 -12
- package/lib/mongoose/nginx.conf +0 -40
- package/lib/mongoose/nodemon.json +0 -12
- package/lib/mongoose/package.json +0 -78
- package/lib/mongoose/src/app.ts +0 -87
- package/lib/mongoose/src/config/index.ts +0 -6
- package/lib/mongoose/src/controllers/auth.controller.ts +0 -44
- package/lib/mongoose/src/controllers/users.controller.ts +0 -63
- package/lib/mongoose/src/database/index.ts +0 -18
- package/lib/mongoose/src/dtos/users.dto.ts +0 -20
- package/lib/mongoose/src/exceptions/HttpException.ts +0 -10
- package/lib/mongoose/src/http/auth.http +0 -27
- package/lib/mongoose/src/http/users.http +0 -34
- package/lib/mongoose/src/interfaces/auth.interface.ts +0 -15
- package/lib/mongoose/src/interfaces/routes.interface.ts +0 -6
- package/lib/mongoose/src/interfaces/users.interface.ts +0 -5
- package/lib/mongoose/src/middlewares/auth.middleware.ts +0 -39
- package/lib/mongoose/src/middlewares/error.middleware.ts +0 -15
- package/lib/mongoose/src/middlewares/validation.middleware.ts +0 -27
- package/lib/mongoose/src/models/users.model.ts +0 -16
- package/lib/mongoose/src/routes/auth.route.ts +0 -22
- package/lib/mongoose/src/routes/users.route.ts +0 -23
- package/lib/mongoose/src/server.ts +0 -10
- package/lib/mongoose/src/services/auth.service.ts +0 -52
- package/lib/mongoose/src/services/users.service.ts +0 -54
- package/lib/mongoose/src/test/auth.test.ts +0 -83
- package/lib/mongoose/src/test/index.test.ts +0 -18
- package/lib/mongoose/src/test/users.test.ts +0 -133
- package/lib/mongoose/src/utils/logger.ts +0 -65
- package/lib/mongoose/src/utils/validateEnv.ts +0 -8
- package/lib/mongoose/swagger.yaml +0 -120
- package/lib/mongoose/tsconfig.json +0 -40
- package/lib/node-postgres/.dockerignore +0 -18
- package/lib/node-postgres/.editorconfig +0 -9
- package/lib/node-postgres/.env.development.local +0 -20
- package/lib/node-postgres/.env.production.local +0 -20
- package/lib/node-postgres/.env.test.local +0 -20
- package/lib/node-postgres/.eslintignore +0 -1
- package/lib/node-postgres/.eslintrc +0 -18
- package/lib/node-postgres/.huskyrc +0 -5
- package/lib/node-postgres/.lintstagedrc.json +0 -5
- package/lib/node-postgres/.prettierrc +0 -8
- package/lib/node-postgres/.swcrc +0 -38
- package/lib/node-postgres/.vscode/launch.json +0 -35
- package/lib/node-postgres/.vscode/settings.json +0 -6
- package/lib/node-postgres/Dockerfile.dev +0 -17
- package/lib/node-postgres/Dockerfile.prod +0 -17
- package/lib/node-postgres/Makefile +0 -46
- package/lib/node-postgres/docker-compose.yml +0 -61
- package/lib/node-postgres/ecosystem.config.js +0 -57
- package/lib/node-postgres/jest.config.js +0 -12
- package/lib/node-postgres/nginx.conf +0 -40
- package/lib/node-postgres/nodemon.json +0 -12
- package/lib/node-postgres/package.json +0 -78
- package/lib/node-postgres/src/app.ts +0 -81
- package/lib/node-postgres/src/config/index.ts +0 -6
- package/lib/node-postgres/src/controllers/auth.controller.ts +0 -44
- package/lib/node-postgres/src/controllers/users.controller.ts +0 -63
- package/lib/node-postgres/src/database/index.ts +0 -10
- package/lib/node-postgres/src/database/init.sql +0 -13
- package/lib/node-postgres/src/dtos/users.dto.ts +0 -20
- package/lib/node-postgres/src/exceptions/httpException.ts +0 -10
- package/lib/node-postgres/src/http/auth.http +0 -27
- package/lib/node-postgres/src/http/users.http +0 -34
- package/lib/node-postgres/src/interfaces/auth.interface.ts +0 -15
- package/lib/node-postgres/src/interfaces/routes.interface.ts +0 -6
- package/lib/node-postgres/src/interfaces/users.interface.ts +0 -5
- package/lib/node-postgres/src/middlewares/auth.middleware.ts +0 -46
- package/lib/node-postgres/src/middlewares/error.middleware.ts +0 -15
- package/lib/node-postgres/src/middlewares/validation.middleware.ts +0 -27
- package/lib/node-postgres/src/routes/auth.route.ts +0 -21
- package/lib/node-postgres/src/routes/users.route.ts +0 -23
- package/lib/node-postgres/src/server.ts +0 -10
- package/lib/node-postgres/src/services/auth.service.ts +0 -103
- package/lib/node-postgres/src/services/users.service.ts +0 -133
- package/lib/node-postgres/src/test/auth.test.ts +0 -57
- package/lib/node-postgres/src/test/users.test.ts +0 -72
- package/lib/node-postgres/src/utils/logger.ts +0 -65
- package/lib/node-postgres/src/utils/validateEnv.ts +0 -8
- package/lib/node-postgres/swagger.yaml +0 -123
- package/lib/node-postgres/tsconfig.json +0 -39
- package/lib/prisma/.dockerignore +0 -18
- package/lib/prisma/.editorconfig +0 -9
- package/lib/prisma/.env.development.local +0 -16
- package/lib/prisma/.env.production.local +0 -16
- package/lib/prisma/.env.test.local +0 -16
- package/lib/prisma/.eslintignore +0 -1
- package/lib/prisma/.eslintrc +0 -18
- package/lib/prisma/.huskyrc +0 -5
- package/lib/prisma/.lintstagedrc.json +0 -5
- package/lib/prisma/.prettierrc +0 -8
- package/lib/prisma/.vscode/launch.json +0 -35
- package/lib/prisma/.vscode/settings.json +0 -6
- package/lib/prisma/Dockerfile.dev +0 -19
- package/lib/prisma/Dockerfile.prod +0 -19
- package/lib/prisma/Makefile +0 -46
- package/lib/prisma/docker-compose.yml +0 -51
- package/lib/prisma/ecosystem.config.js +0 -57
- package/lib/prisma/jest.config.js +0 -12
- package/lib/prisma/nginx.conf +0 -40
- package/lib/prisma/nodemon.json +0 -12
- package/lib/prisma/package.json +0 -84
- package/lib/prisma/src/app.ts +0 -81
- package/lib/prisma/src/config/index.ts +0 -5
- package/lib/prisma/src/controllers/auth.controller.ts +0 -44
- package/lib/prisma/src/controllers/users.controller.ts +0 -63
- package/lib/prisma/src/dtos/users.dto.ts +0 -20
- package/lib/prisma/src/exceptions/HttpException.ts +0 -10
- package/lib/prisma/src/http/auth.http +0 -27
- package/lib/prisma/src/http/users.http +0 -34
- package/lib/prisma/src/interfaces/auth.interface.ts +0 -15
- package/lib/prisma/src/interfaces/routes.interface.ts +0 -6
- package/lib/prisma/src/interfaces/users.interface.ts +0 -5
- package/lib/prisma/src/middlewares/auth.middleware.ts +0 -39
- package/lib/prisma/src/middlewares/error.middleware.ts +0 -15
- package/lib/prisma/src/middlewares/validation.middleware.ts +0 -27
- package/lib/prisma/src/prisma/migrations/20210314081925_initial/migration.sql +0 -9
- package/lib/prisma/src/prisma/migrations/migration_lock.toml +0 -3
- package/lib/prisma/src/prisma/schema.prisma +0 -17
- package/lib/prisma/src/routes/auth.route.ts +0 -22
- package/lib/prisma/src/routes/users.route.ts +0 -23
- package/lib/prisma/src/server.ts +0 -10
- package/lib/prisma/src/services/auth.service.ts +0 -56
- package/lib/prisma/src/services/users.service.ts +0 -49
- package/lib/prisma/src/test/auth.test.ts +0 -81
- package/lib/prisma/src/test/index.test.ts +0 -18
- package/lib/prisma/src/test/users.test.ts +0 -134
- package/lib/prisma/src/utils/logger.ts +0 -65
- package/lib/prisma/src/utils/validateEnv.ts +0 -8
- package/lib/prisma/swagger.yaml +0 -123
- package/lib/prisma/tsconfig.json +0 -38
- package/lib/routing-controllers/.dockerignore +0 -18
- package/lib/routing-controllers/.editorconfig +0 -9
- package/lib/routing-controllers/.env.development.local +0 -13
- package/lib/routing-controllers/.env.production.local +0 -13
- package/lib/routing-controllers/.env.test.local +0 -13
- package/lib/routing-controllers/.eslintignore +0 -1
- package/lib/routing-controllers/.eslintrc +0 -18
- package/lib/routing-controllers/.huskyrc +0 -5
- package/lib/routing-controllers/.lintstagedrc.json +0 -5
- package/lib/routing-controllers/.prettierrc +0 -8
- package/lib/routing-controllers/.swcrc +0 -38
- package/lib/routing-controllers/.vscode/launch.json +0 -35
- package/lib/routing-controllers/.vscode/settings.json +0 -6
- package/lib/routing-controllers/Dockerfile.dev +0 -19
- package/lib/routing-controllers/Dockerfile.prod +0 -19
- package/lib/routing-controllers/Makefile +0 -42
- package/lib/routing-controllers/docker-compose.yml +0 -35
- package/lib/routing-controllers/ecosystem.config.js +0 -57
- package/lib/routing-controllers/jest.config.js +0 -12
- package/lib/routing-controllers/nginx.conf +0 -40
- package/lib/routing-controllers/nodemon.json +0 -12
- package/lib/routing-controllers/package.json +0 -77
- package/lib/routing-controllers/src/app.ts +0 -101
- package/lib/routing-controllers/src/config/index.ts +0 -5
- package/lib/routing-controllers/src/controllers/auth.controller.ts +0 -41
- package/lib/routing-controllers/src/controllers/users.controller.ts +0 -51
- package/lib/routing-controllers/src/dtos/users.dto.ts +0 -20
- package/lib/routing-controllers/src/exceptions/HttpException.ts +0 -12
- package/lib/routing-controllers/src/http/auth.http +0 -27
- package/lib/routing-controllers/src/http/users.http +0 -34
- package/lib/routing-controllers/src/interfaces/auth.interface.ts +0 -15
- package/lib/routing-controllers/src/interfaces/users.interface.ts +0 -5
- package/lib/routing-controllers/src/middlewares/auth.middleware.ts +0 -38
- package/lib/routing-controllers/src/middlewares/error.middleware.ts +0 -15
- package/lib/routing-controllers/src/middlewares/validation.middleware.ts +0 -27
- package/lib/routing-controllers/src/models/users.model.ts +0 -9
- package/lib/routing-controllers/src/server.ts +0 -9
- package/lib/routing-controllers/src/services/auth.service.ts +0 -53
- package/lib/routing-controllers/src/services/users.service.ts +0 -52
- package/lib/routing-controllers/src/test/auth.test.ts +0 -49
- package/lib/routing-controllers/src/test/users.test.ts +0 -65
- package/lib/routing-controllers/src/utils/logger.ts +0 -65
- package/lib/routing-controllers/src/utils/validateEnv.ts +0 -8
- package/lib/routing-controllers/tsconfig.json +0 -38
- package/lib/sequelize/.dockerignore +0 -18
- package/lib/sequelize/.editorconfig +0 -9
- package/lib/sequelize/.env.development.local +0 -20
- package/lib/sequelize/.env.production.local +0 -20
- package/lib/sequelize/.env.test.local +0 -20
- package/lib/sequelize/.eslintignore +0 -1
- package/lib/sequelize/.eslintrc +0 -18
- package/lib/sequelize/.huskyrc +0 -5
- package/lib/sequelize/.lintstagedrc.json +0 -5
- package/lib/sequelize/.prettierrc +0 -8
- package/lib/sequelize/.sequelizerc +0 -8
- package/lib/sequelize/.swcrc +0 -40
- package/lib/sequelize/.vscode/launch.json +0 -35
- package/lib/sequelize/.vscode/settings.json +0 -6
- package/lib/sequelize/Dockerfile.dev +0 -23
- package/lib/sequelize/Dockerfile.prod +0 -23
- package/lib/sequelize/Makefile +0 -46
- package/lib/sequelize/docker-compose.yml +0 -55
- package/lib/sequelize/docker-entrypoint.sh +0 -5
- package/lib/sequelize/ecosystem.config.js +0 -57
- package/lib/sequelize/jest.config.js +0 -12
- package/lib/sequelize/nginx.conf +0 -40
- package/lib/sequelize/nodemon.json +0 -12
- package/lib/sequelize/package.json +0 -82
- package/lib/sequelize/src/app.ts +0 -87
- package/lib/sequelize/src/config/index.ts +0 -6
- package/lib/sequelize/src/config/sequelize-cli.js +0 -15
- package/lib/sequelize/src/controllers/auth.controller.ts +0 -45
- package/lib/sequelize/src/controllers/users.controller.ts +0 -64
- package/lib/sequelize/src/database/index.ts +0 -34
- package/lib/sequelize/src/database/migrations/.gitkeep +0 -0
- package/lib/sequelize/src/database/seeders/.gitkeep +0 -0
- package/lib/sequelize/src/dtos/users.dto.ts +0 -20
- package/lib/sequelize/src/exceptions/HttpException.ts +0 -10
- package/lib/sequelize/src/http/auth.http +0 -27
- package/lib/sequelize/src/http/users.http +0 -34
- package/lib/sequelize/src/interfaces/auth.interface.ts +0 -15
- package/lib/sequelize/src/interfaces/routes.interface.ts +0 -6
- package/lib/sequelize/src/interfaces/users.interface.ts +0 -5
- package/lib/sequelize/src/middlewares/auth.middleware.ts +0 -38
- package/lib/sequelize/src/middlewares/error.middleware.ts +0 -15
- package/lib/sequelize/src/middlewares/validation.middleware.ts +0 -27
- package/lib/sequelize/src/models/users.model.ts +0 -39
- package/lib/sequelize/src/routes/auth.route.ts +0 -21
- package/lib/sequelize/src/routes/users.route.ts +0 -23
- package/lib/sequelize/src/server.ts +0 -10
- package/lib/sequelize/src/services/auth.service.ts +0 -52
- package/lib/sequelize/src/services/users.service.ts +0 -50
- package/lib/sequelize/src/test/auth.test.ts +0 -71
- package/lib/sequelize/src/test/users.test.ts +0 -131
- package/lib/sequelize/src/utils/logger.ts +0 -65
- package/lib/sequelize/src/utils/validateEnv.ts +0 -8
- package/lib/sequelize/swagger.yaml +0 -123
- package/lib/sequelize/tsconfig.json +0 -40
- package/lib/starter.js +0 -262
- package/lib/typegoose/.dockerignore +0 -18
- package/lib/typegoose/.editorconfig +0 -9
- package/lib/typegoose/.env.development.local +0 -18
- package/lib/typegoose/.env.production.local +0 -18
- package/lib/typegoose/.env.test.local +0 -18
- package/lib/typegoose/.eslintignore +0 -1
- package/lib/typegoose/.eslintrc +0 -18
- package/lib/typegoose/.huskyrc +0 -5
- package/lib/typegoose/.lintstagedrc.json +0 -5
- package/lib/typegoose/.prettierrc +0 -8
- package/lib/typegoose/.swcrc +0 -40
- package/lib/typegoose/.vscode/launch.json +0 -35
- package/lib/typegoose/.vscode/settings.json +0 -6
- package/lib/typegoose/Dockerfile.dev +0 -19
- package/lib/typegoose/Dockerfile.prod +0 -19
- package/lib/typegoose/Makefile +0 -46
- package/lib/typegoose/docker-compose.yml +0 -55
- package/lib/typegoose/ecosystem.config.js +0 -57
- package/lib/typegoose/jest.config.js +0 -12
- package/lib/typegoose/nginx.conf +0 -40
- package/lib/typegoose/nodemon.json +0 -12
- package/lib/typegoose/package.json +0 -79
- package/lib/typegoose/src/app.ts +0 -90
- package/lib/typegoose/src/config/index.ts +0 -6
- package/lib/typegoose/src/controllers/auth.controller.ts +0 -44
- package/lib/typegoose/src/controllers/users.controller.ts +0 -63
- package/lib/typegoose/src/database/index.ts +0 -18
- package/lib/typegoose/src/dtos/users.dto.ts +0 -20
- package/lib/typegoose/src/exceptions/HttpException.ts +0 -10
- package/lib/typegoose/src/http/auth.http +0 -27
- package/lib/typegoose/src/http/users.http +0 -34
- package/lib/typegoose/src/interfaces/auth.interface.ts +0 -15
- package/lib/typegoose/src/interfaces/routes.interface.ts +0 -6
- package/lib/typegoose/src/interfaces/users.interface.ts +0 -5
- package/lib/typegoose/src/middlewares/auth.middleware.ts +0 -38
- package/lib/typegoose/src/middlewares/error.middleware.ts +0 -15
- package/lib/typegoose/src/middlewares/validation.middleware.ts +0 -27
- package/lib/typegoose/src/models/users.model.ts +0 -16
- package/lib/typegoose/src/routes/auth.route.ts +0 -21
- package/lib/typegoose/src/routes/users.route.ts +0 -23
- package/lib/typegoose/src/server.ts +0 -10
- package/lib/typegoose/src/services/auth.service.ts +0 -52
- package/lib/typegoose/src/services/users.service.ts +0 -55
- package/lib/typegoose/src/test/auth.test.ts +0 -83
- package/lib/typegoose/src/test/users.test.ts +0 -133
- package/lib/typegoose/src/utils/logger.ts +0 -65
- package/lib/typegoose/src/utils/validateEnv.ts +0 -8
- package/lib/typegoose/swagger.yaml +0 -120
- package/lib/typegoose/tsconfig.json +0 -40
- package/lib/typeorm/.dockerignore +0 -18
- package/lib/typeorm/.editorconfig +0 -9
- package/lib/typeorm/.env.development.local +0 -20
- package/lib/typeorm/.env.production.local +0 -20
- package/lib/typeorm/.env.test.local +0 -20
- package/lib/typeorm/.eslintignore +0 -1
- package/lib/typeorm/.eslintrc +0 -18
- package/lib/typeorm/.huskyrc +0 -5
- package/lib/typeorm/.lintstagedrc.json +0 -5
- package/lib/typeorm/.prettierrc +0 -8
- package/lib/typeorm/.swcrc +0 -40
- package/lib/typeorm/.vscode/launch.json +0 -35
- package/lib/typeorm/.vscode/settings.json +0 -6
- package/lib/typeorm/Dockerfile.dev +0 -19
- package/lib/typeorm/Dockerfile.prod +0 -19
- package/lib/typeorm/Makefile +0 -46
- package/lib/typeorm/docker-compose.yml +0 -57
- package/lib/typeorm/ecosystem.config.js +0 -57
- package/lib/typeorm/jest.config.js +0 -12
- package/lib/typeorm/nginx.conf +0 -40
- package/lib/typeorm/nodemon.json +0 -12
- package/lib/typeorm/package.json +0 -78
- package/lib/typeorm/src/app.ts +0 -87
- package/lib/typeorm/src/config/index.ts +0 -6
- package/lib/typeorm/src/controllers/auth.controller.ts +0 -44
- package/lib/typeorm/src/controllers/users.controller.ts +0 -63
- package/lib/typeorm/src/database/index.ts +0 -26
- package/lib/typeorm/src/database/migrations/.gitkeep +0 -0
- package/lib/typeorm/src/dtos/users.dto.ts +0 -20
- package/lib/typeorm/src/entities/users.entity.ts +0 -26
- package/lib/typeorm/src/exceptions/HttpException.ts +0 -10
- package/lib/typeorm/src/http/auth.http +0 -27
- package/lib/typeorm/src/http/users.http +0 -34
- package/lib/typeorm/src/interfaces/auth.interface.ts +0 -15
- package/lib/typeorm/src/interfaces/routes.interface.ts +0 -6
- package/lib/typeorm/src/interfaces/users.interface.ts +0 -5
- package/lib/typeorm/src/middlewares/auth.middleware.ts +0 -38
- package/lib/typeorm/src/middlewares/error.middleware.ts +0 -15
- package/lib/typeorm/src/middlewares/validation.middleware.ts +0 -27
- package/lib/typeorm/src/routes/auth.route.ts +0 -21
- package/lib/typeorm/src/routes/users.route.ts +0 -23
- package/lib/typeorm/src/server.ts +0 -10
- package/lib/typeorm/src/services/auth.service.ts +0 -54
- package/lib/typeorm/src/services/users.service.ts +0 -51
- package/lib/typeorm/src/test/auth.test.ts +0 -75
- package/lib/typeorm/src/test/users.test.ts +0 -136
- package/lib/typeorm/src/utils/logger.ts +0 -65
- package/lib/typeorm/src/utils/validateEnv.ts +0 -8
- package/lib/typeorm/swagger.yaml +0 -123
- /package/{lib → templates}/default/src/interfaces/routes.interface.ts +0 -0
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { defineConfig } from 'vitest/config';
|
|
2
|
+
import tsconfigPaths from 'vite-tsconfig-paths';
|
|
3
|
+
|
|
4
|
+
export default defineConfig({
|
|
5
|
+
plugins: [tsconfigPaths()],
|
|
6
|
+
test: {
|
|
7
|
+
environment: 'node',
|
|
8
|
+
globals: true, // 전역 expect/describe/it 사용 시 편의. 원치 않으면 제거
|
|
9
|
+
setupFiles: ['src/test/setup.ts'],
|
|
10
|
+
include: ['src/test/**/*.{test,spec}.ts'], // src/test/e2e, src/test/unit에 최적화
|
|
11
|
+
exclude: ['node_modules', 'dist', 'coverage', 'logs'],
|
|
12
|
+
coverage: {
|
|
13
|
+
provider: 'v8', // v8 사용 시
|
|
14
|
+
reporter: ['text', 'html', 'lcov'],
|
|
15
|
+
reportsDirectory: 'coverage',
|
|
16
|
+
include: ['src/**/*.{ts,tsx}'],
|
|
17
|
+
exclude: ['src/**/*.d.ts', 'src/**/index.ts', 'src/test/**'],
|
|
18
|
+
},
|
|
19
|
+
// e2e에서 포트/자원 충돌나면 단일 스레드:
|
|
20
|
+
// poolOptions: { threads: { singleThread: true } },
|
|
21
|
+
},
|
|
22
|
+
});
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "typescript-express-starter",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "11.0.0",
|
|
4
4
|
"description": "Quick and Easy TypeScript Express Starter",
|
|
5
5
|
"author": "AGUMON <ljlm0402@gmail.com>",
|
|
6
6
|
"license": "MIT",
|
|
@@ -29,27 +29,40 @@
|
|
|
29
29
|
"nginx",
|
|
30
30
|
"swc"
|
|
31
31
|
],
|
|
32
|
-
"
|
|
32
|
+
"type": "module",
|
|
33
|
+
"main": "bin/starter.js",
|
|
33
34
|
"bin": {
|
|
34
|
-
"typescript-express-starter": "bin/
|
|
35
|
+
"typescript-express-starter": "bin/starter.js"
|
|
35
36
|
},
|
|
36
37
|
"scripts": {
|
|
37
|
-
"start": "node bin/
|
|
38
|
+
"start": "node bin/starter.js"
|
|
38
39
|
},
|
|
39
40
|
"dependencies": {
|
|
40
|
-
"
|
|
41
|
-
"
|
|
42
|
-
"
|
|
43
|
-
"
|
|
41
|
+
"@clack/prompts": "^0.11.0",
|
|
42
|
+
"chalk": "^5.6.2",
|
|
43
|
+
"cli-progress": "^3.12.0",
|
|
44
|
+
"edit-json-file": "^1.8.1",
|
|
45
|
+
"execa": "^9.6.1",
|
|
46
|
+
"fs-extra": "^11.3.3",
|
|
47
|
+
"gitignore": "^0.7.0",
|
|
48
|
+
"inquirer": "^12.11.1",
|
|
44
49
|
"ncp": "^2.0.0",
|
|
45
|
-
"ora": "^
|
|
50
|
+
"ora": "^8.2.0",
|
|
51
|
+
"recast": "^0.23.11"
|
|
52
|
+
},
|
|
53
|
+
"devDependencies": {
|
|
54
|
+
"@babel/parser": "^7.28.5",
|
|
55
|
+
"@types/node": "^24.10.6",
|
|
56
|
+
"eslint": "^9.39.2",
|
|
57
|
+
"prettier": "^3.7.4",
|
|
58
|
+
"ts-morph": "^26.0.0"
|
|
46
59
|
},
|
|
47
60
|
"publishConfig": {
|
|
48
61
|
"access": "public"
|
|
49
62
|
},
|
|
50
63
|
"engines": {
|
|
51
|
-
"node": ">=
|
|
52
|
-
"npm": ">=
|
|
64
|
+
"node": ">= 16.13.0",
|
|
65
|
+
"npm": ">= 9.11.0"
|
|
53
66
|
},
|
|
54
67
|
"repository": {
|
|
55
68
|
"type": "git",
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "default",
|
|
3
|
+
"version": "1.0.0",
|
|
4
|
+
"description": "default template",
|
|
5
|
+
"scripts": {
|
|
6
|
+
"start": "cross-env NODE_ENV=production node dist/server.js",
|
|
7
|
+
"dev": "cross-env NODE_ENV=development nodemon",
|
|
8
|
+
"dev:watch": "tsx watch src/server.ts",
|
|
9
|
+
"build": "tsc && tsc-alias"
|
|
10
|
+
},
|
|
11
|
+
"dependencies": {
|
|
12
|
+
"bcryptjs": "^3.0.2",
|
|
13
|
+
"compression": "^1.8.1",
|
|
14
|
+
"cookie-parser": "^1.4.7",
|
|
15
|
+
"cors": "^2.8.5",
|
|
16
|
+
"crypto": "^1.0.1",
|
|
17
|
+
"dotenv": "^17.2.1",
|
|
18
|
+
"express": "^5.1.0",
|
|
19
|
+
"express-rate-limit": "^8.0.1",
|
|
20
|
+
"helmet": "^8.1.0",
|
|
21
|
+
"hpp": "^0.2.3",
|
|
22
|
+
"jsonwebtoken": "^9.0.2",
|
|
23
|
+
"morgan": "^1.10.1",
|
|
24
|
+
"pino": "^9.9.0",
|
|
25
|
+
"pino-pretty": "^13.1.1",
|
|
26
|
+
"pino-roll": "^3.1.0",
|
|
27
|
+
"reflect-metadata": "^0.2.2",
|
|
28
|
+
"tslib": "^2.8.1",
|
|
29
|
+
"tsyringe": "^4.10.0",
|
|
30
|
+
"zod": "^4.1.3"
|
|
31
|
+
},
|
|
32
|
+
"devDependencies": {
|
|
33
|
+
"@types/compression": "^1.8.1",
|
|
34
|
+
"@types/cookie-parser": "^1.4.9",
|
|
35
|
+
"@types/cors": "^2.8.19",
|
|
36
|
+
"@types/express": "^5.0.3",
|
|
37
|
+
"@types/hpp": "^0.2.6",
|
|
38
|
+
"@types/jsonwebtoken": "^9.0.10",
|
|
39
|
+
"@types/morgan": "^1.9.10",
|
|
40
|
+
"@types/node": "^24.3.0",
|
|
41
|
+
"cross-env": "^10.0.0",
|
|
42
|
+
"node-gyp": "^11.4.2",
|
|
43
|
+
"nodemon": "^3.1.10",
|
|
44
|
+
"tsc-alias": "^1.8.16",
|
|
45
|
+
"tsx": "^4.20.5",
|
|
46
|
+
"typescript": "^5.9.2"
|
|
47
|
+
}
|
|
48
|
+
}
|
|
@@ -0,0 +1,118 @@
|
|
|
1
|
+
import compression from 'compression';
|
|
2
|
+
import cookieParser from 'cookie-parser';
|
|
3
|
+
import cors from 'cors';
|
|
4
|
+
import express from 'express';
|
|
5
|
+
import rateLimit from 'express-rate-limit';
|
|
6
|
+
import helmet from 'helmet';
|
|
7
|
+
import hpp from 'hpp';
|
|
8
|
+
import morgan from 'morgan';
|
|
9
|
+
import { NODE_ENV, PORT, LOG_FORMAT, CREDENTIALS, CORS_ORIGIN_LIST } from '@config/env';
|
|
10
|
+
import { Routes } from '@interfaces/routes.interface';
|
|
11
|
+
import { ErrorMiddleware } from '@middlewares/error.middleware';
|
|
12
|
+
import { NotFoundMiddleware } from '@middlewares/notFound.middleware';
|
|
13
|
+
import { logger, stream } from '@utils/logger';
|
|
14
|
+
|
|
15
|
+
class App {
|
|
16
|
+
public app: express.Application;
|
|
17
|
+
public env: string;
|
|
18
|
+
public port: string | number;
|
|
19
|
+
|
|
20
|
+
constructor(routes: Routes[], apiPrefix = '/api/v1') {
|
|
21
|
+
this.app = express();
|
|
22
|
+
this.env = NODE_ENV || 'development';
|
|
23
|
+
this.port = PORT || 3000;
|
|
24
|
+
|
|
25
|
+
this.initializeTrustProxy();
|
|
26
|
+
this.initializeMiddlewares();
|
|
27
|
+
this.initializeRoutes(routes, apiPrefix);
|
|
28
|
+
this.initializeErrorHandling();
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
public listen() {
|
|
32
|
+
const server = this.app.listen(this.port, () => {
|
|
33
|
+
logger.info(`=================================`);
|
|
34
|
+
logger.info(`======= ENV: ${this.env} =======`);
|
|
35
|
+
logger.info(`🚀 App listening on the port ${this.port}`);
|
|
36
|
+
logger.info(`=================================`);
|
|
37
|
+
});
|
|
38
|
+
|
|
39
|
+
return server;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
public getServer() {
|
|
43
|
+
return this.app;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
private initializeTrustProxy() {
|
|
47
|
+
// Nginx, Heroku, Cloudflare 등 프록시 환경에서 실IP 추출을 위해 필요
|
|
48
|
+
this.app.set('trust proxy', 1);
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
private initializeMiddlewares() {
|
|
52
|
+
this.app.use(
|
|
53
|
+
rateLimit({
|
|
54
|
+
windowMs: 60_000,
|
|
55
|
+
limit: this.env === 'production' ? 100 : 1000,
|
|
56
|
+
standardHeaders: true,
|
|
57
|
+
legacyHeaders: false,
|
|
58
|
+
skip: (req) =>
|
|
59
|
+
this.env !== 'production' ||
|
|
60
|
+
['127.0.0.1', '::1', '::ffff:127.0.0.1'].includes(req.ip ?? ''),
|
|
61
|
+
}),
|
|
62
|
+
);
|
|
63
|
+
|
|
64
|
+
this.app.use(morgan(LOG_FORMAT || 'dev', { stream }));
|
|
65
|
+
|
|
66
|
+
// CORS 화이트리스트를 환경변수에서 관리
|
|
67
|
+
const allowedOrigins =
|
|
68
|
+
CORS_ORIGIN_LIST.length > 0 ? CORS_ORIGIN_LIST : ['http://localhost:3000'];
|
|
69
|
+
|
|
70
|
+
this.app.use(
|
|
71
|
+
cors({
|
|
72
|
+
origin: (origin, callback) => {
|
|
73
|
+
if (!origin || allowedOrigins.includes(origin)) {
|
|
74
|
+
callback(null, true);
|
|
75
|
+
} else {
|
|
76
|
+
callback(new Error('Not allowed by CORS'));
|
|
77
|
+
}
|
|
78
|
+
},
|
|
79
|
+
credentials: CREDENTIALS,
|
|
80
|
+
}),
|
|
81
|
+
);
|
|
82
|
+
|
|
83
|
+
this.app.use(hpp());
|
|
84
|
+
this.app.use(
|
|
85
|
+
helmet({
|
|
86
|
+
contentSecurityPolicy:
|
|
87
|
+
this.env === 'production'
|
|
88
|
+
? {
|
|
89
|
+
directives: {
|
|
90
|
+
defaultSrc: ["'self'"],
|
|
91
|
+
scriptSrc: ["'self'", "'unsafe-inline'"],
|
|
92
|
+
objectSrc: ["'none'"],
|
|
93
|
+
upgradeInsecureRequests: [],
|
|
94
|
+
},
|
|
95
|
+
}
|
|
96
|
+
: false, // 개발 환경에서는 CSP 비활성화 (hot reload 등 편의)
|
|
97
|
+
referrerPolicy: { policy: 'no-referrer' },
|
|
98
|
+
}),
|
|
99
|
+
);
|
|
100
|
+
this.app.use(compression());
|
|
101
|
+
this.app.use(express.json({ limit: '10mb' }));
|
|
102
|
+
this.app.use(express.urlencoded({ extended: true, limit: '10mb' }));
|
|
103
|
+
this.app.use(cookieParser());
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
private initializeRoutes(routes: Routes[], apiPrefix: string) {
|
|
107
|
+
routes.forEach((route) => {
|
|
108
|
+
this.app.use(apiPrefix, route.router);
|
|
109
|
+
});
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
private initializeErrorHandling() {
|
|
113
|
+
this.app.use(NotFoundMiddleware);
|
|
114
|
+
this.app.use(ErrorMiddleware);
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
export default App;
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
import { config } from 'dotenv';
|
|
2
|
+
import { existsSync } from 'fs';
|
|
3
|
+
import { resolve } from 'path';
|
|
4
|
+
import { z } from 'zod';
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* 1) dotenv 로드 순서
|
|
8
|
+
* - .env (공통)
|
|
9
|
+
* - .env.{NODE_ENV}.local (환경별 override, 있으면 덮어씀)
|
|
10
|
+
*/
|
|
11
|
+
config(); // .env
|
|
12
|
+
const nodeEnv = process.env.NODE_ENV || 'development';
|
|
13
|
+
const layerPath = resolve(process.cwd(), `.env.${nodeEnv}.local`);
|
|
14
|
+
if (existsSync(layerPath)) {
|
|
15
|
+
config({ path: layerPath });
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
* 2) Zod 스키마 정의
|
|
20
|
+
* - 필수/선택/기본값 정책은 필요에 맞게 수정 가능
|
|
21
|
+
*/
|
|
22
|
+
const EnvSchema = z
|
|
23
|
+
.object({
|
|
24
|
+
NODE_ENV: z.enum(['development', 'production', 'test']).default('development'),
|
|
25
|
+
PORT: z.coerce.number().int().positive().optional(), // 기본값은 app.ts에서 3000 처리
|
|
26
|
+
|
|
27
|
+
SECRET_KEY: z.string().min(1),
|
|
28
|
+
|
|
29
|
+
LOG_FORMAT: z.string().min(1).optional(), // 기본값은 app.ts에서 'dev'
|
|
30
|
+
LOG_DIR: z.string().min(1),
|
|
31
|
+
LOG_LEVEL: z.string().min(1),
|
|
32
|
+
|
|
33
|
+
ORIGIN: z.string().min(1), // 필요시 배열화 가능
|
|
34
|
+
CREDENTIALS: z.coerce.boolean(), // 'true'/'false' 문자열 → boolean
|
|
35
|
+
CORS_ORIGINS: z.string().optional(), // "http://a.com,http://b.com"
|
|
36
|
+
|
|
37
|
+
API_SERVER_URL: z.string().url().optional(),
|
|
38
|
+
|
|
39
|
+
SENTRY_DSN: z.string().default(''),
|
|
40
|
+
REDIS_URL: z.string().url().default('redis://localhost:6379'),
|
|
41
|
+
})
|
|
42
|
+
.strip();
|
|
43
|
+
|
|
44
|
+
/**
|
|
45
|
+
* 3) 검증(모듈 import 시점에 실행)
|
|
46
|
+
*/
|
|
47
|
+
const parsed = EnvSchema.safeParse(process.env);
|
|
48
|
+
if (!parsed.success) {
|
|
49
|
+
console.error('\n❌ Invalid environment variables:\n');
|
|
50
|
+
console.error(parsed.error.format());
|
|
51
|
+
process.exit(1);
|
|
52
|
+
}
|
|
53
|
+
const env = parsed.data;
|
|
54
|
+
|
|
55
|
+
/**
|
|
56
|
+
* 4) 타입 안전한 상수 export
|
|
57
|
+
* - 다른 파일에서는 process.env 직접 쓰지 말고 여기서만 가져가세요.
|
|
58
|
+
*/
|
|
59
|
+
export const NODE_ENV = env.NODE_ENV;
|
|
60
|
+
export const PORT = env.PORT; // app.ts에서 PORT || 3000
|
|
61
|
+
export const SECRET_KEY = env.SECRET_KEY;
|
|
62
|
+
|
|
63
|
+
export const LOG_FORMAT = env.LOG_FORMAT; // app.ts에서 LOG_FORMAT || 'dev'
|
|
64
|
+
export const LOG_DIR = env.LOG_DIR;
|
|
65
|
+
export const LOG_LEVEL = env.LOG_LEVEL;
|
|
66
|
+
|
|
67
|
+
export const ORIGIN = env.ORIGIN;
|
|
68
|
+
export const CREDENTIALS = env.CREDENTIALS;
|
|
69
|
+
|
|
70
|
+
export const SENTRY_DSN = env.SENTRY_DSN;
|
|
71
|
+
export const REDIS_URL = env.REDIS_URL;
|
|
72
|
+
export const API_SERVER_URL = env.API_SERVER_URL;
|
|
73
|
+
|
|
74
|
+
// CORS Origins를 배열로도 제공 (없으면 [])
|
|
75
|
+
export const CORS_ORIGIN_LIST =
|
|
76
|
+
env.CORS_ORIGINS?.split(',')
|
|
77
|
+
.map((s) => s.trim())
|
|
78
|
+
.filter(Boolean) ?? [];
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import type { Request, Response } from 'express';
|
|
2
|
+
import { injectable, inject } from 'tsyringe';
|
|
3
|
+
import { RequestWithUser } from '@interfaces/auth.interface';
|
|
4
|
+
import { type UserCreateData } from '@entities/user.entity';
|
|
5
|
+
import { AuthService } from '@services/auth.service';
|
|
6
|
+
import { asyncHandler } from '@utils/asyncHandler';
|
|
7
|
+
|
|
8
|
+
@injectable()
|
|
9
|
+
export class AuthController {
|
|
10
|
+
constructor(@inject(AuthService) private readonly authService: AuthService) {}
|
|
11
|
+
|
|
12
|
+
public signUp = asyncHandler(async (req: Request, res: Response) => {
|
|
13
|
+
const userData: UserCreateData = req.body;
|
|
14
|
+
const signUpUserData = await this.authService.signup(userData);
|
|
15
|
+
|
|
16
|
+
res.status(201).json({ data: signUpUserData.toResponse(), message: 'signup' });
|
|
17
|
+
});
|
|
18
|
+
|
|
19
|
+
public logIn = asyncHandler(async (req: Request, res: Response) => {
|
|
20
|
+
const loginData: { email: string; password: string } = req.body;
|
|
21
|
+
const { cookie, user } = await this.authService.login(loginData);
|
|
22
|
+
|
|
23
|
+
res.setHeader('Set-Cookie', [cookie]);
|
|
24
|
+
res.status(200).json({ data: user.toResponse(), message: 'login' });
|
|
25
|
+
});
|
|
26
|
+
|
|
27
|
+
public logOut = asyncHandler(async (req: Request, res: Response) => {
|
|
28
|
+
const userReq = req as RequestWithUser;
|
|
29
|
+
const user = userReq.user;
|
|
30
|
+
await this.authService.logout(user);
|
|
31
|
+
|
|
32
|
+
res.clearCookie('Authorization', {
|
|
33
|
+
httpOnly: true,
|
|
34
|
+
path: '/',
|
|
35
|
+
sameSite: 'lax',
|
|
36
|
+
// secure: true, // 프로덕션에서 HTTPS일 때만
|
|
37
|
+
});
|
|
38
|
+
res.status(200).json({ message: 'logout' });
|
|
39
|
+
});
|
|
40
|
+
}
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import type { Request, Response } from 'express';
|
|
2
|
+
import { injectable, inject } from 'tsyringe';
|
|
3
|
+
import { type UserCreateData } from '@entities/user.entity';
|
|
4
|
+
import { UsersService } from '@services/users.service';
|
|
5
|
+
import { asyncHandler } from '@utils/asyncHandler';
|
|
6
|
+
|
|
7
|
+
@injectable()
|
|
8
|
+
export class UsersController {
|
|
9
|
+
constructor(@inject(UsersService) private readonly userService: UsersService) {}
|
|
10
|
+
|
|
11
|
+
getUsers = asyncHandler(async (req: Request, res: Response) => {
|
|
12
|
+
const users = await this.userService.getAllUsers();
|
|
13
|
+
const userResponses = users.map((user) => user.toResponse());
|
|
14
|
+
|
|
15
|
+
res.json({ data: userResponses, message: 'findAll' });
|
|
16
|
+
});
|
|
17
|
+
|
|
18
|
+
getUserById = asyncHandler(async (req: Request, res: Response) => {
|
|
19
|
+
const userId: string = req.params.id;
|
|
20
|
+
const user = await this.userService.getUserById(userId);
|
|
21
|
+
|
|
22
|
+
res.json({ data: user.toResponse(), message: 'findById' });
|
|
23
|
+
});
|
|
24
|
+
|
|
25
|
+
createUser = asyncHandler(async (req: Request, res: Response) => {
|
|
26
|
+
const userData: UserCreateData = req.body;
|
|
27
|
+
const user = await this.userService.createUser(userData);
|
|
28
|
+
|
|
29
|
+
res.status(201).json({ data: user.toResponse(), message: 'create' });
|
|
30
|
+
});
|
|
31
|
+
|
|
32
|
+
updateUser = asyncHandler(async (req: Request, res: Response) => {
|
|
33
|
+
const userId: string = req.params.id;
|
|
34
|
+
const updateData: { email?: string; password?: string } = req.body;
|
|
35
|
+
const user = await this.userService.updateUser(userId, updateData);
|
|
36
|
+
|
|
37
|
+
res.json({ data: user.toResponse(), message: 'update' });
|
|
38
|
+
});
|
|
39
|
+
|
|
40
|
+
deleteUser = asyncHandler(async (req: Request, res: Response) => {
|
|
41
|
+
const userId: string = req.params.id;
|
|
42
|
+
await this.userService.deleteUser(userId);
|
|
43
|
+
|
|
44
|
+
res.status(204).json({ message: 'delete' });
|
|
45
|
+
});
|
|
46
|
+
}
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
|
|
3
|
+
// 이메일 스키마 - Entity의 검증 규칙과 일치
|
|
4
|
+
export const emailSchema = z
|
|
5
|
+
.string()
|
|
6
|
+
.min(1, { message: 'Email is required' })
|
|
7
|
+
.max(254, { message: 'Email is too long (max 254 characters)' })
|
|
8
|
+
.email({ message: 'Invalid email format' })
|
|
9
|
+
.transform((email) => email.toLowerCase().trim());
|
|
10
|
+
|
|
11
|
+
// 비밀번호 스키마 - Entity의 검증 규칙과 일치
|
|
12
|
+
export const passwordSchema = z
|
|
13
|
+
.string()
|
|
14
|
+
.min(8, { message: 'Password must be at least 8 characters long' })
|
|
15
|
+
.max(128, { message: 'Password is too long (max 128 characters)' })
|
|
16
|
+
.refine((password) => /\d/.test(password) && /[a-zA-Z]/.test(password), {
|
|
17
|
+
message: 'Password must contain at least one letter and one number',
|
|
18
|
+
});
|
|
19
|
+
|
|
20
|
+
// 회원가입/로그인 DTO
|
|
21
|
+
export const createUserSchema = z.object({
|
|
22
|
+
email: emailSchema,
|
|
23
|
+
password: passwordSchema,
|
|
24
|
+
});
|
|
25
|
+
|
|
26
|
+
export type CreateUserDto = z.infer<typeof createUserSchema>;
|
|
27
|
+
|
|
28
|
+
// 로그인 DTO (동일하지만 명시적으로 분리)
|
|
29
|
+
export const loginUserSchema = z.object({
|
|
30
|
+
email: emailSchema,
|
|
31
|
+
password: z.string().min(1, { message: 'Password is required' }), // 로그인시에는 기존 패스워드 검증 생략
|
|
32
|
+
});
|
|
33
|
+
|
|
34
|
+
export type LoginUserDto = z.infer<typeof loginUserSchema>;
|
|
35
|
+
|
|
36
|
+
// 수정 DTO (모든 필드 optional)
|
|
37
|
+
export const updateUserSchema = z.object({
|
|
38
|
+
email: emailSchema.optional(),
|
|
39
|
+
password: passwordSchema.optional(),
|
|
40
|
+
});
|
|
41
|
+
|
|
42
|
+
export type UpdateUserDto = z.infer<typeof updateUserSchema>;
|
|
@@ -0,0 +1,190 @@
|
|
|
1
|
+
import { hash, compare } from 'bcryptjs';
|
|
2
|
+
import crypto from 'crypto';
|
|
3
|
+
|
|
4
|
+
export interface UserPersistenceData {
|
|
5
|
+
id: string;
|
|
6
|
+
email: string;
|
|
7
|
+
password: string;
|
|
8
|
+
createdAt?: Date;
|
|
9
|
+
updatedAt?: Date;
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
export interface UserCreateData {
|
|
13
|
+
email: string;
|
|
14
|
+
password: string;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
export class User {
|
|
18
|
+
private constructor(
|
|
19
|
+
private readonly _id: string,
|
|
20
|
+
private _email: string,
|
|
21
|
+
private _password: string,
|
|
22
|
+
private readonly _createdAt: Date = new Date(),
|
|
23
|
+
private _updatedAt: Date = new Date(),
|
|
24
|
+
) {}
|
|
25
|
+
|
|
26
|
+
// 팩토리 메서드 - 새로운 사용자 생성
|
|
27
|
+
static async create(data: UserCreateData): Promise<User> {
|
|
28
|
+
const id = User.generateId();
|
|
29
|
+
const validatedEmail = User.validateEmail(data.email);
|
|
30
|
+
const hashedPassword = await User.hashPassword(data.password);
|
|
31
|
+
|
|
32
|
+
return new User(id, validatedEmail, hashedPassword);
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
// 기존 데이터로부터 복원 (DB에서 조회한 경우)
|
|
36
|
+
static fromPersistence(data: UserPersistenceData): User {
|
|
37
|
+
return new User(
|
|
38
|
+
data.id,
|
|
39
|
+
data.email,
|
|
40
|
+
data.password,
|
|
41
|
+
data.createdAt || new Date(),
|
|
42
|
+
data.updatedAt || new Date(),
|
|
43
|
+
);
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
// 비즈니스 로직 - 이메일 변경
|
|
47
|
+
async changeEmail(newEmail: string): Promise<void> {
|
|
48
|
+
const validatedEmail = User.validateEmail(newEmail);
|
|
49
|
+
this._email = validatedEmail;
|
|
50
|
+
this._updatedAt = new Date();
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
// 비즈니스 로직 - 패스워드 변경
|
|
54
|
+
async changePassword(newPassword: string): Promise<void> {
|
|
55
|
+
User.validatePassword(newPassword);
|
|
56
|
+
const hashedPassword = await User.hashPassword(newPassword);
|
|
57
|
+
this._password = hashedPassword;
|
|
58
|
+
this._updatedAt = new Date();
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
// 패스워드 검증
|
|
62
|
+
async verifyPassword(inputPassword: string): Promise<boolean> {
|
|
63
|
+
return compare(inputPassword, this._password);
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
// 도메인 규칙 - 이메일 검증
|
|
67
|
+
private static validateEmail(email: string): string {
|
|
68
|
+
if (!email || typeof email !== 'string') {
|
|
69
|
+
throw new Error('Email is required');
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
const trimmedEmail = email.trim();
|
|
73
|
+
|
|
74
|
+
if (trimmedEmail.length === 0) {
|
|
75
|
+
throw new Error('Email cannot be empty');
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
if (trimmedEmail.length > 254) {
|
|
79
|
+
throw new Error('Email is too long (max 254 characters)');
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
const emailRegex = /^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}$/;
|
|
83
|
+
if (!emailRegex.test(trimmedEmail)) {
|
|
84
|
+
throw new Error('Invalid email format');
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
return trimmedEmail.toLowerCase();
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
// 도메인 규칙 - 패스워드 검증
|
|
91
|
+
private static validatePassword(password: string): void {
|
|
92
|
+
if (!password || typeof password !== 'string') {
|
|
93
|
+
throw new Error('Password is required');
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
if (password.length < 8) {
|
|
97
|
+
throw new Error('Password must be at least 8 characters long');
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
if (password.length > 128) {
|
|
101
|
+
throw new Error('Password is too long (max 128 characters)');
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
// 최소 하나의 숫자와 하나의 문자 포함
|
|
105
|
+
const hasNumber = /\d/.test(password);
|
|
106
|
+
const hasLetter = /[a-zA-Z]/.test(password);
|
|
107
|
+
|
|
108
|
+
if (!hasNumber || !hasLetter) {
|
|
109
|
+
throw new Error('Password must contain at least one letter and one number');
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
// 패스워드 해싱
|
|
114
|
+
private static async hashPassword(password: string): Promise<string> {
|
|
115
|
+
User.validatePassword(password);
|
|
116
|
+
return hash(password, 12); // 보안 강화를 위해 12 rounds 사용
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
// ID 생성
|
|
120
|
+
private static generateId(): string {
|
|
121
|
+
return crypto.randomUUID();
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
// Getter들 - 외부에서 직접 수정 불가능
|
|
125
|
+
get id(): string {
|
|
126
|
+
return this._id;
|
|
127
|
+
}
|
|
128
|
+
get email(): string {
|
|
129
|
+
return this._email;
|
|
130
|
+
}
|
|
131
|
+
get password(): string {
|
|
132
|
+
return this._password;
|
|
133
|
+
}
|
|
134
|
+
get createdAt(): Date {
|
|
135
|
+
return new Date(this._createdAt);
|
|
136
|
+
} // 방어적 복사
|
|
137
|
+
get updatedAt(): Date {
|
|
138
|
+
return new Date(this._updatedAt);
|
|
139
|
+
} // 방어적 복사
|
|
140
|
+
|
|
141
|
+
// 도메인 메서드 - 사용자 정보 업데이트
|
|
142
|
+
async updateProfile(data: { email?: string; password?: string }): Promise<void> {
|
|
143
|
+
let hasChanges = false;
|
|
144
|
+
|
|
145
|
+
if (data.email && data.email !== this._email) {
|
|
146
|
+
await this.changeEmail(data.email);
|
|
147
|
+
hasChanges = true;
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
if (data.password) {
|
|
151
|
+
await this.changePassword(data.password);
|
|
152
|
+
hasChanges = true;
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
if (hasChanges) {
|
|
156
|
+
this._updatedAt = new Date();
|
|
157
|
+
}
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
// 영속성을 위한 직렬화
|
|
161
|
+
toPersistence(): UserPersistenceData {
|
|
162
|
+
return {
|
|
163
|
+
id: this._id,
|
|
164
|
+
email: this._email,
|
|
165
|
+
password: this._password,
|
|
166
|
+
createdAt: this._createdAt,
|
|
167
|
+
updatedAt: this._updatedAt,
|
|
168
|
+
};
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
// API 응답용 직렬화 (패스워드 제외)
|
|
172
|
+
toResponse(): {
|
|
173
|
+
id: string;
|
|
174
|
+
email: string;
|
|
175
|
+
createdAt: Date;
|
|
176
|
+
updatedAt: Date;
|
|
177
|
+
} {
|
|
178
|
+
return {
|
|
179
|
+
id: this._id,
|
|
180
|
+
email: this._email,
|
|
181
|
+
createdAt: this._createdAt,
|
|
182
|
+
updatedAt: this._updatedAt,
|
|
183
|
+
};
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
// 동등성 비교
|
|
187
|
+
equals(other: User): boolean {
|
|
188
|
+
return this._id === other._id;
|
|
189
|
+
}
|
|
190
|
+
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
export class HttpException extends Error {
|
|
2
|
+
public status: number;
|
|
3
|
+
public message: string;
|
|
4
|
+
public data?: unknown;
|
|
5
|
+
|
|
6
|
+
constructor(status: number, message: string, data?: unknown) {
|
|
7
|
+
super(message);
|
|
8
|
+
this.status = status;
|
|
9
|
+
this.message = message;
|
|
10
|
+
this.data = data;
|
|
11
|
+
this.name = this.constructor.name;
|
|
12
|
+
Error.captureStackTrace?.(this, this.constructor);
|
|
13
|
+
}
|
|
14
|
+
}
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import { Request } from 'express';
|
|
2
|
-
import { User } from '@
|
|
1
|
+
import type { Request } from 'express';
|
|
2
|
+
import { User } from '@entities/user.entity';
|
|
3
3
|
|
|
4
4
|
export interface DataStoredInToken {
|
|
5
|
-
id: number;
|
|
5
|
+
id: number | string;
|
|
6
6
|
}
|
|
7
7
|
|
|
8
8
|
export interface TokenData {
|