namirasoft-node 1.0.1 → 1.0.3
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/BaseApplication.d.ts +7 -1
- package/dist/BaseApplication.js +47 -8
- package/dist/BaseApplication.js.map +1 -1
- package/dist/BaseApplicationLink.d.ts +6 -0
- package/dist/BaseApplicationLink.js +3 -0
- package/dist/BaseApplicationLink.js.map +1 -0
- package/package.json +1 -1
- package/src/BaseApplication.ts +58 -8
- package/src/BaseApplicationLink.ts +7 -0
|
@@ -1,11 +1,15 @@
|
|
|
1
1
|
import express, { Router } from 'express';
|
|
2
2
|
import { BaseDatabase } from './BaseDatabase';
|
|
3
3
|
import { ILogger } from "namirasoft-log";
|
|
4
|
+
import { BaseApplicationLink } from './BaseApplicationLink';
|
|
4
5
|
export declare abstract class BaseApplication<D extends BaseDatabase> {
|
|
5
6
|
private title;
|
|
6
7
|
private description;
|
|
8
|
+
private logo;
|
|
7
9
|
private version;
|
|
10
|
+
private serverPath;
|
|
8
11
|
private swaggerPath;
|
|
12
|
+
private links;
|
|
9
13
|
app: express.Express;
|
|
10
14
|
database: D;
|
|
11
15
|
logger: ILogger;
|
|
@@ -13,10 +17,12 @@ export declare abstract class BaseApplication<D extends BaseDatabase> {
|
|
|
13
17
|
protected abstract getLogger(): ILogger;
|
|
14
18
|
protected abstract getRouter(): Router;
|
|
15
19
|
protected abstract getPort(): number;
|
|
16
|
-
constructor(title: string, description: string, version: string,
|
|
20
|
+
constructor(title: string, description: string, logo: string, version: string, serverPath: string, swaggerPath?: string | null);
|
|
21
|
+
addLink(link: BaseApplicationLink): void;
|
|
17
22
|
start(): void;
|
|
18
23
|
protected startCrashHandler(): void;
|
|
19
24
|
protected startDatabase(): void;
|
|
20
25
|
protected startServer(): void;
|
|
21
26
|
protected startSwagger(): void;
|
|
27
|
+
protected startHomePage(): void;
|
|
22
28
|
}
|
package/dist/BaseApplication.js
CHANGED
|
@@ -15,21 +15,30 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
15
15
|
exports.BaseApplication = void 0;
|
|
16
16
|
const express_1 = __importDefault(require("express"));
|
|
17
17
|
const cors_1 = __importDefault(require("cors"));
|
|
18
|
+
const fs_1 = __importDefault(require("fs"));
|
|
18
19
|
const swagger_ui_express_1 = __importDefault(require("swagger-ui-express"));
|
|
19
20
|
const swagger_jsdoc_1 = __importDefault(require("swagger-jsdoc"));
|
|
21
|
+
const path_1 = __importDefault(require("path"));
|
|
20
22
|
class BaseApplication {
|
|
21
|
-
constructor(title, description, version, swaggerPath) {
|
|
23
|
+
constructor(title, description, logo, version, serverPath, swaggerPath = null) {
|
|
24
|
+
this.links = [];
|
|
22
25
|
this.title = title;
|
|
23
26
|
this.description = description;
|
|
27
|
+
this.logo = logo;
|
|
24
28
|
this.version = version;
|
|
25
|
-
this.
|
|
29
|
+
this.serverPath = serverPath;
|
|
30
|
+
this.swaggerPath = swaggerPath !== null && swaggerPath !== void 0 ? swaggerPath : (serverPath + "/swagger");
|
|
26
31
|
this.logger = this.getLogger();
|
|
27
32
|
}
|
|
33
|
+
addLink(link) {
|
|
34
|
+
this.links.push(link);
|
|
35
|
+
}
|
|
28
36
|
start() {
|
|
29
37
|
this.startCrashHandler();
|
|
30
38
|
this.startDatabase();
|
|
31
39
|
this.startServer();
|
|
32
40
|
this.startSwagger();
|
|
41
|
+
this.startHomePage();
|
|
33
42
|
}
|
|
34
43
|
startCrashHandler() {
|
|
35
44
|
process.on('unhandledRejection', (reason) => {
|
|
@@ -85,11 +94,11 @@ class BaseApplication {
|
|
|
85
94
|
// email: "accounts@namirasoft.com",
|
|
86
95
|
// },
|
|
87
96
|
},
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
97
|
+
servers: [
|
|
98
|
+
{
|
|
99
|
+
url: this.serverPath,
|
|
100
|
+
},
|
|
101
|
+
],
|
|
93
102
|
},
|
|
94
103
|
apis: ['./src/route/*.ts'],
|
|
95
104
|
};
|
|
@@ -97,7 +106,37 @@ class BaseApplication {
|
|
|
97
106
|
var options = {
|
|
98
107
|
explorer: true
|
|
99
108
|
};
|
|
100
|
-
this.app.use(this.swaggerPath, swagger_ui_express_1.default.serve, swagger_ui_express_1.default.setup(swaggerSpec, options));
|
|
109
|
+
this.app.use(this.swaggerPath + "/", swagger_ui_express_1.default.serve, swagger_ui_express_1.default.setup(swaggerSpec, options));
|
|
110
|
+
this.addLink({ title: "Swagger", description: this.description + " Swagger", image: "", link: this.swaggerPath + "/" });
|
|
111
|
+
}
|
|
112
|
+
startHomePage() {
|
|
113
|
+
this.app.get(this.serverPath + "/", (_, res) => {
|
|
114
|
+
const htmlFilePath = path_1.default.join(__dirname, 'public/index.html');
|
|
115
|
+
fs_1.default.readFile(htmlFilePath, 'utf8', (err, data) => {
|
|
116
|
+
if (err)
|
|
117
|
+
return res.status(500).send('Error reading HTML file');
|
|
118
|
+
data = data.replace(/\@title/gm, this.title);
|
|
119
|
+
data = data.replace(/\@description/gm, this.description);
|
|
120
|
+
data = data.replace(/\@logo/gm, this.logo);
|
|
121
|
+
let match = /<\@row>(.*)<\/\@row>/gm.exec(data);
|
|
122
|
+
if (match) {
|
|
123
|
+
let rows = [];
|
|
124
|
+
this.links.forEach(link => {
|
|
125
|
+
if (match) {
|
|
126
|
+
let row = match[1];
|
|
127
|
+
row = row.replace(/\@row_title/gm, link.title);
|
|
128
|
+
row = row.replace(/\@row_description/gm, link.description);
|
|
129
|
+
row = row.replace(/\@row_image/gm, link.image);
|
|
130
|
+
row = row.replace(/\@row_link/gm, link.link);
|
|
131
|
+
rows.push(row);
|
|
132
|
+
}
|
|
133
|
+
});
|
|
134
|
+
data.replace(match[0], rows.join(" "));
|
|
135
|
+
}
|
|
136
|
+
res.send(data);
|
|
137
|
+
return;
|
|
138
|
+
});
|
|
139
|
+
});
|
|
101
140
|
}
|
|
102
141
|
}
|
|
103
142
|
exports.BaseApplication = BaseApplication;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"BaseApplication.js","sourceRoot":"","sources":["../src/BaseApplication.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;AAAA,sDAA0C;AAC1C,gDAAwB;AACxB,4EAA2C;AAC3C,kEAAyC;AAIzC,MAAsB,eAAe;
|
|
1
|
+
{"version":3,"file":"BaseApplication.js","sourceRoot":"","sources":["../src/BaseApplication.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;AAAA,sDAA0C;AAC1C,gDAAwB;AACxB,4CAAoB;AACpB,4EAA2C;AAC3C,kEAAyC;AAIzC,gDAAwB;AAExB,MAAsB,eAAe;IAgBjC,YAAY,KAAa,EAAE,WAAmB,EAAE,IAAY,EAAE,OAAe,EAAE,UAAkB,EAAE,cAA6B,IAAI;QAR5H,UAAK,GAA0B,EAAE,CAAC;QAUtC,IAAI,CAAC,KAAK,GAAG,KAAK,CAAC;QACnB,IAAI,CAAC,WAAW,GAAG,WAAW,CAAC;QAC/B,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC;QACjB,IAAI,CAAC,OAAO,GAAG,OAAO,CAAC;QACvB,IAAI,CAAC,UAAU,GAAG,UAAU,CAAC;QAC7B,IAAI,CAAC,WAAW,GAAG,WAAW,aAAX,WAAW,cAAX,WAAW,GAAI,CAAC,UAAU,GAAG,UAAU,CAAC,CAAC;QAC5D,IAAI,CAAC,MAAM,GAAG,IAAI,CAAC,SAAS,EAAE,CAAC;IACnC,CAAC;IACD,OAAO,CAAC,IAAyB;QAE7B,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;IAC1B,CAAC;IACD,KAAK;QAED,IAAI,CAAC,iBAAiB,EAAE,CAAC;QACzB,IAAI,CAAC,aAAa,EAAE,CAAC;QACrB,IAAI,CAAC,WAAW,EAAE,CAAC;QACnB,IAAI,CAAC,YAAY,EAAE,CAAC;QACpB,IAAI,CAAC,aAAa,EAAE,CAAC;IACzB,CAAC;IACS,iBAAiB;QAEvB,O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AAE,IAAI,CAAC,WAAW,CAAC,CAAC;4BAC3D,GAAG,GAAG,GAAG,CAAC,OAAO,CAAC,eAAe,EAAE,IAAI,CAAC,KAAK,CAAC,CAAC;4BAC/C,GAAG,GAAG,GAAG,CAAC,OAAO,CAAC,cAAc,EAAE,IAAI,CAAC,IAAI,CAAC,CAAC;4BAC7C,IAAI,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;yBAClB;oBACL,CAAC,CAAC,CAAC;oBACH,IAAI,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC,CAAC,EAAE,IAAI,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,CAAC;iBAC1C;gBACD,GAAG,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;gBACf,OAAO;YACX,CAAC,CAAC,CAAC;QACP,CAAC,CAAC,CAAC;IACP,CAAC;CACJ;AAvJD,0CAuJC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"BaseApplicationLink.js","sourceRoot":"","sources":["../src/BaseApplicationLink.ts"],"names":[],"mappings":""}
|
package/package.json
CHANGED
package/src/BaseApplication.ts
CHANGED
|
@@ -1,16 +1,22 @@
|
|
|
1
1
|
import express, { Router } from 'express';
|
|
2
2
|
import cors from "cors";
|
|
3
|
+
import fs from "fs";
|
|
3
4
|
import swaggerUi from 'swagger-ui-express';
|
|
4
5
|
import swaggerJSDoc from 'swagger-jsdoc';
|
|
5
6
|
import { BaseDatabase } from './BaseDatabase';
|
|
6
7
|
import { ILogger } from "namirasoft-log";
|
|
8
|
+
import { BaseApplicationLink } from './BaseApplicationLink';
|
|
9
|
+
import path from 'path';
|
|
7
10
|
|
|
8
11
|
export abstract class BaseApplication<D extends BaseDatabase>
|
|
9
12
|
{
|
|
10
13
|
private title: string;
|
|
11
14
|
private description: string;
|
|
15
|
+
private logo: string;
|
|
12
16
|
private version: string;
|
|
17
|
+
private serverPath: string;
|
|
13
18
|
private swaggerPath: string;
|
|
19
|
+
private links: BaseApplicationLink[] = [];
|
|
14
20
|
public app!: express.Express;
|
|
15
21
|
public database!: D;
|
|
16
22
|
public logger: ILogger;
|
|
@@ -18,20 +24,27 @@ export abstract class BaseApplication<D extends BaseDatabase>
|
|
|
18
24
|
protected abstract getLogger(): ILogger;
|
|
19
25
|
protected abstract getRouter(): Router;
|
|
20
26
|
protected abstract getPort(): number;
|
|
21
|
-
constructor(title: string, description: string, version: string, swaggerPath: string)
|
|
27
|
+
constructor(title: string, description: string, logo: string, version: string, serverPath: string, swaggerPath: string | null = null)
|
|
22
28
|
{
|
|
23
29
|
this.title = title;
|
|
24
30
|
this.description = description;
|
|
31
|
+
this.logo = logo;
|
|
25
32
|
this.version = version;
|
|
26
|
-
this.
|
|
33
|
+
this.serverPath = serverPath;
|
|
34
|
+
this.swaggerPath = swaggerPath ?? (serverPath + "/swagger");
|
|
27
35
|
this.logger = this.getLogger();
|
|
28
36
|
}
|
|
37
|
+
addLink(link: BaseApplicationLink)
|
|
38
|
+
{
|
|
39
|
+
this.links.push(link);
|
|
40
|
+
}
|
|
29
41
|
start()
|
|
30
42
|
{
|
|
31
43
|
this.startCrashHandler();
|
|
32
44
|
this.startDatabase();
|
|
33
45
|
this.startServer();
|
|
34
46
|
this.startSwagger();
|
|
47
|
+
this.startHomePage();
|
|
35
48
|
}
|
|
36
49
|
protected startCrashHandler(): void
|
|
37
50
|
{
|
|
@@ -95,11 +108,11 @@ export abstract class BaseApplication<D extends BaseDatabase>
|
|
|
95
108
|
// email: "accounts@namirasoft.com",
|
|
96
109
|
// },
|
|
97
110
|
},
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
111
|
+
servers: [
|
|
112
|
+
{
|
|
113
|
+
url: this.serverPath,
|
|
114
|
+
},
|
|
115
|
+
],
|
|
103
116
|
},
|
|
104
117
|
apis: ['./src/route/*.ts'],
|
|
105
118
|
};
|
|
@@ -107,6 +120,43 @@ export abstract class BaseApplication<D extends BaseDatabase>
|
|
|
107
120
|
var options = {
|
|
108
121
|
explorer: true
|
|
109
122
|
};
|
|
110
|
-
this.app.use(this.swaggerPath, swaggerUi.serve, swaggerUi.setup(swaggerSpec, options));
|
|
123
|
+
this.app.use(this.swaggerPath + "/", swaggerUi.serve, swaggerUi.setup(swaggerSpec, options));
|
|
124
|
+
this.addLink({ title: "Swagger", description: this.description + " Swagger", image: "", link: this.swaggerPath + "/" });
|
|
125
|
+
}
|
|
126
|
+
protected startHomePage(): void
|
|
127
|
+
{
|
|
128
|
+
this.app.get(this.serverPath + "/", (_, res) =>
|
|
129
|
+
{
|
|
130
|
+
const htmlFilePath = path.join(__dirname, 'public/index.html');
|
|
131
|
+
fs.readFile(htmlFilePath, 'utf8', (err: any, data: string) =>
|
|
132
|
+
{
|
|
133
|
+
if (err)
|
|
134
|
+
return res.status(500).send('Error reading HTML file');
|
|
135
|
+
|
|
136
|
+
data = data.replace(/\@title/gm, this.title);
|
|
137
|
+
data = data.replace(/\@description/gm, this.description);
|
|
138
|
+
data = data.replace(/\@logo/gm, this.logo);
|
|
139
|
+
let match = /<\@row>(.*)<\/\@row>/gm.exec(data);
|
|
140
|
+
if (match)
|
|
141
|
+
{
|
|
142
|
+
let rows: string[] = [];
|
|
143
|
+
this.links.forEach(link =>
|
|
144
|
+
{
|
|
145
|
+
if (match)
|
|
146
|
+
{
|
|
147
|
+
let row = match[1];
|
|
148
|
+
row = row.replace(/\@row_title/gm, link.title);
|
|
149
|
+
row = row.replace(/\@row_description/gm, link.description);
|
|
150
|
+
row = row.replace(/\@row_image/gm, link.image);
|
|
151
|
+
row = row.replace(/\@row_link/gm, link.link);
|
|
152
|
+
rows.push(row);
|
|
153
|
+
}
|
|
154
|
+
});
|
|
155
|
+
data.replace(match[0], rows.join(" "));
|
|
156
|
+
}
|
|
157
|
+
res.send(data);
|
|
158
|
+
return;
|
|
159
|
+
});
|
|
160
|
+
});
|
|
111
161
|
}
|
|
112
162
|
}
|