@technomoron/api-server-base 1.1.11 → 1.1.13
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.
|
@@ -330,7 +330,9 @@ function fillConfig(config) {
|
|
|
330
330
|
authApi: config.authApi ?? false,
|
|
331
331
|
devMode: config.devMode ?? false,
|
|
332
332
|
hydrateGetBody: config.hydrateGetBody ?? true,
|
|
333
|
-
validateTokens: config.validateTokens ?? false
|
|
333
|
+
validateTokens: config.validateTokens ?? false,
|
|
334
|
+
apiVersion: config.apiVersion ?? '',
|
|
335
|
+
minClientVersion: config.minClientVersion ?? ''
|
|
334
336
|
};
|
|
335
337
|
}
|
|
336
338
|
class ApiServer {
|
|
@@ -339,6 +341,7 @@ class ApiServer {
|
|
|
339
341
|
this.apiNotFoundHandler = null;
|
|
340
342
|
this.config = fillConfig(config);
|
|
341
343
|
this.apiBasePath = this.normalizeApiBasePath(this.config.apiBasePath);
|
|
344
|
+
this.startedAt = Date.now();
|
|
342
345
|
this.storageAdapter = auth_storage_js_1.nullAuthStorage;
|
|
343
346
|
this.moduleAdapter = auth_module_js_1.nullAuthModule;
|
|
344
347
|
this.app = (0, express_1.default)();
|
|
@@ -347,6 +350,7 @@ class ApiServer {
|
|
|
347
350
|
this.app.use(upload.any());
|
|
348
351
|
}
|
|
349
352
|
this.middlewares();
|
|
353
|
+
this.installPingHandler();
|
|
350
354
|
// addSwaggerUi(this.app);
|
|
351
355
|
this.installApiNotFoundHandler();
|
|
352
356
|
}
|
|
@@ -497,6 +501,20 @@ class ApiServer {
|
|
|
497
501
|
};
|
|
498
502
|
this.app.use((0, cors_1.default)(corsOptions));
|
|
499
503
|
}
|
|
504
|
+
installPingHandler() {
|
|
505
|
+
const path = `${this.apiBasePath}/v1/ping`;
|
|
506
|
+
this.app.get(path, (_req, res) => {
|
|
507
|
+
const payload = {
|
|
508
|
+
status: 'ok',
|
|
509
|
+
apiVersion: this.config.apiVersion ?? '',
|
|
510
|
+
minClientVersion: this.config.minClientVersion ?? '',
|
|
511
|
+
uptimeSec: process.uptime(),
|
|
512
|
+
startedAt: this.startedAt,
|
|
513
|
+
timestamp: new Date().toISOString()
|
|
514
|
+
};
|
|
515
|
+
res.status(200).json({ code: 200, message: 'Success', data: payload });
|
|
516
|
+
});
|
|
517
|
+
}
|
|
500
518
|
normalizeApiBasePath(path) {
|
|
501
519
|
if (!path || typeof path !== 'string') {
|
|
502
520
|
return '/api';
|
|
@@ -100,11 +100,14 @@ export interface ApiServerConf {
|
|
|
100
100
|
devMode: boolean;
|
|
101
101
|
hydrateGetBody: boolean;
|
|
102
102
|
validateTokens: boolean;
|
|
103
|
+
apiVersion: string;
|
|
104
|
+
minClientVersion: string;
|
|
103
105
|
}
|
|
104
106
|
export declare class ApiServer {
|
|
105
107
|
app: Application;
|
|
106
108
|
currReq: ApiRequest | null;
|
|
107
109
|
readonly config: ApiServerConf;
|
|
110
|
+
readonly startedAt: number;
|
|
108
111
|
private readonly apiBasePath;
|
|
109
112
|
private storageAdapter;
|
|
110
113
|
private moduleAdapter;
|
|
@@ -140,6 +143,7 @@ export declare class ApiServer {
|
|
|
140
143
|
guessExceptionText(error: any, defMsg?: string): string;
|
|
141
144
|
protected authorize(apiReq: ApiRequest, requiredClass: ApiAuthClass): Promise<void>;
|
|
142
145
|
private middlewares;
|
|
146
|
+
private installPingHandler;
|
|
143
147
|
private normalizeApiBasePath;
|
|
144
148
|
private installApiNotFoundHandler;
|
|
145
149
|
private ensureApiNotFoundOrdering;
|
|
@@ -100,11 +100,14 @@ export interface ApiServerConf {
|
|
|
100
100
|
devMode: boolean;
|
|
101
101
|
hydrateGetBody: boolean;
|
|
102
102
|
validateTokens: boolean;
|
|
103
|
+
apiVersion: string;
|
|
104
|
+
minClientVersion: string;
|
|
103
105
|
}
|
|
104
106
|
export declare class ApiServer {
|
|
105
107
|
app: Application;
|
|
106
108
|
currReq: ApiRequest | null;
|
|
107
109
|
readonly config: ApiServerConf;
|
|
110
|
+
readonly startedAt: number;
|
|
108
111
|
private readonly apiBasePath;
|
|
109
112
|
private storageAdapter;
|
|
110
113
|
private moduleAdapter;
|
|
@@ -140,6 +143,7 @@ export declare class ApiServer {
|
|
|
140
143
|
guessExceptionText(error: any, defMsg?: string): string;
|
|
141
144
|
protected authorize(apiReq: ApiRequest, requiredClass: ApiAuthClass): Promise<void>;
|
|
142
145
|
private middlewares;
|
|
146
|
+
private installPingHandler;
|
|
143
147
|
private normalizeApiBasePath;
|
|
144
148
|
private installApiNotFoundHandler;
|
|
145
149
|
private ensureApiNotFoundOrdering;
|
|
@@ -322,7 +322,9 @@ function fillConfig(config) {
|
|
|
322
322
|
authApi: config.authApi ?? false,
|
|
323
323
|
devMode: config.devMode ?? false,
|
|
324
324
|
hydrateGetBody: config.hydrateGetBody ?? true,
|
|
325
|
-
validateTokens: config.validateTokens ?? false
|
|
325
|
+
validateTokens: config.validateTokens ?? false,
|
|
326
|
+
apiVersion: config.apiVersion ?? '',
|
|
327
|
+
minClientVersion: config.minClientVersion ?? ''
|
|
326
328
|
};
|
|
327
329
|
}
|
|
328
330
|
export class ApiServer {
|
|
@@ -331,6 +333,7 @@ export class ApiServer {
|
|
|
331
333
|
this.apiNotFoundHandler = null;
|
|
332
334
|
this.config = fillConfig(config);
|
|
333
335
|
this.apiBasePath = this.normalizeApiBasePath(this.config.apiBasePath);
|
|
336
|
+
this.startedAt = Date.now();
|
|
334
337
|
this.storageAdapter = nullAuthStorage;
|
|
335
338
|
this.moduleAdapter = nullAuthModule;
|
|
336
339
|
this.app = express();
|
|
@@ -339,6 +342,7 @@ export class ApiServer {
|
|
|
339
342
|
this.app.use(upload.any());
|
|
340
343
|
}
|
|
341
344
|
this.middlewares();
|
|
345
|
+
this.installPingHandler();
|
|
342
346
|
// addSwaggerUi(this.app);
|
|
343
347
|
this.installApiNotFoundHandler();
|
|
344
348
|
}
|
|
@@ -489,6 +493,20 @@ export class ApiServer {
|
|
|
489
493
|
};
|
|
490
494
|
this.app.use(cors(corsOptions));
|
|
491
495
|
}
|
|
496
|
+
installPingHandler() {
|
|
497
|
+
const path = `${this.apiBasePath}/v1/ping`;
|
|
498
|
+
this.app.get(path, (_req, res) => {
|
|
499
|
+
const payload = {
|
|
500
|
+
status: 'ok',
|
|
501
|
+
apiVersion: this.config.apiVersion ?? '',
|
|
502
|
+
minClientVersion: this.config.minClientVersion ?? '',
|
|
503
|
+
uptimeSec: process.uptime(),
|
|
504
|
+
startedAt: this.startedAt,
|
|
505
|
+
timestamp: new Date().toISOString()
|
|
506
|
+
};
|
|
507
|
+
res.status(200).json({ code: 200, message: 'Success', data: payload });
|
|
508
|
+
});
|
|
509
|
+
}
|
|
492
510
|
normalizeApiBasePath(path) {
|
|
493
511
|
if (!path || typeof path !== 'string') {
|
|
494
512
|
return '/api';
|