@asapjs/core 0.0.4 → 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 +2 -7
- package/dist/application.d.ts.map +1 -1
- package/dist/application.js +12 -42
- package/dist/application.js.map +1 -1
- package/package.json +4 -3
- package/src/application.ts +16 -48
- package/src/middleware/errorHandler.ts +0 -20
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
|
-
private initMiddlewares;
|
|
10
|
-
private initSequelizeConnection;
|
|
5
|
+
private initMoudles;
|
|
11
6
|
run: (port: number) => 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;IAM/C,OAAO,CAAC,WAAW,CASjB;IAEK,GAAG,SAAU,MAAM,UAIxB;CACH"}
|
package/dist/application.js
CHANGED
|
@@ -12,14 +12,21 @@ 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) {
|
|
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
|
+
});
|
|
23
30
|
this.run = (port) => {
|
|
24
31
|
this.app
|
|
25
32
|
.listen(port, () => logger_1.default.info(`@express :: Server is listening at ${port}`))
|
|
@@ -27,44 +34,7 @@ class Application {
|
|
|
27
34
|
};
|
|
28
35
|
(0, config_1.setConfig)(projectConfig);
|
|
29
36
|
this.config = projectConfig;
|
|
30
|
-
this.
|
|
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
|
-
});
|
|
37
|
+
this.initMoudles(dirname);
|
|
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;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,12 +1,11 @@
|
|
|
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": {
|
|
7
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
|
-
"prepublish": "yarn build"
|
|
8
|
+
"localinstall": "yarn build && cp -r ./dist /Users/seungmin/projects/pangaia/pangaia-b4c-ms-shop/node_modules/@asapjs/core/"
|
|
10
9
|
},
|
|
11
10
|
"author": "",
|
|
12
11
|
"license": "ISC",
|
|
@@ -20,6 +19,8 @@
|
|
|
20
19
|
"winston": "^3.6.0"
|
|
21
20
|
},
|
|
22
21
|
"devDependencies": {
|
|
22
|
+
"@asapjs/router": "0.0.2",
|
|
23
|
+
"@asapjs/sequelize": "^0.0.2",
|
|
23
24
|
"@types/body-parser": "^1.19.2",
|
|
24
25
|
"@types/cors": "^2.8.12",
|
|
25
26
|
"@types/express": "^4.17.13",
|
package/src/application.ts
CHANGED
|
@@ -1,64 +1,32 @@
|
|
|
1
|
+
import { initSequelizeModule } from '@asapjs/sequelize';
|
|
2
|
+
import { RouterModule } from '@asapjs/router';
|
|
3
|
+
|
|
1
4
|
import express from 'express';
|
|
2
|
-
import bodyParser from 'body-parser';
|
|
3
|
-
import cors from 'cors';
|
|
4
|
-
import { Sequelize } from 'sequelize-typescript';
|
|
5
5
|
|
|
6
|
-
import errorHandler from './middleware/errorHandler';
|
|
7
6
|
import logger from './util/logger';
|
|
8
|
-
import {
|
|
7
|
+
import { setConfig } from './config';
|
|
9
8
|
|
|
10
9
|
export default class Application {
|
|
11
|
-
public app: express.Application;
|
|
12
|
-
|
|
13
|
-
public sequelize: Promise<Sequelize>;
|
|
14
|
-
|
|
15
10
|
private config: any;
|
|
16
11
|
|
|
12
|
+
private app: express.Application;
|
|
13
|
+
|
|
17
14
|
constructor(dirname: string, projectConfig: any) {
|
|
18
15
|
setConfig(projectConfig);
|
|
19
16
|
this.config = projectConfig;
|
|
20
|
-
this.
|
|
21
|
-
this.initMiddlewares();
|
|
22
|
-
this.initRouter(dirname);
|
|
23
|
-
this.app.use(errorHandler);
|
|
24
|
-
this.sequelize = this.initSequelizeConnection(dirname);
|
|
25
|
-
|
|
26
|
-
console.log(getConfig());
|
|
17
|
+
this.initMoudles(dirname);
|
|
27
18
|
}
|
|
28
19
|
|
|
29
|
-
private
|
|
30
|
-
|
|
31
|
-
const
|
|
32
|
-
|
|
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
|
-
}
|
|
20
|
+
private initMoudles = async (dirname: string) => {
|
|
21
|
+
// init @asapjs/router module
|
|
22
|
+
const { app } = new RouterModule(dirname);
|
|
23
|
+
this.app = app;
|
|
47
24
|
|
|
48
|
-
|
|
49
|
-
this.
|
|
50
|
-
|
|
51
|
-
|
|
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
|
-
}
|
|
25
|
+
// init @asapjs/sequelize module
|
|
26
|
+
if (this.config.extensions.includes('@asapjs/sequelize')) {
|
|
27
|
+
await initSequelizeModule(dirname);
|
|
28
|
+
}
|
|
29
|
+
};
|
|
62
30
|
|
|
63
31
|
public run = (port: number) => {
|
|
64
32
|
this.app
|
|
@@ -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;
|