@asapjs/core 0.0.6 → 0.0.9

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.
@@ -1,11 +1,8 @@
1
- import express from 'express';
2
1
  export default class Application {
3
- app: express.Application;
4
2
  private config;
3
+ private app;
5
4
  constructor(dirname: string, projectConfig: any);
6
- private initRouter;
7
- private initMiddlewares;
8
5
  private initMoudles;
9
- run: (port: number) => void;
6
+ run: () => Promise<void>;
10
7
  }
11
8
  //# sourceMappingURL=application.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"application.d.ts","sourceRoot":"","sources":["../src/application.ts"],"names":[],"mappings":"AAEA,OAAO,OAAO,MAAM,SAAS,CAAC;AAQ9B,MAAM,CAAC,OAAO,OAAO,WAAW;IACvB,GAAG,EAAE,OAAO,CAAC,WAAW,CAAC;IAEhC,OAAO,CAAC,MAAM,CAAM;gBAER,OAAO,EAAE,MAAM,EAAE,aAAa,EAAE,GAAG;IAU/C,OAAO,CAAC,UAAU;IAmBlB,OAAO,CAAC,eAAe;IAMvB,OAAO,CAAC,WAAW,CAIjB;IAEK,GAAG,SAAU,MAAM,UAIxB;CACH"}
1
+ {"version":3,"file":"application.d.ts","sourceRoot":"","sources":["../src/application.ts"],"names":[],"mappings":"AAQA,MAAM,CAAC,OAAO,OAAO,WAAW;IAC9B,OAAO,CAAC,MAAM,CAAM;IAEpB,OAAO,CAAC,GAAG,CAAsB;gBAErB,OAAO,EAAE,MAAM,EAAE,aAAa,EAAE,GAAG;IAK/C,OAAO,CAAC,WAAW,CASjB;IAEK,GAAG,sBAKR;CACH"}
@@ -13,54 +13,28 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
13
13
  };
14
14
  Object.defineProperty(exports, "__esModule", { value: true });
15
15
  const sequelize_1 = require("@asapjs/sequelize");
16
- const express_1 = __importDefault(require("express"));
17
- const body_parser_1 = __importDefault(require("body-parser"));
18
- const cors_1 = __importDefault(require("cors"));
19
- const errorHandler_1 = __importDefault(require("./middleware/errorHandler"));
16
+ const router_1 = require("@asapjs/router");
20
17
  const logger_1 = __importDefault(require("./util/logger"));
21
18
  const config_1 = require("./config");
22
19
  class Application {
23
20
  constructor(dirname, projectConfig) {
24
21
  this.initMoudles = (dirname) => __awaiter(this, void 0, void 0, function* () {
22
+ // init @asapjs/router module
23
+ const { app } = new router_1.RouterModule(dirname);
24
+ this.app = app;
25
+ // init @asapjs/sequelize module
25
26
  if (this.config.extensions.includes('@asapjs/sequelize')) {
26
27
  yield (0, sequelize_1.initSequelizeModule)(dirname);
27
28
  }
28
29
  });
29
- this.run = (port) => {
30
+ this.run = () => __awaiter(this, void 0, void 0, function* () {
31
+ yield this.initMoudles(this.config.dirname);
30
32
  this.app
31
- .listen(port, () => logger_1.default.info(`@express :: Server is listening at ${port}`))
33
+ .listen(this.config.port, () => logger_1.default.info(`@express :: Server is listening at ${this.config.port}`))
32
34
  .on('error', (error) => logger_1.default.error(error));
33
- };
34
- (0, config_1.setConfig)(projectConfig);
35
- this.config = projectConfig;
36
- this.app = (0, express_1.default)();
37
- this.initMiddlewares();
38
- this.initRouter(dirname);
39
- this.app.use(errorHandler_1.default);
40
- this.initMoudles(dirname);
41
- }
42
- initRouter(dirname) {
43
- const router = express_1.default.Router();
44
- const routes = require(`${dirname}/route`).default;
45
- routes.forEach((route) => {
46
- this.app.use(`/shop${route.basePath}`, route.expressRouter || route.router);
47
- });
48
- this.app.use(router);
49
- this.app.get('/shop', (req, res) => {
50
- res.send('pangaia-b4c-ms-shop server is working');
51
35
  });
52
- this.app.get('/health-check', (req, res) => {
53
- res.send('pangaia-b4c-ms-shop server is working');
54
- });
55
- // this.app.get('/sync', async (req: any, res: any) => {
56
- // const result = await modelsSync();
57
- // res.send(result);
58
- // });
59
- }
60
- initMiddlewares() {
61
- this.app.use((0, cors_1.default)());
62
- this.app.use(body_parser_1.default.json());
63
- this.app.use(body_parser_1.default.urlencoded({ extended: true }));
36
+ (0, config_1.setConfig)(projectConfig);
37
+ this.config = Object.assign({ dirname }, projectConfig);
64
38
  }
65
39
  }
66
40
  exports.default = Application;
@@ -1 +1 @@
1
- {"version":3,"file":"application.js","sourceRoot":"","sources":["../src/application.ts"],"names":[],"mappings":";;;;;;;;;;;;;;AAAA,iDAAwD;AAExD,sDAA8B;AAC9B,8DAAqC;AACrC,gDAAwB;AAExB,6EAAqD;AACrD,2DAAmC;AACnC,qCAAqC;AAErC,MAAqB,WAAW;IAK9B,YAAY,OAAe,EAAE,aAAkB;QAmCvC,gBAAW,GAAG,CAAO,OAAe,EAAE,EAAE;YAC9C,IAAI,IAAI,CAAC,MAAM,CAAC,UAAU,CAAC,QAAQ,CAAC,mBAAmB,CAAC,EAAE;gBACxD,MAAM,IAAA,+BAAmB,EAAC,OAAO,CAAC,CAAC;aACpC;QACH,CAAC,CAAA,CAAC;QAEK,QAAG,GAAG,CAAC,IAAY,EAAE,EAAE;YAC5B,IAAI,CAAC,GAAG;iBACL,MAAM,CAAC,IAAI,EAAE,GAAG,EAAE,CAAC,gBAAM,CAAC,IAAI,CAAC,sCAAsC,IAAI,EAAE,CAAC,CAAC;iBAC7E,EAAE,CAAC,OAAO,EAAE,CAAC,KAAa,EAAE,EAAE,CAAC,gBAAM,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC,CAAC;QACzD,CAAC,CAAC;QA5CA,IAAA,kBAAS,EAAC,aAAa,CAAC,CAAC;QACzB,IAAI,CAAC,MAAM,GAAG,aAAa,CAAC;QAC5B,IAAI,CAAC,GAAG,GAAG,IAAA,iBAAO,GAAE,CAAC;QACrB,IAAI,CAAC,eAAe,EAAE,CAAC;QACvB,IAAI,CAAC,UAAU,CAAC,OAAO,CAAC,CAAC;QACzB,IAAI,CAAC,GAAG,CAAC,GAAG,CAAC,sBAAY,CAAC,CAAC;QAC3B,IAAI,CAAC,WAAW,CAAC,OAAO,CAAC,CAAC;IAC5B,CAAC;IAEO,UAAU,CAAC,OAAe;QAChC,MAAM,MAAM,GAAmB,iBAAO,C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ErC,MAAqB,WAAW;IAK9B,YAAY,OAAe,EAAE,aAAkB;QAKvC,gBAAW,GAAG,CAAO,OAAe,EAAE,EAAE;YAC9C,6BAA6B;YAC7B,MAAM,EAAE,GAAG,EAAE,GAAG,IAAI,qBAAY,CAAC,OAAO,CAAC,CAAC;YAC1C,IAAI,CAAC,GAAG,GAAG,GAAG,CAAC;YAEf,gCAAgC;YAChC,IAAI,IAAI,CAAC,MAAM,CAAC,UAAU,CAAC,QAAQ,CAAC,mBAAmB,CAAC,EAAE;gBACxD,MAAM,IAAA,+BAAmB,EAAC,OAAO,CAAC,CAAC;aACpC;QACH,CAAC,CAAA,CAAC;QAEK,QAAG,GAAG,GAAS,EAAE;YACtB,MAAM,IAAI,CAAC,WAAW,CAAC,IAAI,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC;YAC5C,IAAI,CAAC,GAAG;iBACL,MAAM,CAAC,IAAI,CAAC,MAAM,CAAC,IAAI,EAAE,GAAG,EAAE,CAAC,gBAAM,CAAC,IAAI,CAAC,sCAAsC,IAAI,CAAC,MAAM,CAAC,IAAI,EAAE,CAAC,CAAC;iBACrG,EAAE,CAAC,OAAO,EAAE,CAAC,KAAa,EAAE,EAAE,CAAC,gBAAM,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC,CAAC;QACzD,CAAC,CAAA,CAAC;QApBA,IAAA,kBAAS,EAAC,aAAa,CAAC,CAAC;QACzB,IAAI,CAAC,MAAM,mBAAK,OAAO,IAAK,aAAa,CAAE,CAAC;IAC9C,CAAC;CAmBF;AA3BD,8BA2BC"}
@@ -1,4 +1,38 @@
1
+ interface IConfig {
2
+ dirname: string;
3
+ debug: boolean;
4
+ name: string;
5
+ extensions: string[];
6
+ port: number;
7
+ swagger: {
8
+ name: string;
9
+ version: string;
10
+ description: string;
11
+ scheme: 'http' | 'https';
12
+ host: string;
13
+ };
14
+ auth: {
15
+ jwt_secret: string;
16
+ };
17
+ db: {
18
+ database: string;
19
+ username: string;
20
+ password?: string;
21
+ host: string;
22
+ port: number;
23
+ dialect: string;
24
+ logging?: (query: string, time: number) => void;
25
+ timezone?: string;
26
+ pool?: {
27
+ max: number;
28
+ idle: number;
29
+ acquire: number;
30
+ };
31
+ };
32
+ extra: any;
33
+ }
1
34
  export declare let config: null;
2
- export declare const getConfig: () => null;
35
+ export declare const getConfig: () => IConfig | null;
3
36
  export declare const setConfig: (v: any) => void;
37
+ export {};
4
38
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/config/index.ts"],"names":[],"mappings":"AAAA,eAAO,IAAI,MAAM,MAAO,CAAC;AAEzB,eAAO,MAAM,SAAS,YAAe,CAAC;AAEtC,eAAO,MAAM,SAAS,MAAO,GAAG,SAE/B,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/config/index.ts"],"names":[],"mappings":"AAAA,UAAU,OAAO;IACf,OAAO,EAAE,MAAM,CAAC;IAChB,KAAK,EAAE,OAAO,CAAC;IACf,IAAI,EAAE,MAAM,CAAC;IACb,UAAU,EAAE,MAAM,EAAE,CAAC;IACrB,IAAI,EAAE,MAAM,CAAC;IACb,OAAO,EAAE;QACP,IAAI,EAAE,MAAM,CAAC;QACb,OAAO,EAAE,MAAM,CAAC;QAChB,WAAW,EAAE,MAAM,CAAC;QACpB,MAAM,EAAE,MAAM,GAAG,OAAO,CAAC;QACzB,IAAI,EAAE,MAAM,CAAC;KACd,CAAC;IACF,IAAI,EAAE;QACJ,UAAU,EAAE,MAAM,CAAC;KACpB,CAAC;IACF,EAAE,EAAE;QACF,QAAQ,EAAE,MAAM,CAAC;QACjB,QAAQ,EAAE,MAAM,CAAC;QACjB,QAAQ,CAAC,EAAE,MAAM,CAAC;QAClB,IAAI,EAAE,MAAM,CAAC;QACb,IAAI,EAAE,MAAM,CAAC;QACb,OAAO,EAAE,MAAM,CAAC;QAChB,OAAO,CAAC,EAAE,CAAC,KAAK,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,KAAK,IAAI,CAAC;QAChD,QAAQ,CAAC,EAAE,MAAM,CAAC;QAClB,IAAI,CAAC,EAAE;YACL,GAAG,EAAE,MAAM,CAAC;YACZ,IAAI,EAAE,MAAM,CAAC;YACb,OAAO,EAAE,MAAM,CAAC;SACjB,CAAC;KACH,CAAC;IACF,KAAK,EAAE,GAAG,CAAC;CACZ;AAED,eAAO,IAAI,MAAM,MAAO,CAAC;AAEzB,eAAO,MAAM,SAAS,EAAE,MAAM,OAAO,GAAG,IAAmB,CAAC;AAE5D,eAAO,MAAM,SAAS,MAAO,GAAG,SAE/B,CAAC"}
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/config/index.ts"],"names":[],"mappings":";;;AAAW,QAAA,MAAM,GAAG,IAAI,CAAC;AAElB,MAAM,SAAS,GAAG,GAAG,EAAE,CAAC,cAAM,CAAC;AAAzB,QAAA,SAAS,aAAgB;AAE/B,MAAM,SAAS,GAAG,CAAC,CAAM,EAAE,EAAE;IAClC,cAAM,GAAG,CAAC,CAAC;AACb,CAAC,CAAC;AAFW,QAAA,SAAS,aAEpB"}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/config/index.ts"],"names":[],"mappings":";;;AAkCW,QAAA,MAAM,GAAG,IAAI,CAAC;AAElB,MAAM,SAAS,GAAyB,GAAG,EAAE,CAAC,cAAM,CAAC;AAA/C,QAAA,SAAS,aAAsC;AAErD,MAAM,SAAS,GAAG,CAAC,CAAM,EAAE,EAAE;IAClC,cAAM,GAAG,CAAC,CAAC;AACb,CAAC,CAAC;AAFW,QAAA,SAAS,aAEpB"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@asapjs/core",
3
- "version": "0.0.6",
3
+ "version": "0.0.9",
4
4
  "description": "",
5
5
  "main": "dist/index.js",
6
6
  "scripts": {
@@ -19,6 +19,7 @@
19
19
  "winston": "^3.6.0"
20
20
  },
21
21
  "devDependencies": {
22
+ "@asapjs/router": "0.0.2",
22
23
  "@asapjs/sequelize": "^0.0.2",
23
24
  "@types/body-parser": "^1.19.2",
24
25
  "@types/cors": "^2.8.12",
package/.prettierrc DELETED
@@ -1,8 +0,0 @@
1
- {
2
- "singleQuote": true,
3
- "semi": true,
4
- "useTabs": false,
5
- "tabWidth": 2,
6
- "trailingComma": "all",
7
- "printWidth": 120
8
- }
@@ -1,9 +0,0 @@
1
- import { NextFunction, Request, Response } from 'express';
2
- export declare class HttpException extends Error {
3
- status: number;
4
- message: string;
5
- constructor(status?: number, message?: string);
6
- }
7
- declare const errorHandler: (error: HttpException, req: Request, res: Response, next: NextFunction) => void;
8
- export default errorHandler;
9
- //# sourceMappingURL=errorHandler.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"errorHandler.d.ts","sourceRoot":"","sources":["../../src/middleware/errorHandler.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,OAAO,EAAE,QAAQ,EAAE,MAAM,SAAS,CAAC;AAE1D,qBAAa,aAAc,SAAQ,KAAK;IAC/B,MAAM,EAAE,MAAM,CAAC;IAEf,OAAO,EAAE,MAAM,CAAC;gBAEX,MAAM,GAAE,MAAY,EAAE,OAAO,GAAE,MAAgC;CAK5E;AAED,QAAA,MAAM,YAAY,UAAW,aAAa,OAAO,OAAO,OAAO,QAAQ,QAAQ,YAAY,SAG1F,CAAC;AAEF,eAAe,YAAY,CAAC"}
@@ -1,17 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.HttpException = void 0;
4
- class HttpException extends Error {
5
- constructor(status = 500, message = '알 수 없는 서버 오류가 발생했습니다.') {
6
- super(message);
7
- this.status = status;
8
- this.message = message;
9
- }
10
- }
11
- exports.HttpException = HttpException;
12
- const errorHandler = (error, req, res, next) => {
13
- const { status = 500, message } = error;
14
- res.status(status).json({ status, message });
15
- };
16
- exports.default = errorHandler;
17
- //# sourceMappingURL=errorHandler.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"errorHandler.js","sourceRoot":"","sources":["../../src/middleware/errorHandler.ts"],"names":[],"mappings":";;;AAEA,MAAa,aAAc,SAAQ,KAAK;IAKtC,YAAY,SAAiB,GAAG,EAAE,UAAkB,uBAAuB;QACzE,KAAK,CAAC,OAAO,CAAC,CAAC;QACf,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC;QACrB,IAAI,CAAC,OAAO,GAAG,OAAO,CAAC;IACzB,CAAC;CACF;AAVD,sCAUC;AAED,MAAM,YAAY,GAAG,CAAC,KAAoB,EAAE,GAAY,EAAE,GAAa,EAAE,IAAkB,EAAE,EAAE;IAC7F,MAAM,EAAE,MAAM,GAAG,GAAG,EAAE,OAAO,EAAE,GAAG,KAAK,CAAC;IACxC,GAAG,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC,IAAI,CAAC,EAAE,MAAM,EAAE,OAAO,EAAE,CAAC,CAAC;AAC/C,CAAC,CAAC;AAEF,kBAAe,YAAY,CAAC"}
@@ -1,8 +0,0 @@
1
- import { Sequelize, SequelizeOptions } from 'sequelize-typescript';
2
- import 'reflect-metadata';
3
- export declare const dbInit: (config: SequelizeOptions) => Promise<Sequelize>;
4
- export declare const loadPath: (path: string, subPath: string) => Promise<void>;
5
- export declare const addModelsToSequelize: () => Promise<void>;
6
- export declare const modelsSync: () => Promise<boolean>;
7
- export declare const getSequelize: () => Sequelize;
8
- //# sourceMappingURL=index.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/sequelize/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAoB,SAAS,EAAE,gBAAgB,EAAE,MAAM,sBAAsB,CAAC;AAKrF,OAAO,kBAAkB,CAAC;AAQ1B,eAAO,MAAM,MAAM,WAAkB,gBAAgB,uBAepD,CAAC;AAEF,eAAO,MAAM,QAAQ,SAAgB,MAAM,WAAW,MAAM,kBAY3D,CAAC;AAEF,eAAO,MAAM,oBAAoB,qBAGhC,CAAC;AAEF,eAAO,MAAM,UAAU,wBAItB,CAAC;AAEF,eAAO,MAAM,YAAY,iBAAmB,CAAC"}
@@ -1,67 +0,0 @@
1
- "use strict";
2
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
- return new (P || (P = Promise))(function (resolve, reject) {
5
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
- step((generator = generator.apply(thisArg, _arguments || [])).next());
9
- });
10
- };
11
- var __importDefault = (this && this.__importDefault) || function (mod) {
12
- return (mod && mod.__esModule) ? mod : { "default": mod };
13
- };
14
- Object.defineProperty(exports, "__esModule", { value: true });
15
- exports.getSequelize = exports.modelsSync = exports.addModelsToSequelize = exports.loadPath = exports.dbInit = void 0;
16
- const sequelize_typescript_1 = require("sequelize-typescript");
17
- const fs_1 = __importDefault(require("fs"));
18
- const logger_1 = __importDefault(require("../util/logger"));
19
- require("reflect-metadata");
20
- let container = null;
21
- const models = [];
22
- const dtos = [];
23
- const dbInit = (config) => __awaiter(void 0, void 0, void 0, function* () {
24
- const sequelize = new sequelize_typescript_1.Sequelize(config);
25
- container = sequelize;
26
- sequelize
27
- .authenticate()
28
- .then(() => {
29
- logger_1.default.info('@sequelize :: Database connected.');
30
- })
31
- .catch((err) => {
32
- logger_1.default.error('@sequelize :: Unable to connect to the database:\n', err);
33
- });
34
- logger_1.default.info('@sequelize :: database initalize.');
35
- return sequelize;
36
- });
37
- exports.dbInit = dbInit;
38
- const loadPath = (path, subPath) => __awaiter(void 0, void 0, void 0, function* () {
39
- const files = yield fs_1.default.readdirSync(path + subPath, { withFileTypes: true });
40
- const extension = process.env.NODE_ENV === 'production' ? 'js' : 'ts';
41
- for (const file of files) {
42
- if (file.isDirectory()) {
43
- yield (0, exports.loadPath)(path, `${subPath}/${file.name}`);
44
- }
45
- else if (file.name.includes(`Table.${extension}`) && file.name.endsWith('map') === false) {
46
- models.push(require(`${path}/${subPath}/${file.name}`).default);
47
- }
48
- else if (file.name.includes(`Dto.${extension}`) && file.name.endsWith('map') === false) {
49
- dtos.push(require(`${path}/${subPath}/${file.name}`).default);
50
- }
51
- }
52
- });
53
- exports.loadPath = loadPath;
54
- const addModelsToSequelize = () => __awaiter(void 0, void 0, void 0, function* () {
55
- container.addModels(models);
56
- logger_1.default.info('@sequelize :: add models to sequelize instance.');
57
- });
58
- exports.addModelsToSequelize = addModelsToSequelize;
59
- const modelsSync = () => __awaiter(void 0, void 0, void 0, function* () {
60
- yield container.sync({ alter: { drop: false } });
61
- logger_1.default.info('@sequelize :: models sync finished');
62
- return true;
63
- });
64
- exports.modelsSync = modelsSync;
65
- const getSequelize = () => container;
66
- exports.getSequelize = getSequelize;
67
- //# sourceMappingURL=index.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/sequelize/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;AAAA,+DAAqF;AACrF,4CAAoB;AAEpB,4DAAoC;AAEpC,4BAA0B;AAE1B,IAAI,SAAS,GAAqB,IAAI,CAAC;AAEvC,MAAM,MAAM,GAAiC,EAAE,CAAC;AAEhD,MAAM,IAAI,GAAU,EAAE,CAAC;AAEhB,MAAM,MAAM,GAAG,CAAO,MAAwB,EAAE,EAAE;IACvD,MAAM,SAAS,GAAG,IAAI,gCAAS,CAAC,MAAM,CAAC,CAAC;IACxC,SAAS,GAAG,SAAS,CAAC;IACtB,SAAS;SACN,YAAY,EAAE;SACd,IAAI,CAAC,GAAG,EAAE;QACT,gBAAM,CAAC,IAAI,CAAC,mCAAmC,CAAC,CAAC;IACnD,CAAC,CAAC;SACD,KAAK,CAAC,CAAC,GAAG,EAAE,EAAE;QACb,gBAAM,CAAC,KAAK,CAAC,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AC/D;KACF;AACH,CAAC,CAAA,CAAC;AAZW,QAAA,QAAQ,YAYnB;AAEK,MAAM,oBAAoB,GAAG,GAAS,EAAE;IAC7C,SAAU,CAAC,SAAS,CAAC,MAAM,CAAC,CAAC;IAC7B,gBAAM,CAAC,IAAI,CAAC,iDAAiD,CAAC,CAAC;AACjE,CAAC,CAAA,CAAC;AAHW,QAAA,oBAAoB,wBAG/B;AAEK,MAAM,UAAU,GAAG,GAAS,EAAE;IACnC,MAAM,SAAU,CAAC,IAAI,CAAC,EAAE,KAAK,EAAE,EAAE,IAAI,EAAE,KAAK,EAAE,EAAE,CAAC,CAAC;IAClD,gBAAM,CAAC,IAAI,CAAC,oCAAoC,CAAC,CAAC;IAClD,OAAO,IAAI,CAAC;AACd,CAAC,CAAA,CAAC;AAJW,QAAA,UAAU,cAIrB;AAEK,MAAM,YAAY,GAAG,GAAG,EAAE,CAAC,SAAU,CAAC;AAAhC,QAAA,YAAY,gBAAoB"}
@@ -1,62 +0,0 @@
1
- import { initSequelizeModule } from '@asapjs/sequelize';
2
-
3
- import express from 'express';
4
- import bodyParser from 'body-parser';
5
- import cors from 'cors';
6
-
7
- import errorHandler from './middleware/errorHandler';
8
- import logger from './util/logger';
9
- import { setConfig } from './config';
10
-
11
- export default class Application {
12
- public app: express.Application;
13
-
14
- private config: any;
15
-
16
- constructor(dirname: string, projectConfig: any) {
17
- setConfig(projectConfig);
18
- this.config = projectConfig;
19
- this.app = express();
20
- this.initMiddlewares();
21
- this.initRouter(dirname);
22
- this.app.use(errorHandler);
23
- this.initMoudles(dirname);
24
- }
25
-
26
- private initRouter(dirname: string) {
27
- const router: express.Router = express.Router();
28
- const routes = require(`${dirname}/route`).default;
29
- routes.forEach((route: any) => {
30
- this.app.use(`/shop${route.basePath}`, route.expressRouter || route.router);
31
- });
32
- this.app.use(router);
33
- this.app.get('/shop', (req: any, res: any) => {
34
- res.send('pangaia-b4c-ms-shop server is working');
35
- });
36
- this.app.get('/health-check', (req: any, res: any) => {
37
- res.send('pangaia-b4c-ms-shop server is working');
38
- });
39
- // this.app.get('/sync', async (req: any, res: any) => {
40
- // const result = await modelsSync();
41
- // res.send(result);
42
- // });
43
- }
44
-
45
- private initMiddlewares() {
46
- this.app.use(cors());
47
- this.app.use(bodyParser.json());
48
- this.app.use(bodyParser.urlencoded({ extended: true }));
49
- }
50
-
51
- private initMoudles = async (dirname: string) => {
52
- if (this.config.extensions.includes('@asapjs/sequelize')) {
53
- await initSequelizeModule(dirname);
54
- }
55
- };
56
-
57
- public run = (port: number) => {
58
- this.app
59
- .listen(port, () => logger.info(`@express :: Server is listening at ${port}`))
60
- .on('error', (error: string) => logger.error(error));
61
- };
62
- }
@@ -1,7 +0,0 @@
1
- export let config = null;
2
-
3
- export const getConfig = () => config;
4
-
5
- export const setConfig = (v: any) => {
6
- config = v;
7
- };
package/src/index.ts DELETED
@@ -1,3 +0,0 @@
1
- export { default as Application } from './application';
2
- export { getConfig } from './config';
3
- export { default as logger } from './util/logger';
@@ -1,20 +0,0 @@
1
- import { NextFunction, Request, Response } from 'express';
2
-
3
- export class HttpException extends Error {
4
- public status: number;
5
-
6
- public message: string;
7
-
8
- constructor(status: number = 500, message: string = '알 수 없는 서버 오류가 발생했습니다.') {
9
- super(message);
10
- this.status = status;
11
- this.message = message;
12
- }
13
- }
14
-
15
- const errorHandler = (error: HttpException, req: Request, res: Response, next: NextFunction) => {
16
- const { status = 500, message } = error;
17
- res.status(status).json({ status, message });
18
- };
19
-
20
- export default errorHandler;
@@ -1,25 +0,0 @@
1
- import { createLogger, transports, format } from 'winston';
2
-
3
- interface TransformableInfo {
4
- level: string;
5
- message: string;
6
- [key: string]: any;
7
- }
8
-
9
- const logger = createLogger({
10
- transports: [
11
- new transports.Console({
12
- level: 'debug',
13
- format: format.combine(
14
- format.label({ label: '[shop]' }),
15
- format.timestamp({
16
- format: 'YYYY-MM-DD HH:mm:ss',
17
- }),
18
- format.colorize(),
19
- format.printf((info: TransformableInfo) => `${info.timestamp} - ${info.level}: ${info.label} ${info.message}`),
20
- ),
21
- }),
22
- ],
23
- });
24
-
25
- export default logger;