@asapjs/core 0.0.6 → 0.0.7
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 +1 -4
- package/dist/application.d.ts.map +1 -1
- package/dist/application.js +5 -31
- package/dist/application.js.map +1 -1
- package/package.json +2 -1
- package/src/application.ts +8 -34
- package/src/middleware/errorHandler.ts +0 -20
package/dist/application.d.ts
CHANGED
|
@@ -1,10 +1,7 @@
|
|
|
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
6
|
run: (port: number) => void;
|
|
10
7
|
}
|
|
@@ -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;IAM/C,OAAO,CAAC,WAAW,CASjB;IAEK,GAAG,SAAU,MAAM,UAIxB;CACH"}
|
package/dist/application.js
CHANGED
|
@@ -13,15 +13,16 @@ 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
|
|
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
|
}
|
|
@@ -33,35 +34,8 @@ class Application {
|
|
|
33
34
|
};
|
|
34
35
|
(0, config_1.setConfig)(projectConfig);
|
|
35
36
|
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
37
|
this.initMoudles(dirname);
|
|
41
38
|
}
|
|
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
|
-
});
|
|
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 }));
|
|
64
|
-
}
|
|
65
39
|
}
|
|
66
40
|
exports.default = Application;
|
|
67
41
|
//# sourceMappingURL=application.js.map
|
package/dist/application.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"application.js","sourceRoot":"","sources":["../src/application.ts"],"names":[],"mappings":";;;;;;;;;;;;;;AAAA,iDAAwD;
|
|
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;QAMvC,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,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;QApBA,IAAA,kBAAS,EAAC,aAAa,CAAC,CAAC;QACzB,IAAI,CAAC,MAAM,GAAG,aAAa,CAAC;QAC5B,IAAI,CAAC,WAAW,CAAC,OAAO,CAAC,CAAC;IAC5B,CAAC;CAkBF;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.7",
|
|
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/src/application.ts
CHANGED
|
@@ -1,54 +1,28 @@
|
|
|
1
1
|
import { initSequelizeModule } from '@asapjs/sequelize';
|
|
2
|
+
import { RouterModule } from '@asapjs/router';
|
|
2
3
|
|
|
3
4
|
import express from 'express';
|
|
4
|
-
import bodyParser from 'body-parser';
|
|
5
|
-
import cors from 'cors';
|
|
6
5
|
|
|
7
|
-
import errorHandler from './middleware/errorHandler';
|
|
8
6
|
import logger from './util/logger';
|
|
9
7
|
import { setConfig } from './config';
|
|
10
8
|
|
|
11
9
|
export default class Application {
|
|
12
|
-
public app: express.Application;
|
|
13
|
-
|
|
14
10
|
private config: any;
|
|
15
11
|
|
|
12
|
+
private app: express.Application;
|
|
13
|
+
|
|
16
14
|
constructor(dirname: string, projectConfig: any) {
|
|
17
15
|
setConfig(projectConfig);
|
|
18
16
|
this.config = projectConfig;
|
|
19
|
-
this.app = express();
|
|
20
|
-
this.initMiddlewares();
|
|
21
|
-
this.initRouter(dirname);
|
|
22
|
-
this.app.use(errorHandler);
|
|
23
17
|
this.initMoudles(dirname);
|
|
24
18
|
}
|
|
25
19
|
|
|
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
20
|
private initMoudles = async (dirname: string) => {
|
|
21
|
+
// init @asapjs/router module
|
|
22
|
+
const { app } = new RouterModule(dirname);
|
|
23
|
+
this.app = app;
|
|
24
|
+
|
|
25
|
+
// init @asapjs/sequelize module
|
|
52
26
|
if (this.config.extensions.includes('@asapjs/sequelize')) {
|
|
53
27
|
await initSequelizeModule(dirname);
|
|
54
28
|
}
|
|
@@ -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;
|