@asapjs/core 0.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/.prettierrc +8 -0
- package/dist/application.d.ts +13 -0
- package/dist/application.d.ts.map +1 -0
- package/dist/application.js +68 -0
- package/dist/application.js.map +1 -0
- package/dist/index.d.ts +3 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +11 -0
- package/dist/index.js.map +1 -0
- package/dist/middleware/errorHandler.d.ts +9 -0
- package/dist/middleware/errorHandler.d.ts.map +1 -0
- package/dist/middleware/errorHandler.js +17 -0
- package/dist/middleware/errorHandler.js.map +1 -0
- package/dist/sequelize/index.d.ts +8 -0
- package/dist/sequelize/index.d.ts.map +1 -0
- package/dist/sequelize/index.js +67 -0
- package/dist/sequelize/index.js.map +1 -0
- package/dist/util/logger.d.ts +3 -0
- package/dist/util/logger.d.ts.map +1 -0
- package/dist/util/logger.js +15 -0
- package/dist/util/logger.js.map +1 -0
- package/package.json +28 -0
- package/src/application.ts +63 -0
- package/src/index.ts +2 -0
- package/src/middleware/errorHandler.ts +20 -0
- package/src/util/logger.ts +25 -0
- package/tsconfig.json +21 -0
package/.prettierrc
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import express from 'express';
|
|
2
|
+
import { Sequelize } from 'sequelize-typescript';
|
|
3
|
+
export default class Application {
|
|
4
|
+
app: express.Application;
|
|
5
|
+
sequelize: Promise<Sequelize>;
|
|
6
|
+
private config;
|
|
7
|
+
constructor(dirname: string, config: any);
|
|
8
|
+
private initRouter;
|
|
9
|
+
private initMiddlewares;
|
|
10
|
+
private initSequelizeConnection;
|
|
11
|
+
run: (port: number) => void;
|
|
12
|
+
}
|
|
13
|
+
//# sourceMappingURL=application.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"application.d.ts","sourceRoot":"","sources":["../src/application.ts"],"names":[],"mappings":"AAAA,OAAO,OAAO,MAAM,SAAS,CAAC;AAG9B,OAAO,EAAE,SAAS,EAAE,MAAM,sBAAsB,CAAC;AAIjD,MAAM,CAAC,OAAO,OAAO,WAAW;IACvB,GAAG,EAAE,OAAO,CAAC,WAAW,CAAC;IAEzB,SAAS,EAAE,OAAO,CAAC,SAAS,CAAC,CAAC;IAErC,OAAO,CAAC,MAAM,CAAM;gBAER,OAAO,EAAE,MAAM,EAAE,MAAM,EAAE,GAAG;IASxC,OAAO,CAAC,UAAU;IAmBlB,OAAO,CAAC,eAAe;YAMT,uBAAuB;IAS9B,GAAG,SAAU,MAAM,UAIxB;CACH"}
|
|
@@ -0,0 +1,68 @@
|
|
|
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
|
+
const express_1 = __importDefault(require("express"));
|
|
16
|
+
const body_parser_1 = __importDefault(require("body-parser"));
|
|
17
|
+
const cors_1 = __importDefault(require("cors"));
|
|
18
|
+
const errorHandler_1 = __importDefault(require("./middleware/errorHandler"));
|
|
19
|
+
const logger_1 = __importDefault(require("./util/logger"));
|
|
20
|
+
class Application {
|
|
21
|
+
constructor(dirname, config) {
|
|
22
|
+
this.run = (port) => {
|
|
23
|
+
this.app
|
|
24
|
+
.listen(port, () => logger_1.default.info(`@express :: Server is listening at ${port}`))
|
|
25
|
+
.on('error', (error) => logger_1.default.error(error));
|
|
26
|
+
};
|
|
27
|
+
this.config = config;
|
|
28
|
+
this.app = (0, express_1.default)();
|
|
29
|
+
this.initMiddlewares();
|
|
30
|
+
this.initRouter(dirname);
|
|
31
|
+
this.app.use(errorHandler_1.default);
|
|
32
|
+
this.sequelize = this.initSequelizeConnection(dirname);
|
|
33
|
+
}
|
|
34
|
+
initRouter(dirname) {
|
|
35
|
+
const router = express_1.default.Router();
|
|
36
|
+
const routes = require(`${dirname}/route`).default;
|
|
37
|
+
routes.forEach((route) => {
|
|
38
|
+
this.app.use(`/shop${route.basePath}`, route.expressRouter || route.router);
|
|
39
|
+
});
|
|
40
|
+
this.app.use(router);
|
|
41
|
+
this.app.get('/shop', (req, res) => {
|
|
42
|
+
res.send('pangaia-b4c-ms-shop server is working');
|
|
43
|
+
});
|
|
44
|
+
this.app.get('/health-check', (req, res) => {
|
|
45
|
+
res.send('pangaia-b4c-ms-shop server is working');
|
|
46
|
+
});
|
|
47
|
+
// this.app.get('/sync', async (req: any, res: any) => {
|
|
48
|
+
// const result = await modelsSync();
|
|
49
|
+
// res.send(result);
|
|
50
|
+
// });
|
|
51
|
+
}
|
|
52
|
+
initMiddlewares() {
|
|
53
|
+
this.app.use((0, cors_1.default)());
|
|
54
|
+
this.app.use(body_parser_1.default.json());
|
|
55
|
+
this.app.use(body_parser_1.default.urlencoded({ extended: true }));
|
|
56
|
+
}
|
|
57
|
+
initSequelizeConnection(dirname) {
|
|
58
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
59
|
+
const { addModelsToSequelize, dbInit, loadPath, modelsSync } = require('@asapjs/sequelize');
|
|
60
|
+
const dbContainer = yield dbInit(this.config.DB);
|
|
61
|
+
yield loadPath(dirname, '');
|
|
62
|
+
yield addModelsToSequelize();
|
|
63
|
+
return dbContainer;
|
|
64
|
+
});
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
exports.default = Application;
|
|
68
|
+
//# sourceMappingURL=application.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"application.js","sourceRoot":"","sources":["../src/application.ts"],"names":[],"mappings":";;;;;;;;;;;;;;AAAA,sDAA8B;AAC9B,8DAAqC;AACrC,gDAAwB;AAExB,6EAAqD;AACrD,2DAAmC;AAEnC,MAAqB,WAAW;IAO9B,YAAY,OAAe,EAAE,MAAW;QA2CjC,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;QA9CA,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC;QACrB,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,SAAS,GAAG,IAAI,CAAC,uBAAuB,CAAC,OAAO,CAAC,CAAC;IACzD,CAAC;IAEO,UAAU,CAAC,OAAe;QAChC,MAAM,MAAM,GAAmB,iBAAO,CAAC,MAAM,EAAE,CAAC;QAChD,MAAM,MAAM,GAAG,OAAO,CAAC,GAAG,OAAO,QAAQ,CAAC,CAAC,OAAO,CAAC;QACnD,MAAM,CAAC,OAAO,CAAC,CAAC,KAAU,EAAE,EAAE;YAC5B,IAAI,CAAC,GAAG,CAAC,GAAG,CAAC,QAAQ,KAAK,CAAC,QAAQ,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d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,IAAI,WAAW,EAAE,MAAM,eAAe,CAAC;AACvD,OAAO,EAAE,OAAO,IAAI,MAAM,EAAE,MAAM,eAAe,CAAC"}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.logger = exports.Application = void 0;
|
|
7
|
+
var application_1 = require("./application");
|
|
8
|
+
Object.defineProperty(exports, "Application", { enumerable: true, get: function () { return __importDefault(application_1).default; } });
|
|
9
|
+
var logger_1 = require("./util/logger");
|
|
10
|
+
Object.defineProperty(exports, "logger", { enumerable: true, get: function () { return __importDefault(logger_1).default; } });
|
|
11
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;;AAAA,6CAAuD;AAA9C,2HAAA,OAAO,OAAe;AAC/B,wCAAkD;AAAzC,iHAAA,OAAO,OAAU"}
|
|
@@ -0,0 +1,9 @@
|
|
|
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
|
|
@@ -0,0 +1 @@
|
|
|
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"}
|
|
@@ -0,0 +1,17 @@
|
|
|
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
|
|
@@ -0,0 +1 @@
|
|
|
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"}
|
|
@@ -0,0 +1,8 @@
|
|
|
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
|
|
@@ -0,0 +1 @@
|
|
|
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"}
|
|
@@ -0,0 +1,67 @@
|
|
|
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
|
|
@@ -0,0 +1 @@
|
|
|
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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AAC,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"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"logger.d.ts","sourceRoot":"","sources":["../../src/util/logger.ts"],"names":[],"mappings":"AAQA,QAAA,MAAM,MAAM,0BAcV,CAAC;AAEH,eAAe,MAAM,CAAC"}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const winston_1 = require("winston");
|
|
4
|
+
const logger = (0, winston_1.createLogger)({
|
|
5
|
+
transports: [
|
|
6
|
+
new winston_1.transports.Console({
|
|
7
|
+
level: 'debug',
|
|
8
|
+
format: winston_1.format.combine(winston_1.format.label({ label: '[shop]' }), winston_1.format.timestamp({
|
|
9
|
+
format: 'YYYY-MM-DD HH:mm:ss',
|
|
10
|
+
}), winston_1.format.colorize(), winston_1.format.printf((info) => `${info.timestamp} - ${info.level}: ${info.label} ${info.message}`)),
|
|
11
|
+
}),
|
|
12
|
+
],
|
|
13
|
+
});
|
|
14
|
+
exports.default = logger;
|
|
15
|
+
//# sourceMappingURL=logger.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"logger.js","sourceRoot":"","sources":["../../src/util/logger.ts"],"names":[],"mappings":";;AAAA,qCAA2D;AAQ3D,MAAM,MAAM,GAAG,IAAA,sBAAY,EAAC;IAC1B,UAAU,EAAE;QACV,IAAI,oBAAU,CAAC,OAAO,CAAC;YACrB,KAAK,EAAE,OAAO;YACd,MAAM,EAAE,gBAAM,CAAC,OAAO,CACpB,gBAAM,CAAC,KAAK,CAAC,EAAE,KAAK,EAAE,QAAQ,EAAE,CAAC,EACjC,gBAAM,CAAC,SAAS,CAAC;gBACf,MAAM,EAAE,qBAAqB;aAC9B,CAAC,EACF,gBAAM,CAAC,QAAQ,EAAE,EACjB,gBAAM,CAAC,MAAM,CAAC,CAAC,IAAuB,EAAE,EAAE,CAAC,GAAG,IAAI,CAAC,SAAS,MAAM,IAAI,CAAC,KAAK,KAAK,IAAI,CAAC,KAAK,IAAI,IAAI,CAAC,OAAO,EAAE,CAAC,CAC/G;SACF,CAAC;KACH;CACF,CAAC,CAAC;AAEH,kBAAe,MAAM,CAAC"}
|
package/package.json
ADDED
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@asapjs/core",
|
|
3
|
+
"version": "0.0.1",
|
|
4
|
+
"description": "",
|
|
5
|
+
"main": "dist/index.js",
|
|
6
|
+
"scripts": {
|
|
7
|
+
"build": "./node_modules/typescript/bin/tsc",
|
|
8
|
+
"localinstall": "yarn build && cp -r ./dist /Users/seungmin/projects/pangaia/pangaia-b4c-ms-shop/node_modules/@asapjs/core/"
|
|
9
|
+
},
|
|
10
|
+
"author": "",
|
|
11
|
+
"license": "ISC",
|
|
12
|
+
"dependencies": {
|
|
13
|
+
"body-parser": "^1.19.2",
|
|
14
|
+
"cors": "^2.8.5",
|
|
15
|
+
"express": "^4.17.3",
|
|
16
|
+
"fs": "^0.0.1-security",
|
|
17
|
+
"sequelize": "^6.17.0",
|
|
18
|
+
"sequelize-typescript": "^2.1.3",
|
|
19
|
+
"winston": "^3.6.0"
|
|
20
|
+
},
|
|
21
|
+
"devDependencies": {
|
|
22
|
+
"@types/body-parser": "^1.19.2",
|
|
23
|
+
"@types/cors": "^2.8.12",
|
|
24
|
+
"@types/express": "^4.17.13",
|
|
25
|
+
"@types/node": "^17.0.21",
|
|
26
|
+
"typescript": "^4.6.2"
|
|
27
|
+
}
|
|
28
|
+
}
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
import express from 'express';
|
|
2
|
+
import bodyParser from 'body-parser';
|
|
3
|
+
import cors from 'cors';
|
|
4
|
+
import { Sequelize } from 'sequelize-typescript';
|
|
5
|
+
import errorHandler from './middleware/errorHandler';
|
|
6
|
+
import logger from './util/logger';
|
|
7
|
+
|
|
8
|
+
export default class Application {
|
|
9
|
+
public app: express.Application;
|
|
10
|
+
|
|
11
|
+
public sequelize: Promise<Sequelize>;
|
|
12
|
+
|
|
13
|
+
private config: any;
|
|
14
|
+
|
|
15
|
+
constructor(dirname: string, config: any) {
|
|
16
|
+
this.config = config;
|
|
17
|
+
this.app = express();
|
|
18
|
+
this.initMiddlewares();
|
|
19
|
+
this.initRouter(dirname);
|
|
20
|
+
this.app.use(errorHandler);
|
|
21
|
+
this.sequelize = this.initSequelizeConnection(dirname);
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
private initRouter(dirname: string) {
|
|
25
|
+
const router: express.Router = express.Router();
|
|
26
|
+
const routes = require(`${dirname}/route`).default;
|
|
27
|
+
routes.forEach((route: any) => {
|
|
28
|
+
this.app.use(`/shop${route.basePath}`, route.expressRouter || route.router);
|
|
29
|
+
});
|
|
30
|
+
this.app.use(router);
|
|
31
|
+
this.app.get('/shop', (req: any, res: any) => {
|
|
32
|
+
res.send('pangaia-b4c-ms-shop server is working');
|
|
33
|
+
});
|
|
34
|
+
this.app.get('/health-check', (req: any, res: any) => {
|
|
35
|
+
res.send('pangaia-b4c-ms-shop server is working');
|
|
36
|
+
});
|
|
37
|
+
// this.app.get('/sync', async (req: any, res: any) => {
|
|
38
|
+
// const result = await modelsSync();
|
|
39
|
+
// res.send(result);
|
|
40
|
+
// });
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
private initMiddlewares() {
|
|
44
|
+
this.app.use(cors());
|
|
45
|
+
this.app.use(bodyParser.json());
|
|
46
|
+
this.app.use(bodyParser.urlencoded({ extended: true }));
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
private async initSequelizeConnection(dirname: string): Promise<Sequelize> {
|
|
50
|
+
const { addModelsToSequelize, dbInit, loadPath, modelsSync } = require('@asapjs/sequelize');
|
|
51
|
+
|
|
52
|
+
const dbContainer = await dbInit(this.config.DB);
|
|
53
|
+
await loadPath(dirname, '');
|
|
54
|
+
await addModelsToSequelize();
|
|
55
|
+
return dbContainer;
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
public run = (port: number) => {
|
|
59
|
+
this.app
|
|
60
|
+
.listen(port, () => logger.info(`@express :: Server is listening at ${port}`))
|
|
61
|
+
.on('error', (error: string) => logger.error(error));
|
|
62
|
+
};
|
|
63
|
+
}
|
package/src/index.ts
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
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;
|
|
@@ -0,0 +1,25 @@
|
|
|
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;
|
package/tsconfig.json
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
{
|
|
2
|
+
"compilerOptions": {
|
|
3
|
+
"module": "commonjs",
|
|
4
|
+
"esModuleInterop": true,
|
|
5
|
+
"target": "es6",
|
|
6
|
+
"noImplicitAny": true,
|
|
7
|
+
"moduleResolution": "node",
|
|
8
|
+
"sourceMap": true,
|
|
9
|
+
"declaration": true,
|
|
10
|
+
"declarationMap": true,
|
|
11
|
+
"baseUrl": ".",
|
|
12
|
+
"outDir": "dist",
|
|
13
|
+
"lib": ["es2015", "es2019", "es2020"],
|
|
14
|
+
"skipLibCheck": true,
|
|
15
|
+
"strictNullChecks": true,
|
|
16
|
+
"experimentalDecorators": true,
|
|
17
|
+
"emitDecoratorMetadata": true,
|
|
18
|
+
"resolveJsonModule": true
|
|
19
|
+
},
|
|
20
|
+
"include": ["src/**/*"]
|
|
21
|
+
}
|