namirasoft-node 1.0.1 → 1.0.2
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 +44 -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 +55 -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,29 @@ 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"));
|
|
20
21
|
class BaseApplication {
|
|
21
|
-
constructor(title, description, version, swaggerPath) {
|
|
22
|
+
constructor(title, description, logo, version, serverPath, swaggerPath = null) {
|
|
23
|
+
this.links = [];
|
|
22
24
|
this.title = title;
|
|
23
25
|
this.description = description;
|
|
26
|
+
this.logo = logo;
|
|
24
27
|
this.version = version;
|
|
25
|
-
this.
|
|
28
|
+
this.serverPath = serverPath;
|
|
29
|
+
this.swaggerPath = swaggerPath !== null && swaggerPath !== void 0 ? swaggerPath : (serverPath + "/swagger");
|
|
26
30
|
this.logger = this.getLogger();
|
|
27
31
|
}
|
|
32
|
+
addLink(link) {
|
|
33
|
+
this.links.push(link);
|
|
34
|
+
}
|
|
28
35
|
start() {
|
|
29
36
|
this.startCrashHandler();
|
|
30
37
|
this.startDatabase();
|
|
31
38
|
this.startServer();
|
|
32
39
|
this.startSwagger();
|
|
40
|
+
this.startHomePage();
|
|
33
41
|
}
|
|
34
42
|
startCrashHandler() {
|
|
35
43
|
process.on('unhandledRejection', (reason) => {
|
|
@@ -85,11 +93,11 @@ class BaseApplication {
|
|
|
85
93
|
// email: "accounts@namirasoft.com",
|
|
86
94
|
// },
|
|
87
95
|
},
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
96
|
+
servers: [
|
|
97
|
+
{
|
|
98
|
+
url: this.serverPath,
|
|
99
|
+
},
|
|
100
|
+
],
|
|
93
101
|
},
|
|
94
102
|
apis: ['./src/route/*.ts'],
|
|
95
103
|
};
|
|
@@ -97,7 +105,35 @@ class BaseApplication {
|
|
|
97
105
|
var options = {
|
|
98
106
|
explorer: true
|
|
99
107
|
};
|
|
100
|
-
this.app.use(this.swaggerPath, swagger_ui_express_1.default.serve, swagger_ui_express_1.default.setup(swaggerSpec, options));
|
|
108
|
+
this.app.use(this.swaggerPath + "/", swagger_ui_express_1.default.serve, swagger_ui_express_1.default.setup(swaggerSpec, options));
|
|
109
|
+
}
|
|
110
|
+
startHomePage() {
|
|
111
|
+
this.app.get('/', (_, res) => {
|
|
112
|
+
fs_1.default.readFile('./public/index.html', 'utf8', (err, data) => {
|
|
113
|
+
if (err)
|
|
114
|
+
return res.status(500).send('Error reading HTML file');
|
|
115
|
+
data = data.replace(/\@title/gm, this.title);
|
|
116
|
+
data = data.replace(/\@description/gm, this.description);
|
|
117
|
+
data = data.replace(/\@logo/gm, this.logo);
|
|
118
|
+
let match = /<\@row>(.*)<\/\@row>/gm.exec(data);
|
|
119
|
+
if (match) {
|
|
120
|
+
let rows = [];
|
|
121
|
+
this.links.forEach(link => {
|
|
122
|
+
if (match) {
|
|
123
|
+
let row = match[1];
|
|
124
|
+
row = row.replace(/\@row_title/gm, link.title);
|
|
125
|
+
row = row.replace(/\@row_description/gm, link.description);
|
|
126
|
+
row = row.replace(/\@row_image/gm, link.image);
|
|
127
|
+
row = row.replace(/\@row_link/gm, link.link);
|
|
128
|
+
rows.push(row);
|
|
129
|
+
}
|
|
130
|
+
});
|
|
131
|
+
data.replace(match[0], rows.join(" "));
|
|
132
|
+
}
|
|
133
|
+
res.send(data);
|
|
134
|
+
return;
|
|
135
|
+
});
|
|
136
|
+
});
|
|
101
137
|
}
|
|
102
138
|
}
|
|
103
139
|
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,kEAA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AC,CAAC,CAAC;IACP,CAAC;CACJ;AArJD,0CAqJC"}
|
|
@@ -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,21 @@
|
|
|
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';
|
|
7
9
|
|
|
8
10
|
export abstract class BaseApplication<D extends BaseDatabase>
|
|
9
11
|
{
|
|
10
12
|
private title: string;
|
|
11
13
|
private description: string;
|
|
14
|
+
private logo: string;
|
|
12
15
|
private version: string;
|
|
16
|
+
private serverPath: string;
|
|
13
17
|
private swaggerPath: string;
|
|
18
|
+
private links: BaseApplicationLink[] = [];
|
|
14
19
|
public app!: express.Express;
|
|
15
20
|
public database!: D;
|
|
16
21
|
public logger: ILogger;
|
|
@@ -18,20 +23,27 @@ export abstract class BaseApplication<D extends BaseDatabase>
|
|
|
18
23
|
protected abstract getLogger(): ILogger;
|
|
19
24
|
protected abstract getRouter(): Router;
|
|
20
25
|
protected abstract getPort(): number;
|
|
21
|
-
constructor(title: string, description: string, version: string, swaggerPath: string)
|
|
26
|
+
constructor(title: string, description: string, logo: string, version: string, serverPath: string, swaggerPath: string | null = null)
|
|
22
27
|
{
|
|
23
28
|
this.title = title;
|
|
24
29
|
this.description = description;
|
|
30
|
+
this.logo = logo;
|
|
25
31
|
this.version = version;
|
|
26
|
-
this.
|
|
32
|
+
this.serverPath = serverPath;
|
|
33
|
+
this.swaggerPath = swaggerPath ?? (serverPath + "/swagger");
|
|
27
34
|
this.logger = this.getLogger();
|
|
28
35
|
}
|
|
36
|
+
addLink(link: BaseApplicationLink)
|
|
37
|
+
{
|
|
38
|
+
this.links.push(link);
|
|
39
|
+
}
|
|
29
40
|
start()
|
|
30
41
|
{
|
|
31
42
|
this.startCrashHandler();
|
|
32
43
|
this.startDatabase();
|
|
33
44
|
this.startServer();
|
|
34
45
|
this.startSwagger();
|
|
46
|
+
this.startHomePage();
|
|
35
47
|
}
|
|
36
48
|
protected startCrashHandler(): void
|
|
37
49
|
{
|
|
@@ -95,11 +107,11 @@ export abstract class BaseApplication<D extends BaseDatabase>
|
|
|
95
107
|
// email: "accounts@namirasoft.com",
|
|
96
108
|
// },
|
|
97
109
|
},
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
110
|
+
servers: [
|
|
111
|
+
{
|
|
112
|
+
url: this.serverPath,
|
|
113
|
+
},
|
|
114
|
+
],
|
|
103
115
|
},
|
|
104
116
|
apis: ['./src/route/*.ts'],
|
|
105
117
|
};
|
|
@@ -107,6 +119,41 @@ export abstract class BaseApplication<D extends BaseDatabase>
|
|
|
107
119
|
var options = {
|
|
108
120
|
explorer: true
|
|
109
121
|
};
|
|
110
|
-
this.app.use(this.swaggerPath, swaggerUi.serve, swaggerUi.setup(swaggerSpec, options));
|
|
122
|
+
this.app.use(this.swaggerPath + "/", swaggerUi.serve, swaggerUi.setup(swaggerSpec, options));
|
|
123
|
+
}
|
|
124
|
+
protected startHomePage(): void
|
|
125
|
+
{
|
|
126
|
+
this.app.get('/', (_, res) =>
|
|
127
|
+
{
|
|
128
|
+
fs.readFile('./public/index.html', 'utf8', (err: any, data: string) =>
|
|
129
|
+
{
|
|
130
|
+
if (err)
|
|
131
|
+
return res.status(500).send('Error reading HTML file');
|
|
132
|
+
|
|
133
|
+
data = data.replace(/\@title/gm, this.title);
|
|
134
|
+
data = data.replace(/\@description/gm, this.description);
|
|
135
|
+
data = data.replace(/\@logo/gm, this.logo);
|
|
136
|
+
let match = /<\@row>(.*)<\/\@row>/gm.exec(data);
|
|
137
|
+
if (match)
|
|
138
|
+
{
|
|
139
|
+
let rows: string[] = [];
|
|
140
|
+
this.links.forEach(link =>
|
|
141
|
+
{
|
|
142
|
+
if (match)
|
|
143
|
+
{
|
|
144
|
+
let row = match[1];
|
|
145
|
+
row = row.replace(/\@row_title/gm, link.title);
|
|
146
|
+
row = row.replace(/\@row_description/gm, link.description);
|
|
147
|
+
row = row.replace(/\@row_image/gm, link.image);
|
|
148
|
+
row = row.replace(/\@row_link/gm, link.link);
|
|
149
|
+
rows.push(row);
|
|
150
|
+
}
|
|
151
|
+
});
|
|
152
|
+
data.replace(match[0], rows.join(" "));
|
|
153
|
+
}
|
|
154
|
+
res.send(data);
|
|
155
|
+
return;
|
|
156
|
+
});
|
|
157
|
+
});
|
|
111
158
|
}
|
|
112
159
|
}
|