typescript-express-starter 9.2.0 → 10.0.1
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/CONTRIBUTORS.md +69 -0
- package/README.kr.md +122 -167
- package/README.md +118 -163
- package/bin/cli.js +1 -1
- package/lib/default/.swcrc +0 -3
- package/lib/default/Dockerfile.dev +18 -0
- package/lib/default/Dockerfile.prod +18 -0
- package/lib/default/Makefile +29 -16
- package/lib/default/docker-compose.yml +8 -8
- package/lib/default/package.json +3 -1
- package/lib/default/src/app.ts +4 -5
- package/lib/default/src/controllers/auth.controller.ts +9 -11
- package/lib/default/src/controllers/users.controller.ts +11 -13
- package/lib/default/src/dtos/users.dto.ts +12 -1
- package/lib/default/src/interfaces/users.interface.ts +2 -2
- package/lib/default/src/middlewares/auth.middleware.ts +16 -10
- package/lib/default/src/middlewares/error.middleware.ts +2 -4
- package/lib/default/src/middlewares/validation.middleware.ts +22 -20
- package/lib/default/src/models/users.model.ts +6 -8
- package/lib/default/src/routes/auth.route.ts +8 -11
- package/lib/default/src/routes/users.route.ts +10 -12
- package/lib/default/src/server.ts +6 -7
- package/lib/default/src/services/auth.service.ts +22 -33
- package/lib/default/src/services/users.service.ts +16 -25
- package/lib/{graphql/src/tests → default/src/test}/auth.test.ts +21 -21
- package/lib/default/src/test/users.test.ts +62 -0
- package/lib/default/src/utils/validateEnv.ts +1 -3
- package/lib/default/tsconfig.json +1 -1
- package/lib/graphql/.env.development.local +6 -6
- package/lib/graphql/.env.production.local +6 -6
- package/lib/graphql/.env.test.local +6 -6
- package/lib/graphql/.swcrc +1 -1
- package/lib/graphql/Dockerfile.dev +19 -0
- package/lib/graphql/Dockerfile.prod +19 -0
- package/lib/graphql/Makefile +32 -15
- package/lib/graphql/docker-compose.yml +23 -15
- package/lib/graphql/package.json +2 -1
- package/lib/graphql/src/app.ts +16 -16
- package/lib/graphql/src/config/index.ts +2 -2
- package/lib/graphql/src/database/index.ts +26 -0
- package/lib/graphql/src/dtos/users.dto.ts +14 -1
- package/lib/graphql/src/interfaces/users.interface.ts +2 -2
- package/lib/graphql/src/middlewares/auth.middleware.ts +16 -6
- package/lib/graphql/src/middlewares/error.middleware.ts +2 -4
- package/lib/graphql/src/repositories/auth.repository.ts +16 -24
- package/lib/graphql/src/repositories/users.repository.ts +5 -14
- package/lib/graphql/src/resolvers/auth.resolver.ts +2 -2
- package/lib/graphql/src/resolvers/users.resolver.ts +4 -4
- package/lib/graphql/src/server.ts +6 -7
- package/lib/graphql/src/test/auth.test.ts +10 -0
- package/lib/graphql/src/test/users.test.ts +11 -0
- package/lib/graphql/src/typedefs/users.type.ts +2 -2
- package/lib/graphql/src/utils/logger.ts +2 -0
- package/lib/graphql/src/utils/validateEnv.ts +1 -3
- package/lib/graphql/tsconfig.json +2 -2
- package/lib/knex/.env.development.local +2 -2
- package/lib/knex/.env.production.local +3 -3
- package/lib/knex/.env.test.local +3 -3
- package/lib/knex/.swcrc +1 -1
- package/lib/knex/Dockerfile.dev +19 -0
- package/lib/knex/Dockerfile.prod +19 -0
- package/lib/knex/Makefile +32 -15
- package/lib/knex/docker-compose.yml +19 -14
- package/lib/knex/knexfile.ts +7 -9
- package/lib/knex/package.json +2 -0
- package/lib/knex/src/app.ts +7 -9
- package/lib/knex/src/config/index.ts +2 -1
- package/lib/knex/src/controllers/auth.controller.ts +9 -11
- package/lib/knex/src/controllers/users.controller.ts +10 -12
- package/lib/knex/src/database/index.ts +24 -0
- package/lib/knex/src/database/migrations/20210713110926_initial.ts +17 -0
- package/lib/knex/src/dtos/users.dto.ts +12 -1
- package/lib/knex/src/interfaces/users.interface.ts +2 -2
- package/lib/knex/src/middlewares/auth.middleware.ts +17 -10
- package/lib/knex/src/middlewares/error.middleware.ts +2 -4
- package/lib/knex/src/middlewares/validation.middleware.ts +22 -20
- package/lib/knex/src/models/users.model.ts +2 -2
- package/lib/knex/src/routes/auth.route.ts +8 -10
- package/lib/knex/src/routes/users.route.ts +10 -12
- package/lib/knex/src/server.ts +6 -7
- package/lib/knex/src/services/auth.service.ts +24 -33
- package/lib/knex/src/services/users.service.ts +14 -19
- package/lib/knex/src/{tests → test}/auth.test.ts +2 -2
- package/lib/knex/src/{tests → test}/users.test.ts +2 -2
- package/lib/knex/src/utils/validateEnv.ts +1 -3
- package/lib/knex/tsconfig.json +2 -2
- package/lib/mikro-orm/.env.production.local +1 -1
- package/lib/mikro-orm/.env.test.local +1 -1
- package/lib/mikro-orm/.swcrc +1 -1
- package/lib/mikro-orm/Dockerfile.dev +19 -0
- package/lib/mikro-orm/Dockerfile.prod +19 -0
- package/lib/mikro-orm/Makefile +32 -15
- package/lib/mikro-orm/docker-compose.yml +20 -11
- package/lib/mikro-orm/package.json +2 -0
- package/lib/mikro-orm/src/app.ts +12 -13
- package/lib/mikro-orm/src/config/index.ts +2 -1
- package/lib/mikro-orm/src/controllers/auth.controller.ts +9 -11
- package/lib/mikro-orm/src/controllers/users.controller.ts +11 -13
- package/lib/mikro-orm/src/dtos/users.dto.ts +12 -1
- package/lib/mikro-orm/src/interfaces/users.interface.ts +1 -1
- package/lib/mikro-orm/src/middlewares/auth.middleware.ts +17 -10
- package/lib/mikro-orm/src/middlewares/error.middleware.ts +2 -4
- package/lib/mikro-orm/src/middlewares/validation.middleware.ts +22 -20
- package/lib/mikro-orm/src/routes/auth.route.ts +8 -10
- package/lib/mikro-orm/src/routes/users.route.ts +9 -11
- package/lib/mikro-orm/src/server.ts +6 -7
- package/lib/mikro-orm/src/services/auth.service.ts +19 -29
- package/lib/mikro-orm/src/services/users.service.ts +8 -16
- package/lib/mikro-orm/src/{tests → test}/auth.test.ts +3 -4
- package/lib/mikro-orm/src/{tests → test}/users.test.ts +4 -5
- package/lib/mikro-orm/src/utils/validateEnv.ts +1 -3
- package/lib/mikro-orm/tsconfig.json +2 -2
- package/lib/mongoose/.env.production.local +1 -1
- package/lib/mongoose/.env.test.local +1 -1
- package/lib/mongoose/.swcrc +1 -1
- package/lib/mongoose/Dockerfile.dev +19 -0
- package/lib/mongoose/Dockerfile.prod +19 -0
- package/lib/mongoose/Makefile +32 -15
- package/lib/mongoose/docker-compose.yml +20 -11
- package/lib/mongoose/package.json +2 -0
- package/lib/mongoose/src/app.ts +7 -13
- package/lib/mongoose/src/config/index.ts +2 -1
- package/lib/mongoose/src/controllers/auth.controller.ts +9 -11
- package/lib/mongoose/src/controllers/users.controller.ts +11 -13
- package/lib/mongoose/src/database/index.ts +18 -0
- package/lib/mongoose/src/dtos/users.dto.ts +12 -1
- package/lib/mongoose/src/interfaces/users.interface.ts +1 -1
- package/lib/mongoose/src/middlewares/auth.middleware.ts +16 -9
- package/lib/mongoose/src/middlewares/error.middleware.ts +2 -4
- package/lib/mongoose/src/middlewares/validation.middleware.ts +22 -20
- package/lib/mongoose/src/models/users.model.ts +2 -4
- package/lib/mongoose/src/routes/auth.route.ts +8 -10
- package/lib/mongoose/src/routes/users.route.ts +9 -11
- package/lib/mongoose/src/server.ts +6 -7
- package/lib/mongoose/src/services/auth.service.ts +22 -33
- package/lib/mongoose/src/services/users.service.ts +14 -24
- package/lib/{typegoose/src/tests → mongoose/src/test}/users.test.ts +7 -7
- package/lib/mongoose/src/utils/validateEnv.ts +1 -3
- package/lib/mongoose/tsconfig.json +2 -2
- package/lib/node-postgres/.dockerignore +18 -0
- package/lib/node-postgres/.editorconfig +9 -0
- package/lib/node-postgres/.env.development.local +13 -0
- package/lib/node-postgres/.env.production.local +13 -0
- package/lib/node-postgres/.env.test.local +13 -0
- package/lib/node-postgres/.eslintignore +1 -0
- package/lib/node-postgres/.eslintrc +18 -0
- package/lib/node-postgres/.huskyrc +5 -0
- package/lib/node-postgres/.lintstagedrc.json +5 -0
- package/lib/node-postgres/.prettierrc +8 -0
- package/lib/node-postgres/.swcrc +39 -0
- package/lib/node-postgres/.vscode/launch.json +35 -0
- package/lib/node-postgres/.vscode/settings.json +6 -0
- package/lib/node-postgres/Dockerfile.dev +17 -0
- package/lib/node-postgres/Dockerfile.prod +17 -0
- package/lib/node-postgres/Makefile +46 -0
- package/lib/node-postgres/docker-compose.yml +61 -0
- package/lib/node-postgres/ecosystem.config.js +57 -0
- package/lib/node-postgres/jest.config.js +12 -0
- package/lib/node-postgres/nginx.conf +40 -0
- package/lib/node-postgres/nodemon.json +12 -0
- package/lib/node-postgres/package.json +78 -0
- package/lib/node-postgres/src/app.ts +87 -0
- package/lib/node-postgres/src/config/index.ts +6 -0
- package/lib/node-postgres/src/controllers/auth.controller.ts +44 -0
- package/lib/node-postgres/src/controllers/users.controller.ts +63 -0
- package/lib/node-postgres/src/database/index.ts +6 -0
- package/lib/node-postgres/src/database/init.sql +110 -0
- package/lib/node-postgres/src/dtos/users.dto.ts +20 -0
- package/lib/node-postgres/src/exceptions/httpException.ts +10 -0
- package/lib/node-postgres/src/http/auth.http +27 -0
- package/lib/node-postgres/src/http/users.http +34 -0
- package/lib/node-postgres/src/interfaces/auth.interface.ts +15 -0
- package/lib/node-postgres/src/interfaces/routes.interface.ts +6 -0
- package/lib/node-postgres/src/interfaces/users.interface.ts +5 -0
- package/lib/node-postgres/src/middlewares/auth.middleware.ts +38 -0
- package/lib/node-postgres/src/middlewares/error.middleware.ts +15 -0
- package/lib/node-postgres/src/middlewares/validation.middleware.ts +27 -0
- package/lib/node-postgres/src/models/users.model.ts +9 -0
- package/lib/node-postgres/src/routes/auth.route.ts +21 -0
- package/lib/node-postgres/src/routes/users.route.ts +23 -0
- package/lib/node-postgres/src/server.ts +10 -0
- package/lib/node-postgres/src/services/auth.service.ts +52 -0
- package/lib/node-postgres/src/services/users.service.ts +51 -0
- package/lib/{default/src/tests → node-postgres/src/test}/auth.test.ts +2 -2
- package/lib/{default/src/tests → node-postgres/src/test}/users.test.ts +5 -5
- package/lib/node-postgres/src/utils/logger.ts +65 -0
- package/lib/node-postgres/src/utils/validateEnv.ts +8 -0
- package/lib/node-postgres/swagger.yaml +123 -0
- package/lib/node-postgres/tsconfig.json +40 -0
- package/lib/prisma/.env.production.local +1 -1
- package/lib/prisma/.env.test.local +1 -1
- package/lib/prisma/Dockerfile.dev +19 -0
- package/lib/prisma/Dockerfile.prod +19 -0
- package/lib/prisma/Makefile +32 -15
- package/lib/prisma/docker-compose.yml +15 -14
- package/lib/prisma/package.json +2 -0
- package/lib/prisma/src/app.ts +4 -5
- package/lib/prisma/src/controllers/auth.controller.ts +10 -12
- package/lib/prisma/src/controllers/users.controller.ts +12 -14
- package/lib/prisma/src/dtos/users.dto.ts +12 -1
- package/lib/prisma/src/interfaces/auth.interface.ts +1 -1
- package/lib/prisma/src/interfaces/users.interface.ts +5 -0
- package/lib/prisma/src/middlewares/auth.middleware.ts +16 -11
- package/lib/prisma/src/middlewares/error.middleware.ts +2 -4
- package/lib/prisma/src/middlewares/validation.middleware.ts +22 -20
- package/lib/prisma/src/routes/auth.route.ts +8 -10
- package/lib/prisma/src/routes/users.route.ts +9 -11
- package/lib/prisma/src/server.ts +6 -7
- package/lib/prisma/src/services/auth.service.ts +6 -12
- package/lib/prisma/src/services/users.service.ts +15 -23
- package/lib/prisma/src/utils/validateEnv.ts +1 -3
- package/lib/prisma/tsconfig.json +1 -1
- package/lib/routing-controllers/Dockerfile.dev +19 -0
- package/lib/routing-controllers/Dockerfile.prod +19 -0
- package/lib/routing-controllers/Makefile +29 -16
- package/lib/routing-controllers/docker-compose.yml +9 -9
- package/lib/routing-controllers/package.json +1 -0
- package/lib/routing-controllers/src/app.ts +4 -6
- package/lib/routing-controllers/src/controllers/auth.controller.ts +13 -12
- package/lib/routing-controllers/src/controllers/users.controller.ts +15 -13
- package/lib/routing-controllers/src/dtos/users.dto.ts +12 -1
- package/lib/routing-controllers/src/interfaces/users.interface.ts +1 -1
- package/lib/routing-controllers/src/middlewares/auth.middleware.ts +16 -10
- package/lib/routing-controllers/src/middlewares/error.middleware.ts +2 -5
- package/lib/routing-controllers/src/middlewares/validation.middleware.ts +23 -27
- package/lib/routing-controllers/src/models/users.model.ts +1 -3
- package/lib/routing-controllers/src/server.ts +5 -6
- package/lib/routing-controllers/src/services/auth.service.ts +21 -31
- package/lib/routing-controllers/src/services/users.service.ts +13 -21
- package/lib/routing-controllers/src/{tests → test}/auth.test.ts +1 -1
- package/lib/routing-controllers/src/{tests → test}/users.test.ts +10 -10
- package/lib/routing-controllers/src/utils/validateEnv.ts +1 -3
- package/lib/routing-controllers/tsconfig.json +1 -1
- package/lib/sequelize/.env.development.local +2 -2
- package/lib/sequelize/.env.production.local +3 -3
- package/lib/sequelize/.env.test.local +3 -3
- package/lib/sequelize/.sequelizerc +8 -0
- package/lib/sequelize/.swcrc +1 -1
- package/lib/sequelize/Dockerfile.dev +23 -0
- package/lib/sequelize/Dockerfile.prod +23 -0
- package/lib/sequelize/Makefile +32 -15
- package/lib/sequelize/docker-compose.yml +19 -14
- package/lib/sequelize/package.json +5 -1
- package/lib/sequelize/src/app.ts +7 -8
- package/lib/sequelize/src/config/index.ts +2 -1
- package/lib/sequelize/src/config/sequelize-cli.js +15 -0
- package/lib/sequelize/src/controllers/auth.controller.ts +7 -8
- package/lib/sequelize/src/controllers/users.controller.ts +9 -10
- package/lib/sequelize/src/{databases → database}/index.ts +1 -3
- package/lib/sequelize/src/dtos/users.dto.ts +12 -1
- package/lib/sequelize/src/interfaces/users.interface.ts +1 -1
- package/lib/sequelize/src/middlewares/auth.middleware.ts +16 -10
- package/lib/sequelize/src/middlewares/error.middleware.ts +2 -4
- package/lib/sequelize/src/middlewares/validation.middleware.ts +22 -20
- package/lib/sequelize/src/routes/auth.route.ts +8 -11
- package/lib/sequelize/src/routes/users.route.ts +9 -11
- package/lib/sequelize/src/server.ts +6 -7
- package/lib/sequelize/src/services/auth.service.ts +20 -31
- package/lib/sequelize/src/services/users.service.ts +14 -25
- package/lib/sequelize/src/{tests → test}/auth.test.ts +2 -2
- package/lib/sequelize/src/{tests → test}/users.test.ts +2 -2
- package/lib/sequelize/src/utils/validateEnv.ts +1 -3
- package/lib/sequelize/tsconfig.json +2 -2
- package/lib/starter.js +17 -26
- package/lib/typegoose/.env.production.local +1 -1
- package/lib/typegoose/.env.test.local +1 -1
- package/lib/typegoose/.swcrc +1 -1
- package/lib/typegoose/Dockerfile.dev +19 -0
- package/lib/typegoose/Dockerfile.prod +19 -0
- package/lib/typegoose/Makefile +32 -15
- package/lib/typegoose/docker-compose.yml +20 -11
- package/lib/typegoose/package.json +2 -0
- package/lib/typegoose/src/app.ts +7 -10
- package/lib/typegoose/src/config/index.ts +2 -1
- package/lib/typegoose/src/controllers/auth.controller.ts +9 -11
- package/lib/typegoose/src/controllers/users.controller.ts +11 -13
- package/lib/typegoose/src/database/index.ts +18 -0
- package/lib/typegoose/src/dtos/users.dto.ts +12 -1
- package/lib/typegoose/src/interfaces/users.interface.ts +1 -1
- package/lib/typegoose/src/middlewares/auth.middleware.ts +16 -10
- package/lib/typegoose/src/middlewares/error.middleware.ts +2 -4
- package/lib/typegoose/src/middlewares/validation.middleware.ts +22 -20
- package/lib/typegoose/src/models/users.model.ts +1 -3
- package/lib/typegoose/src/routes/auth.route.ts +8 -11
- package/lib/typegoose/src/routes/users.route.ts +9 -11
- package/lib/typegoose/src/server.ts +5 -6
- package/lib/typegoose/src/services/auth.service.ts +23 -32
- package/lib/typegoose/src/services/users.service.ts +12 -21
- package/lib/typegoose/src/{tests → test}/auth.test.ts +2 -2
- package/lib/{mongoose/src/tests → typegoose/src/test}/users.test.ts +7 -7
- package/lib/typegoose/src/utils/validateEnv.ts +1 -3
- package/lib/typegoose/tsconfig.json +2 -2
- package/lib/typeorm/.env.development.local +2 -2
- package/lib/typeorm/.env.production.local +3 -3
- package/lib/typeorm/.env.test.local +3 -3
- package/lib/typeorm/.swcrc +1 -1
- package/lib/typeorm/Dockerfile.dev +19 -0
- package/lib/typeorm/Dockerfile.prod +19 -0
- package/lib/typeorm/Makefile +32 -15
- package/lib/typeorm/docker-compose.yml +21 -14
- package/lib/typeorm/package.json +1 -0
- package/lib/typeorm/src/app.ts +7 -10
- package/lib/typeorm/src/config/index.ts +2 -1
- package/lib/typeorm/src/controllers/auth.controller.ts +9 -11
- package/lib/typeorm/src/controllers/users.controller.ts +11 -13
- package/lib/typeorm/src/database/index.ts +26 -0
- package/lib/typeorm/src/dtos/users.dto.ts +12 -1
- package/lib/typeorm/src/interfaces/users.interface.ts +1 -1
- package/lib/typeorm/src/middlewares/auth.middleware.ts +14 -7
- package/lib/typeorm/src/middlewares/error.middleware.ts +2 -4
- package/lib/typeorm/src/middlewares/validation.middleware.ts +22 -20
- package/lib/typeorm/src/routes/auth.route.ts +8 -11
- package/lib/typeorm/src/routes/users.route.ts +9 -11
- package/lib/typeorm/src/server.ts +6 -7
- package/lib/typeorm/src/services/auth.service.ts +20 -28
- package/lib/typeorm/src/services/users.service.ts +6 -16
- package/lib/typeorm/src/{tests → test}/auth.test.ts +6 -6
- package/lib/typeorm/src/{tests → test}/users.test.ts +6 -6
- package/lib/typeorm/src/utils/validateEnv.ts +1 -3
- package/lib/typeorm/tsconfig.json +2 -2
- package/package.json +2 -1
- package/lib/default/Dockerfile +0 -24
- package/lib/default/src/controllers/index.controller.ts +0 -13
- package/lib/default/src/routes/index.route.ts +0 -19
- package/lib/default/src/utils/util.ts +0 -19
- package/lib/graphql/Dockerfile +0 -24
- package/lib/graphql/src/databases/index.ts +0 -22
- package/lib/graphql/src/tests/index.test.ts +0 -18
- package/lib/graphql/src/tests/users.test.ts +0 -71
- package/lib/graphql/src/utils/util.ts +0 -19
- package/lib/knex/Dockerfile +0 -24
- package/lib/knex/src/controllers/index.controller.ts +0 -13
- package/lib/knex/src/databases/index.ts +0 -21
- package/lib/knex/src/databases/migrations/20210713110926_initial.ts +0 -13
- package/lib/knex/src/routes/index.route.ts +0 -19
- package/lib/knex/src/tests/index.test.ts +0 -17
- package/lib/knex/src/utils/util.ts +0 -19
- package/lib/mikro-orm/Dockerfile +0 -24
- package/lib/mikro-orm/src/controllers/index.controller.ts +0 -13
- package/lib/mikro-orm/src/routes/index.route.ts +0 -19
- package/lib/mikro-orm/src/tests/index.test.ts +0 -18
- package/lib/mikro-orm/src/utils/util.ts +0 -19
- package/lib/mongoose/Dockerfile +0 -24
- package/lib/mongoose/src/controllers/index.controller.ts +0 -13
- package/lib/mongoose/src/databases/index.ts +0 -9
- package/lib/mongoose/src/routes/index.route.ts +0 -19
- package/lib/mongoose/src/utils/util.ts +0 -19
- package/lib/prisma/Dockerfile +0 -24
- package/lib/prisma/src/controllers/index.controller.ts +0 -13
- package/lib/prisma/src/routes/index.route.ts +0 -19
- package/lib/prisma/src/tests/index.test.ts +0 -18
- package/lib/prisma/src/utils/util.ts +0 -19
- package/lib/routing-controllers/Dockerfile +0 -24
- package/lib/routing-controllers/src/controllers/index.controller.ts +0 -9
- package/lib/routing-controllers/src/tests/index.test.ts +0 -17
- package/lib/routing-controllers/src/utils/util.ts +0 -19
- package/lib/sequelize/Dockerfile +0 -28
- package/lib/sequelize/src/controllers/index.controller.ts +0 -13
- package/lib/sequelize/src/routes/index.route.ts +0 -19
- package/lib/sequelize/src/tests/index.test.ts +0 -18
- package/lib/sequelize/src/utils/util.ts +0 -19
- package/lib/typegoose/Dockerfile +0 -24
- package/lib/typegoose/src/controllers/index.controller.ts +0 -13
- package/lib/typegoose/src/databases/index.ts +0 -3
- package/lib/typegoose/src/routes/index.route.ts +0 -19
- package/lib/typegoose/src/tests/index.test.ts +0 -18
- package/lib/typegoose/src/utils/util.ts +0 -19
- package/lib/typeorm/Dockerfile +0 -24
- package/lib/typeorm/src/controllers/index.controller.ts +0 -13
- package/lib/typeorm/src/databases/index.ts +0 -22
- package/lib/typeorm/src/routes/index.route.ts +0 -19
- package/lib/typeorm/src/tests/index.test.ts +0 -18
- package/lib/typeorm/src/utils/util.ts +0 -19
- package/lib/knex/src/{databases → database}/migrations/.gitkeep +0 -0
- package/lib/knex/src/{databases → database}/seeds/.gitkeep +0 -0
- package/lib/mikro-orm/src/{databases → database}/index.ts +0 -0
- package/lib/mongoose/src/{tests → test}/auth.test.ts +0 -0
- package/lib/{default/src/tests → mongoose/src/test}/index.test.ts +0 -0
- package/lib/prisma/src/{tests → test}/auth.test.ts +1 -1
- package/lib/{mongoose/src/tests → prisma/src/test}/index.test.ts +0 -0
- package/lib/prisma/src/{tests → test}/users.test.ts +1 -1
- /package/lib/sequelize/src/{migrations → database/migrations}/.gitkeep +0 -0
- /package/lib/sequelize/src/{seeders → database/seeders}/.gitkeep +0 -0
- /package/lib/typeorm/src/{migration → database/migrations}/.gitkeep +0 -0
|
@@ -1,25 +1,27 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
import { HttpException } from '@exceptions/
|
|
1
|
+
import { plainToInstance } from 'class-transformer';
|
|
2
|
+
import { validateOrReject, ValidationError } from 'class-validator';
|
|
3
|
+
import { NextFunction, Request, Response } from 'express';
|
|
4
|
+
import { HttpException } from '@exceptions/httpException';
|
|
5
5
|
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
6
|
+
/**
|
|
7
|
+
* @name ValidationMiddleware
|
|
8
|
+
* @description Allows use of decorator and non-decorator based validation
|
|
9
|
+
* @param type dto
|
|
10
|
+
* @param skipMissingProperties When skipping missing properties
|
|
11
|
+
* @param whitelist Even if your object is an instance of a validation class it can contain additional properties that are not defined
|
|
12
|
+
* @param forbidNonWhitelisted If you would rather to have an error thrown when any non-whitelisted properties are present
|
|
13
|
+
*/
|
|
14
|
+
export const ValidationMiddleware = (type: any, skipMissingProperties = false, whitelist = false, forbidNonWhitelisted = false) => {
|
|
15
|
+
return (req: Request, res: Response, next: NextFunction) => {
|
|
16
|
+
const dto = plainToInstance(type, req.body);
|
|
17
|
+
validateOrReject(dto, { skipMissingProperties, whitelist, forbidNonWhitelisted })
|
|
18
|
+
.then(() => {
|
|
19
|
+
req.body = dto;
|
|
20
|
+
next();
|
|
21
|
+
})
|
|
22
|
+
.catch((errors: ValidationError[]) => {
|
|
16
23
|
const message = errors.map((error: ValidationError) => Object.values(error.constraints)).join(', ');
|
|
17
24
|
next(new HttpException(400, message));
|
|
18
|
-
}
|
|
19
|
-
next();
|
|
20
|
-
}
|
|
21
|
-
});
|
|
25
|
+
});
|
|
22
26
|
};
|
|
23
27
|
};
|
|
24
|
-
|
|
25
|
-
export default validationMiddleware;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { Model, ModelObject } from 'objection';
|
|
2
2
|
import { User } from '@interfaces/users.interface';
|
|
3
3
|
|
|
4
|
-
export class
|
|
4
|
+
export class UserModel extends Model implements User {
|
|
5
5
|
id!: number;
|
|
6
6
|
email!: string;
|
|
7
7
|
password!: string;
|
|
@@ -10,4 +10,4 @@ export class Users extends Model implements User {
|
|
|
10
10
|
static idColumn = 'id'; // id column name
|
|
11
11
|
}
|
|
12
12
|
|
|
13
|
-
export type
|
|
13
|
+
export type UserShape = ModelObject<UserModel>;
|
|
@@ -1,24 +1,22 @@
|
|
|
1
1
|
import { Router } from 'express';
|
|
2
|
-
import AuthController from '
|
|
2
|
+
import { AuthController } from '@/controllers/auth.controller';
|
|
3
3
|
import { CreateUserDto } from '@dtos/users.dto';
|
|
4
4
|
import { Routes } from '@interfaces/routes.interface';
|
|
5
|
-
import
|
|
6
|
-
import
|
|
5
|
+
import { AuthMiddleware } from '@middlewares/auth.middleware';
|
|
6
|
+
import { ValidationMiddleware } from '@middlewares/validation.middleware';
|
|
7
7
|
|
|
8
|
-
class AuthRoute implements Routes {
|
|
8
|
+
export class AuthRoute implements Routes {
|
|
9
9
|
public path = '/';
|
|
10
10
|
public router = Router();
|
|
11
|
-
public
|
|
11
|
+
public auth = new AuthController();
|
|
12
12
|
|
|
13
13
|
constructor() {
|
|
14
14
|
this.initializeRoutes();
|
|
15
15
|
}
|
|
16
16
|
|
|
17
17
|
private initializeRoutes() {
|
|
18
|
-
this.router.post(`${this.path}signup`,
|
|
19
|
-
this.router.post(`${this.path}login`,
|
|
20
|
-
this.router.post(`${this.path}logout`,
|
|
18
|
+
this.router.post(`${this.path}signup`, ValidationMiddleware(CreateUserDto), this.auth.signUp);
|
|
19
|
+
this.router.post(`${this.path}login`, ValidationMiddleware(CreateUserDto), this.auth.logIn);
|
|
20
|
+
this.router.post(`${this.path}logout`, AuthMiddleware, this.auth.logOut);
|
|
21
21
|
}
|
|
22
22
|
}
|
|
23
|
-
|
|
24
|
-
export default AuthRoute;
|
|
@@ -1,25 +1,23 @@
|
|
|
1
1
|
import { Router } from 'express';
|
|
2
|
-
import
|
|
3
|
-
import { CreateUserDto } from '@dtos/users.dto';
|
|
2
|
+
import { UserController } from '@/controllers/users.controller';
|
|
3
|
+
import { CreateUserDto, UpdateUserDto } from '@dtos/users.dto';
|
|
4
4
|
import { Routes } from '@interfaces/routes.interface';
|
|
5
|
-
import
|
|
5
|
+
import { ValidationMiddleware } from '@middlewares/validation.middleware';
|
|
6
6
|
|
|
7
|
-
class
|
|
7
|
+
export class UserRoute implements Routes {
|
|
8
8
|
public path = '/users';
|
|
9
9
|
public router = Router();
|
|
10
|
-
public
|
|
10
|
+
public user = new UserController();
|
|
11
11
|
|
|
12
12
|
constructor() {
|
|
13
13
|
this.initializeRoutes();
|
|
14
14
|
}
|
|
15
15
|
|
|
16
16
|
private initializeRoutes() {
|
|
17
|
-
this.router.get(`${this.path}`, this.
|
|
18
|
-
this.router.get(`${this.path}/:id(\\d+)`, this.
|
|
19
|
-
this.router.post(`${this.path}`,
|
|
20
|
-
this.router.put(`${this.path}/:id(\\d+)`,
|
|
21
|
-
this.router.delete(`${this.path}/:id(\\d+)`, this.
|
|
17
|
+
this.router.get(`${this.path}`, this.user.getUsers);
|
|
18
|
+
this.router.get(`${this.path}/:id(\\d+)`, this.user.getUserById);
|
|
19
|
+
this.router.post(`${this.path}`, ValidationMiddleware(CreateUserDto), this.user.createUser);
|
|
20
|
+
this.router.put(`${this.path}/:id(\\d+)`, ValidationMiddleware(UpdateUserDto), this.user.updateUser);
|
|
21
|
+
this.router.delete(`${this.path}/:id(\\d+)`, this.user.deleteUser);
|
|
22
22
|
}
|
|
23
23
|
}
|
|
24
|
-
|
|
25
|
-
export default UsersRoute;
|
package/lib/knex/src/server.ts
CHANGED
|
@@ -1,11 +1,10 @@
|
|
|
1
|
-
import App from '@/app';
|
|
2
|
-
import AuthRoute from '@routes/auth.route';
|
|
3
|
-
import
|
|
4
|
-
import
|
|
5
|
-
import validateEnv from '@utils/validateEnv';
|
|
1
|
+
import { App } from '@/app';
|
|
2
|
+
import { AuthRoute } from '@routes/auth.route';
|
|
3
|
+
import { UserRoute } from '@routes/users.route';
|
|
4
|
+
import { ValidateEnv } from '@utils/validateEnv';
|
|
6
5
|
|
|
7
|
-
|
|
6
|
+
ValidateEnv();
|
|
8
7
|
|
|
9
|
-
const app = new App([new
|
|
8
|
+
const app = new App([new UserRoute(), new AuthRoute()]);
|
|
10
9
|
|
|
11
10
|
app.listen();
|
|
@@ -1,47 +1,52 @@
|
|
|
1
1
|
import { hash, compare } from 'bcrypt';
|
|
2
2
|
import { sign } from 'jsonwebtoken';
|
|
3
|
+
import { Service } from 'typedi';
|
|
3
4
|
import { SECRET_KEY } from '@config';
|
|
4
|
-
import {
|
|
5
|
-
import { HttpException } from '@exceptions/HttpException';
|
|
5
|
+
import { HttpException } from '@exceptions/httpException';
|
|
6
6
|
import { DataStoredInToken, TokenData } from '@interfaces/auth.interface';
|
|
7
7
|
import { User } from '@interfaces/users.interface';
|
|
8
|
-
import {
|
|
9
|
-
import { isEmpty } from '@utils/util';
|
|
8
|
+
import { UserModel } from '@models/users.model';
|
|
10
9
|
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
10
|
+
const createToken = (user: User): TokenData => {
|
|
11
|
+
const dataStoredInToken: DataStoredInToken = { id: user.id };
|
|
12
|
+
const expiresIn: number = 60 * 60;
|
|
14
13
|
|
|
15
|
-
|
|
14
|
+
return { expiresIn, token: sign(dataStoredInToken, SECRET_KEY, { expiresIn }) };
|
|
15
|
+
};
|
|
16
|
+
|
|
17
|
+
const createCookie = (tokenData: TokenData): string => {
|
|
18
|
+
return `Authorization=${tokenData.token}; HttpOnly; Max-Age=${tokenData.expiresIn};`;
|
|
19
|
+
};
|
|
20
|
+
|
|
21
|
+
@Service()
|
|
22
|
+
export class AuthService {
|
|
23
|
+
public async signup(userData: User): Promise<User> {
|
|
24
|
+
const findUser: User = await UserModel.query().select().from('users').where('email', '=', userData.email).first();
|
|
16
25
|
if (findUser) throw new HttpException(409, `This email ${userData.email} already exists`);
|
|
17
26
|
|
|
18
27
|
const hashedPassword = await hash(userData.password, 10);
|
|
19
|
-
const createUserData: User = await
|
|
28
|
+
const createUserData: User = await UserModel.query()
|
|
20
29
|
.insert({ ...userData, password: hashedPassword })
|
|
21
30
|
.into('users');
|
|
22
31
|
|
|
23
32
|
return createUserData;
|
|
24
33
|
}
|
|
25
34
|
|
|
26
|
-
public async login(userData:
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
const findUser: User = await Users.query().select().from('users').where('email', '=', userData.email).first();
|
|
35
|
+
public async login(userData: User): Promise<{ cookie: string; findUser: User }> {
|
|
36
|
+
const findUser: User = await UserModel.query().select().from('users').where('email', '=', userData.email).first();
|
|
30
37
|
if (!findUser) throw new HttpException(409, `This email ${userData.email} was not found`);
|
|
31
38
|
|
|
32
39
|
const isPasswordMatching: boolean = await compare(userData.password, findUser.password);
|
|
33
|
-
if (!isPasswordMatching) throw new HttpException(409,
|
|
40
|
+
if (!isPasswordMatching) throw new HttpException(409, 'Password is not matching');
|
|
34
41
|
|
|
35
|
-
const tokenData =
|
|
36
|
-
const cookie =
|
|
42
|
+
const tokenData = createToken(findUser);
|
|
43
|
+
const cookie = createCookie(tokenData);
|
|
37
44
|
|
|
38
45
|
return { cookie, findUser };
|
|
39
46
|
}
|
|
40
47
|
|
|
41
48
|
public async logout(userData: User): Promise<User> {
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
const findUser: User = await Users.query()
|
|
49
|
+
const findUser: User = await UserModel.query()
|
|
45
50
|
.select()
|
|
46
51
|
.from('users')
|
|
47
52
|
.where('email', '=', userData.email)
|
|
@@ -52,18 +57,4 @@ class AuthService {
|
|
|
52
57
|
|
|
53
58
|
return findUser;
|
|
54
59
|
}
|
|
55
|
-
|
|
56
|
-
public createToken(user: User): TokenData {
|
|
57
|
-
const dataStoredInToken: DataStoredInToken = { id: user.id };
|
|
58
|
-
const secretKey: string = SECRET_KEY;
|
|
59
|
-
const expiresIn: number = 60 * 60;
|
|
60
|
-
|
|
61
|
-
return { expiresIn, token: sign(dataStoredInToken, secretKey, { expiresIn }) };
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
public createCookie(tokenData: TokenData): string {
|
|
65
|
-
return `Authorization=${tokenData.token}; HttpOnly; Max-Age=${tokenData.expiresIn};`;
|
|
66
|
-
}
|
|
67
60
|
}
|
|
68
|
-
|
|
69
|
-
export default AuthService;
|
|
@@ -1,31 +1,30 @@
|
|
|
1
1
|
import { hash } from 'bcrypt';
|
|
2
|
+
import { Service } from 'typedi';
|
|
2
3
|
import { CreateUserDto } from '@dtos/users.dto';
|
|
3
|
-
import { HttpException } from '@exceptions/
|
|
4
|
+
import { HttpException } from '@exceptions/httpException';
|
|
4
5
|
import { User } from '@interfaces/users.interface';
|
|
5
|
-
import {
|
|
6
|
-
import { isEmpty } from '@utils/util';
|
|
6
|
+
import { UserModel } from '@models/users.model';
|
|
7
7
|
|
|
8
|
-
|
|
8
|
+
@Service()
|
|
9
|
+
export class UserService {
|
|
9
10
|
public async findAllUser(): Promise<User[]> {
|
|
10
|
-
const users: User[] = await
|
|
11
|
+
const users: User[] = await UserModel.query().select().from('users');
|
|
11
12
|
return users;
|
|
12
13
|
}
|
|
13
14
|
|
|
14
15
|
public async findUserById(userId: number): Promise<User> {
|
|
15
|
-
const findUser: User = await
|
|
16
|
+
const findUser: User = await UserModel.query().findById(userId);
|
|
16
17
|
if (!findUser) throw new HttpException(409, "User doesn't exist");
|
|
17
18
|
|
|
18
19
|
return findUser;
|
|
19
20
|
}
|
|
20
21
|
|
|
21
22
|
public async createUser(userData: CreateUserDto): Promise<User> {
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
const findUser: User = await Users.query().select().from('users').where('email', '=', userData.email).first();
|
|
23
|
+
const findUser: User = await UserModel.query().select().from('users').where('email', '=', userData.email).first();
|
|
25
24
|
if (findUser) throw new HttpException(409, `This email ${userData.email} already exists`);
|
|
26
25
|
|
|
27
26
|
const hashedPassword = await hash(userData.password, 10);
|
|
28
|
-
const createUserData: User = await
|
|
27
|
+
const createUserData: User = await UserModel.query()
|
|
29
28
|
.insert({ ...userData, password: hashedPassword })
|
|
30
29
|
.into('users');
|
|
31
30
|
|
|
@@ -33,28 +32,24 @@ class UserService {
|
|
|
33
32
|
}
|
|
34
33
|
|
|
35
34
|
public async updateUser(userId: number, userData: User): Promise<User> {
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
const findUser: User[] = await Users.query().select().from('users').where('id', '=', userId);
|
|
35
|
+
const findUser: User[] = await UserModel.query().select().from('users').where('id', '=', userId);
|
|
39
36
|
if (!findUser) throw new HttpException(409, "User doesn't exist");
|
|
40
37
|
|
|
41
38
|
const hashedPassword = await hash(userData.password, 10);
|
|
42
|
-
await
|
|
39
|
+
await UserModel.query()
|
|
43
40
|
.update({ ...userData, password: hashedPassword })
|
|
44
41
|
.where('id', '=', userId)
|
|
45
42
|
.into('users');
|
|
46
43
|
|
|
47
|
-
const updateUserData: User = await
|
|
44
|
+
const updateUserData: User = await UserModel.query().select().from('users').where('id', '=', userId).first();
|
|
48
45
|
return updateUserData;
|
|
49
46
|
}
|
|
50
47
|
|
|
51
48
|
public async deleteUser(userId: number): Promise<User> {
|
|
52
|
-
const findUser: User = await
|
|
49
|
+
const findUser: User = await UserModel.query().select().from('users').where('id', '=', userId).first();
|
|
53
50
|
if (!findUser) throw new HttpException(409, "User doesn't exist");
|
|
54
51
|
|
|
55
|
-
await
|
|
52
|
+
await UserModel.query().delete().where('id', '=', userId).into('users');
|
|
56
53
|
return findUser;
|
|
57
54
|
}
|
|
58
55
|
}
|
|
59
|
-
|
|
60
|
-
export default UserService;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import request from 'supertest';
|
|
2
|
-
import App from '@/app';
|
|
2
|
+
import { App } from '@/app';
|
|
3
3
|
import { CreateUserDto } from '@dtos/users.dto';
|
|
4
|
-
import AuthRoute from '@routes/auth.route';
|
|
4
|
+
import { AuthRoute } from '@routes/auth.route';
|
|
5
5
|
|
|
6
6
|
afterAll(async () => {
|
|
7
7
|
await new Promise<void>(resolve => setTimeout(() => resolve(), 500));
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import request from 'supertest';
|
|
2
|
-
import App from '@/app';
|
|
2
|
+
import { App } from '@/app';
|
|
3
3
|
import { CreateUserDto } from '@dtos/users.dto';
|
|
4
|
-
import UserRoute from '@routes/users.route';
|
|
4
|
+
import { UserRoute } from '@routes/users.route';
|
|
5
5
|
|
|
6
6
|
afterAll(async () => {
|
|
7
7
|
await new Promise<void>(resolve => setTimeout(() => resolve(), 500));
|
package/lib/knex/tsconfig.json
CHANGED
|
@@ -24,7 +24,7 @@
|
|
|
24
24
|
"@/*": ["*"],
|
|
25
25
|
"@config": ["config"],
|
|
26
26
|
"@controllers/*": ["controllers/*"],
|
|
27
|
-
"@
|
|
27
|
+
"@database": ["database"],
|
|
28
28
|
"@dtos/*": ["dtos/*"],
|
|
29
29
|
"@exceptions/*": ["exceptions/*"],
|
|
30
30
|
"@interfaces/*": ["interfaces/*"],
|
|
@@ -36,5 +36,5 @@
|
|
|
36
36
|
}
|
|
37
37
|
},
|
|
38
38
|
"include": ["src/**/*.ts", "src/**/*.json", ".env"],
|
|
39
|
-
"exclude": ["node_modules", "src/http", "src/logs"
|
|
39
|
+
"exclude": ["node_modules", "src/http", "src/logs"]
|
|
40
40
|
}
|
package/lib/mikro-orm/.swcrc
CHANGED
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
# NodeJS Version 16
|
|
2
|
+
FROM node:16.18-buster-slim
|
|
3
|
+
|
|
4
|
+
# Copy Dir
|
|
5
|
+
COPY . ./app
|
|
6
|
+
|
|
7
|
+
# Work to Dir
|
|
8
|
+
WORKDIR /app
|
|
9
|
+
|
|
10
|
+
# Install Node Package
|
|
11
|
+
RUN npm install --legacy-peer-deps
|
|
12
|
+
|
|
13
|
+
# Set Env
|
|
14
|
+
ENV NODE_ENV development
|
|
15
|
+
|
|
16
|
+
EXPOSE 3000
|
|
17
|
+
|
|
18
|
+
# Cmd script
|
|
19
|
+
CMD ["npm", "run", "dev"]
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
# NodeJS Version 16
|
|
2
|
+
FROM node:16.18-buster-slim
|
|
3
|
+
|
|
4
|
+
# Copy Dir
|
|
5
|
+
COPY . ./app
|
|
6
|
+
|
|
7
|
+
# Work to Dir
|
|
8
|
+
WORKDIR /app
|
|
9
|
+
|
|
10
|
+
# Install Node Package
|
|
11
|
+
RUN npm install --legacy-peer-deps
|
|
12
|
+
|
|
13
|
+
# Set Env
|
|
14
|
+
ENV NODE_ENV production
|
|
15
|
+
|
|
16
|
+
EXPOSE 3000
|
|
17
|
+
|
|
18
|
+
# Cmd script
|
|
19
|
+
CMD ["npm", "run", "start"]
|
package/lib/mikro-orm/Makefile
CHANGED
|
@@ -2,28 +2,45 @@
|
|
|
2
2
|
# ex) production-stage: make build APP_NAME=<APP_NAME>
|
|
3
3
|
# ex) development-stage: make build-dev APP_NAME=<APP_NAME>
|
|
4
4
|
|
|
5
|
+
SHELL := /bin/bash
|
|
6
|
+
|
|
5
7
|
APP_NAME = typescript-express
|
|
6
8
|
APP_NAME := $(APP_NAME)
|
|
7
9
|
|
|
8
|
-
.PHONY:
|
|
9
|
-
|
|
10
|
-
|
|
10
|
+
.PHONY: help start clean db test
|
|
11
|
+
|
|
12
|
+
help:
|
|
13
|
+
@grep -E '^[1-9a-zA-Z_-]+:.*?## .*$$|(^#--)' $(MAKEFILE_LIST) \
|
|
14
|
+
| awk 'BEGIN {FS = ":.*?## "}; {printf "\033[32m %-43s\033[0m %s\n", $$1, $$2}' \
|
|
15
|
+
| sed -e 's/\[32m #-- /[33m/'
|
|
16
|
+
|
|
17
|
+
#-- Docker
|
|
18
|
+
up: ## Up the container images
|
|
19
|
+
docker-compose up -d
|
|
20
|
+
|
|
21
|
+
down: ## Down the container images
|
|
22
|
+
docker-compose down
|
|
23
|
+
|
|
24
|
+
build: ## Build the container image - Production
|
|
11
25
|
docker build -t ${APP_NAME}\
|
|
12
|
-
|
|
13
|
-
-f Dockerfile .
|
|
26
|
+
-f Dockerfile.prod .
|
|
14
27
|
|
|
15
|
-
|
|
16
|
-
build:
|
|
28
|
+
build-dev: ## Build the container image - Development
|
|
17
29
|
docker build -t ${APP_NAME}\
|
|
18
|
-
|
|
19
|
-
-f Dockerfile .
|
|
30
|
+
-f Dockerfile.dev .
|
|
20
31
|
|
|
21
|
-
|
|
22
|
-
|
|
32
|
+
run: ## Run the container image
|
|
33
|
+
docker run -d -it -p 3000:3000 ${APP_NAME}
|
|
34
|
+
|
|
35
|
+
pause: ## Pause the containers
|
|
36
|
+
docker container rm -f ${APP_NAME}
|
|
37
|
+
|
|
38
|
+
clean: ## Clean the images
|
|
23
39
|
docker rmi -f ${APP_NAME}
|
|
24
40
|
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
docker run -d -it -p 3000:3000 ${APP_NAME}
|
|
41
|
+
remove: ## Remove the volumes
|
|
42
|
+
docker volume rm -f ${APP_NAME}
|
|
28
43
|
|
|
29
|
-
|
|
44
|
+
#-- Database
|
|
45
|
+
db: ## Start the local database MongoDB
|
|
46
|
+
docker-compose up -d mongo
|
|
@@ -1,39 +1,48 @@
|
|
|
1
|
-
version:
|
|
1
|
+
version: "3.9"
|
|
2
2
|
|
|
3
3
|
services:
|
|
4
4
|
proxy:
|
|
5
|
-
image: nginx:alpine
|
|
6
5
|
container_name: proxy
|
|
6
|
+
image: nginx:alpine
|
|
7
7
|
ports:
|
|
8
|
-
-
|
|
8
|
+
- "80:80"
|
|
9
9
|
volumes:
|
|
10
10
|
- ./nginx.conf:/etc/nginx/nginx.conf
|
|
11
|
-
restart:
|
|
11
|
+
restart: "unless-stopped"
|
|
12
12
|
networks:
|
|
13
13
|
- backend
|
|
14
|
+
|
|
14
15
|
server:
|
|
16
|
+
container_name: server
|
|
15
17
|
build:
|
|
16
18
|
context: ./
|
|
17
|
-
|
|
18
|
-
dockerfile: Dockerfile
|
|
19
|
-
container_name: server
|
|
19
|
+
dockerfile: Dockerfile.dev
|
|
20
20
|
ports:
|
|
21
|
-
-
|
|
21
|
+
- "3000:3000"
|
|
22
|
+
environment:
|
|
23
|
+
DB_HOST: localhost
|
|
24
|
+
DB_PORT: 27017
|
|
25
|
+
DB_DATABASE: dev
|
|
22
26
|
volumes:
|
|
23
27
|
- ./:/app
|
|
24
28
|
- /app/node_modules
|
|
25
|
-
restart:
|
|
29
|
+
restart: "unless-stopped"
|
|
26
30
|
networks:
|
|
27
31
|
- backend
|
|
28
32
|
links:
|
|
29
33
|
- mongo
|
|
30
34
|
depends_on:
|
|
31
35
|
- mongo
|
|
36
|
+
|
|
32
37
|
mongo:
|
|
33
|
-
image: mvertes/alpine-mongo
|
|
34
38
|
container_name: mongo
|
|
39
|
+
image: mongo
|
|
35
40
|
ports:
|
|
36
|
-
-
|
|
41
|
+
- "27017:27017"
|
|
42
|
+
environment:
|
|
43
|
+
DB_HOST: localhost
|
|
44
|
+
DB_PORT: 27017
|
|
45
|
+
DB_DATABASE: dev
|
|
37
46
|
networks:
|
|
38
47
|
- backend
|
|
39
48
|
|
|
@@ -31,8 +31,10 @@
|
|
|
31
31
|
"hpp": "^0.2.3",
|
|
32
32
|
"jsonwebtoken": "^8.5.1",
|
|
33
33
|
"morgan": "^1.10.0",
|
|
34
|
+
"reflect-metadata": "^0.1.13",
|
|
34
35
|
"swagger-jsdoc": "^6.2.1",
|
|
35
36
|
"swagger-ui-express": "^4.5.0",
|
|
37
|
+
"typedi": "^0.10.0",
|
|
36
38
|
"winston": "^3.8.1",
|
|
37
39
|
"winston-daily-rotate-file": "^4.7.1"
|
|
38
40
|
},
|
package/lib/mikro-orm/src/app.ts
CHANGED
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
import 'reflect-metadata';
|
|
2
|
+
import { MikroORM, RequestContext } from '@mikro-orm/core';
|
|
1
3
|
import express from 'express';
|
|
2
4
|
import cookieParser from 'cookie-parser';
|
|
3
5
|
import compression from 'compression';
|
|
@@ -7,27 +9,25 @@ import hpp from 'hpp';
|
|
|
7
9
|
import morgan from 'morgan';
|
|
8
10
|
import swaggerJSDoc from 'swagger-jsdoc';
|
|
9
11
|
import swaggerUi from 'swagger-ui-express';
|
|
10
|
-
import { logger, stream } from '@utils/logger';
|
|
11
|
-
import { MikroORM, RequestContext } from '@mikro-orm/core';
|
|
12
12
|
import { NODE_ENV, PORT, LOG_FORMAT, ORIGIN, CREDENTIALS } from '@config';
|
|
13
|
-
import { DI, dbOptions } from '@
|
|
13
|
+
import { DI, dbOptions } from '@database';
|
|
14
14
|
import { UserEntity } from '@entities/users.entity';
|
|
15
15
|
import { Routes } from '@interfaces/routes.interface';
|
|
16
|
-
import
|
|
16
|
+
import { ErrorMiddleware } from '@middlewares/error.middleware';
|
|
17
|
+
import { logger, stream } from '@utils/logger';
|
|
17
18
|
|
|
18
|
-
class App {
|
|
19
|
+
export class App {
|
|
19
20
|
public app: express.Application;
|
|
20
21
|
public env: string;
|
|
21
22
|
public port: string | number;
|
|
22
|
-
public host: string;
|
|
23
23
|
|
|
24
24
|
constructor(routes: Routes[]) {
|
|
25
25
|
this.app = express();
|
|
26
26
|
this.env = NODE_ENV || 'development';
|
|
27
27
|
this.port = PORT || 3000;
|
|
28
28
|
|
|
29
|
-
this.initializeMiddlewares();
|
|
30
29
|
this.connectToDatabase();
|
|
30
|
+
this.initializeMiddlewares();
|
|
31
31
|
this.initializeRoutes(routes);
|
|
32
32
|
this.initializeSwagger();
|
|
33
33
|
this.initializeErrorHandling();
|
|
@@ -49,12 +49,13 @@ class App {
|
|
|
49
49
|
private async connectToDatabase() {
|
|
50
50
|
try {
|
|
51
51
|
DI.orm = await MikroORM.init(dbOptions);
|
|
52
|
-
DI.em = DI.orm.em
|
|
53
|
-
DI.userRepository = DI.orm.em.
|
|
52
|
+
DI.em = DI.orm.em;
|
|
53
|
+
DI.userRepository = DI.orm.em.getRepository(UserEntity);
|
|
54
54
|
} catch (error) {
|
|
55
55
|
logger.error(error);
|
|
56
|
+
} finally {
|
|
57
|
+
this.app.use((_1, _2, next) => RequestContext.create(DI.orm.em, next));
|
|
56
58
|
}
|
|
57
|
-
this.app.use((_1, _2, next) => RequestContext.create(DI.orm.em, next));
|
|
58
59
|
}
|
|
59
60
|
|
|
60
61
|
private initializeMiddlewares() {
|
|
@@ -91,8 +92,6 @@ class App {
|
|
|
91
92
|
}
|
|
92
93
|
|
|
93
94
|
private initializeErrorHandling() {
|
|
94
|
-
this.app.use(
|
|
95
|
+
this.app.use(ErrorMiddleware);
|
|
95
96
|
}
|
|
96
97
|
}
|
|
97
|
-
|
|
98
|
-
export default App;
|
|
@@ -2,4 +2,5 @@ import { config } from 'dotenv';
|
|
|
2
2
|
config({ path: `.env.${process.env.NODE_ENV || 'development'}.local` });
|
|
3
3
|
|
|
4
4
|
export const CREDENTIALS = process.env.CREDENTIALS === 'true';
|
|
5
|
-
export const { NODE_ENV, PORT,
|
|
5
|
+
export const { NODE_ENV, PORT, SECRET_KEY, LOG_FORMAT, LOG_DIR, ORIGIN } = process.env;
|
|
6
|
+
export const { DB_HOST, DB_PORT, DB_DATABASE } = process.env;
|