@asapjs/core 0.0.5 → 0.0.8
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/dist/application.d.ts +3 -8
- package/dist/application.d.ts.map +1 -1
- package/dist/application.js +15 -45
- package/dist/application.js.map +1 -1
- package/package.json +3 -1
- package/.prettierrc +0 -8
- package/dist/middleware/errorHandler.d.ts +0 -9
- package/dist/middleware/errorHandler.d.ts.map +0 -1
- package/dist/middleware/errorHandler.js +0 -17
- package/dist/middleware/errorHandler.js.map +0 -1
- package/dist/sequelize/index.d.ts +0 -8
- package/dist/sequelize/index.d.ts.map +0 -1
- package/dist/sequelize/index.js +0 -67
- package/dist/sequelize/index.js.map +0 -1
- package/src/application.ts +0 -68
- package/src/config/index.ts +0 -7
- package/src/index.ts +0 -3
- package/src/middleware/errorHandler.ts +0 -20
- package/src/util/logger.ts +0 -25
package/dist/application.d.ts
CHANGED
|
@@ -1,13 +1,8 @@
|
|
|
1
|
-
import express from 'express';
|
|
2
|
-
import { Sequelize } from 'sequelize-typescript';
|
|
3
1
|
export default class Application {
|
|
4
|
-
app: express.Application;
|
|
5
|
-
sequelize: Promise<Sequelize>;
|
|
6
2
|
private config;
|
|
3
|
+
private app;
|
|
7
4
|
constructor(dirname: string, projectConfig: any);
|
|
8
|
-
private
|
|
9
|
-
|
|
10
|
-
private initSequelizeConnection;
|
|
11
|
-
run: (port: number) => void;
|
|
5
|
+
private initMoudles;
|
|
6
|
+
run: (port: number) => Promise<void>;
|
|
12
7
|
}
|
|
13
8
|
//# sourceMappingURL=application.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"application.d.ts","sourceRoot":"","sources":["../src/application.ts"],"names":[],"mappings":"
|
|
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,SAAgB,MAAM,mBAK9B;CACH"}
|
package/dist/application.js
CHANGED
|
@@ -12,59 +12,29 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
12
12
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
13
13
|
};
|
|
14
14
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
|
-
const
|
|
16
|
-
const
|
|
17
|
-
const cors_1 = __importDefault(require("cors"));
|
|
18
|
-
const errorHandler_1 = __importDefault(require("./middleware/errorHandler"));
|
|
15
|
+
const sequelize_1 = require("@asapjs/sequelize");
|
|
16
|
+
const router_1 = require("@asapjs/router");
|
|
19
17
|
const logger_1 = __importDefault(require("./util/logger"));
|
|
20
18
|
const config_1 = require("./config");
|
|
21
19
|
class Application {
|
|
22
20
|
constructor(dirname, projectConfig) {
|
|
23
|
-
this.
|
|
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
|
|
26
|
+
if (this.config.extensions.includes('@asapjs/sequelize')) {
|
|
27
|
+
yield (0, sequelize_1.initSequelizeModule)(dirname);
|
|
28
|
+
}
|
|
29
|
+
});
|
|
30
|
+
this.run = (port) => __awaiter(this, void 0, void 0, function* () {
|
|
31
|
+
yield this.initMoudles(this.config.dirname);
|
|
24
32
|
this.app
|
|
25
33
|
.listen(port, () => logger_1.default.info(`@express :: Server is listening at ${port}`))
|
|
26
34
|
.on('error', (error) => logger_1.default.error(error));
|
|
27
|
-
};
|
|
28
|
-
(0, config_1.setConfig)(projectConfig);
|
|
29
|
-
this.config = projectConfig;
|
|
30
|
-
this.app = (0, express_1.default)();
|
|
31
|
-
this.initMiddlewares();
|
|
32
|
-
this.initRouter(dirname);
|
|
33
|
-
this.app.use(errorHandler_1.default);
|
|
34
|
-
this.sequelize = this.initSequelizeConnection(dirname);
|
|
35
|
-
console.log((0, config_1.getConfig)());
|
|
36
|
-
}
|
|
37
|
-
initRouter(dirname) {
|
|
38
|
-
const router = express_1.default.Router();
|
|
39
|
-
const routes = require(`${dirname}/route`).default;
|
|
40
|
-
routes.forEach((route) => {
|
|
41
|
-
this.app.use(`/shop${route.basePath}`, route.expressRouter || route.router);
|
|
42
|
-
});
|
|
43
|
-
this.app.use(router);
|
|
44
|
-
this.app.get('/shop', (req, res) => {
|
|
45
|
-
res.send('pangaia-b4c-ms-shop server is working');
|
|
46
|
-
});
|
|
47
|
-
this.app.get('/health-check', (req, res) => {
|
|
48
|
-
res.send('pangaia-b4c-ms-shop server is working');
|
|
49
|
-
});
|
|
50
|
-
// this.app.get('/sync', async (req: any, res: any) => {
|
|
51
|
-
// const result = await modelsSync();
|
|
52
|
-
// res.send(result);
|
|
53
|
-
// });
|
|
54
|
-
}
|
|
55
|
-
initMiddlewares() {
|
|
56
|
-
this.app.use((0, cors_1.default)());
|
|
57
|
-
this.app.use(body_parser_1.default.json());
|
|
58
|
-
this.app.use(body_parser_1.default.urlencoded({ extended: true }));
|
|
59
|
-
}
|
|
60
|
-
initSequelizeConnection(dirname) {
|
|
61
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
62
|
-
const { addModelsToSequelize, dbInit, loadPath, modelsSync } = require('@asapjs/sequelize');
|
|
63
|
-
const dbContainer = yield dbInit(this.config.DB);
|
|
64
|
-
yield loadPath(dirname, '');
|
|
65
|
-
yield addModelsToSequelize();
|
|
66
|
-
return dbContainer;
|
|
67
35
|
});
|
|
36
|
+
(0, config_1.setConfig)(projectConfig);
|
|
37
|
+
this.config = Object.assign({ dirname }, projectConfig);
|
|
68
38
|
}
|
|
69
39
|
}
|
|
70
40
|
exports.default = Application;
|
package/dist/application.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"application.js","sourceRoot":"","sources":["../src/application.ts"],"names":[],"mappings":";;;;;;;;;;;;;;AAAA,
|
|
1
|
+
{"version":3,"file":"application.js","sourceRoot":"","sources":["../src/application.ts"],"names":[],"mappings":";;;;;;;;;;;;;;AAAA,iDAAwD;AACxD,2CAA8C;AAI9C,2DAAmC;AACnC,qCAAqC;AAErC,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,CAAO,IAAY,EAAE,EAAE;YAClC,MAAM,IAAI,CAAC,WAAW,CAAC,IAAI,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC;YAC5C,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,CAAA,CAAC;QApBA,IAAA,kBAAS,EAAC,aAAa,CAAC,CAAC;QACzB,IAAI,CAAC,MAAM,mBAAK,OAAO,IAAK,aAAa,CAAE,CAAC;IAC9C,CAAC;CAmBF;AA3BD,8BA2BC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@asapjs/core",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.8",
|
|
4
4
|
"description": "",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"scripts": {
|
|
@@ -19,6 +19,8 @@
|
|
|
19
19
|
"winston": "^3.6.0"
|
|
20
20
|
},
|
|
21
21
|
"devDependencies": {
|
|
22
|
+
"@asapjs/router": "0.0.2",
|
|
23
|
+
"@asapjs/sequelize": "^0.0.2",
|
|
22
24
|
"@types/body-parser": "^1.19.2",
|
|
23
25
|
"@types/cors": "^2.8.12",
|
|
24
26
|
"@types/express": "^4.17.13",
|
package/.prettierrc
DELETED
|
@@ -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"}
|
package/dist/sequelize/index.js
DELETED
|
@@ -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,oDAAoD,EAAE,GAAG,CAAC,CAAC;IAC1E,CAAC,CAAC,CAAC;IAEL,gBAAM,CAAC,IAAI,CAAC,mCAAmC,CAAC,CAAC;IAEjD,OAAO,SAAS,CAAC;AACnB,CAAC,CAAA,CAAC;AAfW,QAAA,MAAM,UAejB;AAEK,MAAM,QAAQ,GAAG,CAAO,IAAY,EAAE,OAAe,EAAE,EAAE;IAC9D,MAAM,KAAK,GAAG,MAAM,YAAE,CAAC,WAAW,CAAC,IAAI,GAAG,OAAO,EAAE,EAAE,aAAa,EAAE,IAAI,EAAE,CAAC,CAAC;IAC5E,MAAM,SAAS,GAAG,OAAO,CAAC,GAAG,CAAC,QAAQ,KAAK,YAAY,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,IAAI,CAAC;IACtE,KAAK,MAAM,IAAI,IAAI,KAAK,EAAE;QACxB,IAAI,IAAI,CAAC,WAAW,EAAE,EAAE;YACtB,MAAM,IAAA,gBAAQ,EAAC,IAAI,EAAE,GAAG,OAAO,IAAI,IAAI,CAAC,IAAI,EAAE,CAAC,CAAC;SACjD;aAAM,IAAI,IAAI,CAAC,IAAI,CAAC,QAAQ,CAAC,SAAS,SAAS,EAAE,CAAC,IAAI,IAAI,CAAC,IAAI,CAAC,QAAQ,CAAC,KAAK,CAAC,KAAK,KAAK,EAAE;YAC1F,MAAM,CAAC,IAAI,CAAC,OAAO,CAAC,GAAG,IAAI,IAAI,OAAO,IAAI,IAAI,CAAC,IAAI,EAAE,CAAC,CAAC,OAAO,CAAC,CAAC;SACjE;aAAM,IAAI,IAAI,CAAC,IAAI,CAAC,QAAQ,CAAC,OAAO,SAAS,EAAE,CAAC,IAAI,IAAI,CAAC,IAAI,CAAC,QAAQ,CAAC,KAAK,CAAC,KAAK,KAAK,EAAE;YACxF,IAAI,CAAC,IAAI,CAAC,OAAO,CAAC,GAAG,IAAI,IAAI,OAAO,IAAI,IAAI,CAAC,IAAI,EAAE,CAAC,CAAC,OAAO,CAAC,CAAC;SAC/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"}
|
package/src/application.ts
DELETED
|
@@ -1,68 +0,0 @@
|
|
|
1
|
-
import express from 'express';
|
|
2
|
-
import bodyParser from 'body-parser';
|
|
3
|
-
import cors from 'cors';
|
|
4
|
-
import { Sequelize } from 'sequelize-typescript';
|
|
5
|
-
|
|
6
|
-
import errorHandler from './middleware/errorHandler';
|
|
7
|
-
import logger from './util/logger';
|
|
8
|
-
import { getConfig, setConfig } from './config';
|
|
9
|
-
|
|
10
|
-
export default class Application {
|
|
11
|
-
public app: express.Application;
|
|
12
|
-
|
|
13
|
-
public sequelize: Promise<Sequelize>;
|
|
14
|
-
|
|
15
|
-
private config: any;
|
|
16
|
-
|
|
17
|
-
constructor(dirname: string, projectConfig: any) {
|
|
18
|
-
setConfig(projectConfig);
|
|
19
|
-
this.config = projectConfig;
|
|
20
|
-
this.app = express();
|
|
21
|
-
this.initMiddlewares();
|
|
22
|
-
this.initRouter(dirname);
|
|
23
|
-
this.app.use(errorHandler);
|
|
24
|
-
this.sequelize = this.initSequelizeConnection(dirname);
|
|
25
|
-
|
|
26
|
-
console.log(getConfig());
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
private initRouter(dirname: string) {
|
|
30
|
-
const router: express.Router = express.Router();
|
|
31
|
-
const routes = require(`${dirname}/route`).default;
|
|
32
|
-
routes.forEach((route: any) => {
|
|
33
|
-
this.app.use(`/shop${route.basePath}`, route.expressRouter || route.router);
|
|
34
|
-
});
|
|
35
|
-
this.app.use(router);
|
|
36
|
-
this.app.get('/shop', (req: any, res: any) => {
|
|
37
|
-
res.send('pangaia-b4c-ms-shop server is working');
|
|
38
|
-
});
|
|
39
|
-
this.app.get('/health-check', (req: any, res: any) => {
|
|
40
|
-
res.send('pangaia-b4c-ms-shop server is working');
|
|
41
|
-
});
|
|
42
|
-
// this.app.get('/sync', async (req: any, res: any) => {
|
|
43
|
-
// const result = await modelsSync();
|
|
44
|
-
// res.send(result);
|
|
45
|
-
// });
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
private initMiddlewares() {
|
|
49
|
-
this.app.use(cors());
|
|
50
|
-
this.app.use(bodyParser.json());
|
|
51
|
-
this.app.use(bodyParser.urlencoded({ extended: true }));
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
private async initSequelizeConnection(dirname: string): Promise<Sequelize> {
|
|
55
|
-
const { addModelsToSequelize, dbInit, loadPath, modelsSync } = require('@asapjs/sequelize');
|
|
56
|
-
|
|
57
|
-
const dbContainer = await dbInit(this.config.DB);
|
|
58
|
-
await loadPath(dirname, '');
|
|
59
|
-
await addModelsToSequelize();
|
|
60
|
-
return dbContainer;
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
public run = (port: number) => {
|
|
64
|
-
this.app
|
|
65
|
-
.listen(port, () => logger.info(`@express :: Server is listening at ${port}`))
|
|
66
|
-
.on('error', (error: string) => logger.error(error));
|
|
67
|
-
};
|
|
68
|
-
}
|
package/src/config/index.ts
DELETED
package/src/index.ts
DELETED
|
@@ -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;
|
package/src/util/logger.ts
DELETED
|
@@ -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;
|