@naturalcycles/backend-lib 4.19.0 → 4.19.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/admin/login.html +1 -1
- package/dist/db/httpDB.d.ts +1 -1
- package/dist/db/httpDB.js +1 -1
- package/dist/deploy/deploy.model.d.ts +2 -1
- package/dist/deploy/deploy.util.js +1 -1
- package/dist/deploy/deployHealthCheck.js +5 -6
- package/dist/deploy/deployPrepare.js +4 -6
- package/dist/server/appEngineLogMiddleware.js +2 -3
- package/dist/server/createDefaultApp.js +1 -1
- package/dist/server/createDefaultApp.model.d.ts +1 -1
- package/dist/server/serverStatusMiddleware.js +1 -1
- package/dist/server/validateMiddleware.d.ts +1 -1
- package/dist/server/zodValidateMiddleware.d.ts +1 -1
- package/dist/testing/express.test.service.js +6 -4
- package/package.json +2 -5
- package/readme.md +1 -1
- package/src/admin/base.admin.service.ts +4 -1
- package/src/admin/login.html +1 -1
- package/src/db/httpDB.ts +7 -7
- package/src/deploy/deploy.model.ts +3 -1
- package/src/deploy/deploy.util.ts +15 -12
- package/src/deploy/deployHealthCheck.ts +1 -2
- package/src/deploy/deployPrepare.ts +1 -3
- package/src/sentry/sentry.shared.service.ts +2 -0
- package/src/server/appEngineLogMiddleware.ts +1 -2
- package/src/server/asyncLocalStorageMiddleware.ts +1 -1
- package/src/server/createDefaultApp.model.ts +1 -1
- package/src/server/createDefaultApp.ts +2 -2
- package/src/server/serverStatusMiddleware.ts +2 -2
- package/src/server/validateMiddleware.ts +1 -1
- package/src/server/zodValidateMiddleware.ts +1 -1
- package/src/testing/express.test.service.ts +7 -12
package/dist/admin/login.html
CHANGED
package/dist/db/httpDB.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { FetcherOptions, JsonSchemaRootObject, ObjectWithId } from '@naturalcycles/js-lib';
|
|
2
1
|
import { BaseCommonDB, CommonDB, CommonDBOptions, CommonDBSaveOptions, CommonDBStreamOptions, DBQuery, RunQueryResult } from '@naturalcycles/db-lib';
|
|
2
|
+
import { FetcherOptions, JsonSchemaRootObject, ObjectWithId } from '@naturalcycles/js-lib';
|
|
3
3
|
import { ReadableTyped } from '@naturalcycles/nodejs-lib';
|
|
4
4
|
export interface HttpDBCfg extends FetcherOptions {
|
|
5
5
|
baseUrl: string;
|
package/dist/db/httpDB.js
CHANGED
|
@@ -2,8 +2,8 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.HttpDB = void 0;
|
|
4
4
|
const node_stream_1 = require("node:stream");
|
|
5
|
-
const js_lib_1 = require("@naturalcycles/js-lib");
|
|
6
5
|
const db_lib_1 = require("@naturalcycles/db-lib");
|
|
6
|
+
const js_lib_1 = require("@naturalcycles/js-lib");
|
|
7
7
|
/**
|
|
8
8
|
* Implementation of CommonDB that proxies all requests via HTTP to "httpDBRequestHandler".
|
|
9
9
|
*/
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { UnixTimestampNumber } from '@naturalcycles/js-lib';
|
|
1
2
|
export interface DeployInfo {
|
|
2
3
|
gaeProject: string;
|
|
3
4
|
gaeService: string;
|
|
@@ -10,7 +11,7 @@ export interface DeployInfo {
|
|
|
10
11
|
/**
|
|
11
12
|
* Unix timestamp of deployInfo.json being generated.
|
|
12
13
|
*/
|
|
13
|
-
ts:
|
|
14
|
+
ts: UnixTimestampNumber;
|
|
14
15
|
}
|
|
15
16
|
export interface AppYaml extends Record<string, any> {
|
|
16
17
|
runtime: string;
|
|
@@ -35,7 +35,7 @@ exports.createAndSaveDeployInfo = createAndSaveDeployInfo;
|
|
|
35
35
|
async function createDeployInfo(backendCfg) {
|
|
36
36
|
const simpleGit = require('simple-git'); // lazy load
|
|
37
37
|
const git = simpleGit('.');
|
|
38
|
-
const now = (0, js_lib_1.
|
|
38
|
+
const now = (0, js_lib_1.localTimeNow)();
|
|
39
39
|
const gitBranch = (await git.status()).current;
|
|
40
40
|
const gitRev = (await git.revparse(['HEAD'])).slice(0, 7);
|
|
41
41
|
let { gaeProject, gaeProjectByBranch = {}, gaeService, gaeServiceByBranch = {}, serviceWithBranchName, prodBranch, branchesWithTimestampVersions = [], } = backendCfg;
|
|
@@ -2,9 +2,8 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.deployHealthCheck = exports.deployHealthCheckYargsOptions = void 0;
|
|
4
4
|
const node_util_1 = require("node:util");
|
|
5
|
-
const nodejs_lib_1 = require("@naturalcycles/nodejs-lib");
|
|
6
5
|
const js_lib_1 = require("@naturalcycles/js-lib");
|
|
7
|
-
const
|
|
6
|
+
const nodejs_lib_1 = require("@naturalcycles/nodejs-lib");
|
|
8
7
|
const request_log_util_1 = require("../server/request.log.util");
|
|
9
8
|
exports.deployHealthCheckYargsOptions = {
|
|
10
9
|
thresholdHealthy: {
|
|
@@ -70,7 +69,7 @@ async function deployHealthCheck(url, opt = {}) {
|
|
|
70
69
|
await makeAttempt();
|
|
71
70
|
}
|
|
72
71
|
if (failed) {
|
|
73
|
-
console.log((0,
|
|
72
|
+
console.log((0, nodejs_lib_1.red)(`Health check failed!`));
|
|
74
73
|
if (logOnFailure) {
|
|
75
74
|
try {
|
|
76
75
|
(0, nodejs_lib_1.execVoidCommandSync)(`gcloud app logs read --project ${gaeProject} --service ${gaeService} --version ${gaeVersion}`, [], { shell: true });
|
|
@@ -87,7 +86,7 @@ async function deployHealthCheck(url, opt = {}) {
|
|
|
87
86
|
}
|
|
88
87
|
async function makeAttempt() {
|
|
89
88
|
attempt++;
|
|
90
|
-
console.log([`>>`, (0,
|
|
89
|
+
console.log([`>>`, (0, nodejs_lib_1.dimGrey)(url), (0, node_util_1.inspect)({ attempt }, inspectOpt)].join(' '));
|
|
91
90
|
const started = Date.now();
|
|
92
91
|
const { err, statusCode = 0 } = await fetcher.doFetch({
|
|
93
92
|
url,
|
|
@@ -123,7 +122,7 @@ async function deployHealthCheck(url, opt = {}) {
|
|
|
123
122
|
console.log([
|
|
124
123
|
`<< HTTP`,
|
|
125
124
|
(0, request_log_util_1.coloredHttpCode)(statusCode),
|
|
126
|
-
(0,
|
|
125
|
+
(0, nodejs_lib_1.dimGrey)((0, js_lib_1._since)(started)),
|
|
127
126
|
(0, node_util_1.inspect)((0, js_lib_1._filterFalsyValues)({ countHealthy, countUnhealthy }), inspectOpt),
|
|
128
127
|
].join(' '));
|
|
129
128
|
if (attempt >= maxTries) {
|
|
@@ -135,7 +134,7 @@ async function deployHealthCheck(url, opt = {}) {
|
|
|
135
134
|
console.log(doneReason);
|
|
136
135
|
}
|
|
137
136
|
else {
|
|
138
|
-
console.log((0,
|
|
137
|
+
console.log((0, nodejs_lib_1.dimGrey)(`... waiting ${(0, js_lib_1._ms)(currentInterval)} ...`));
|
|
139
138
|
await (0, js_lib_1.pDelay)(currentInterval);
|
|
140
139
|
}
|
|
141
140
|
}
|
|
@@ -2,8 +2,6 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.deployPrepare = exports.deployPrepareYargsOptions = void 0;
|
|
4
4
|
const nodejs_lib_1 = require("@naturalcycles/nodejs-lib");
|
|
5
|
-
const nodejs_lib_2 = require("@naturalcycles/nodejs-lib");
|
|
6
|
-
const nodejs_lib_3 = require("@naturalcycles/nodejs-lib");
|
|
7
5
|
const paths_cnst_1 = require("../paths.cnst");
|
|
8
6
|
const backend_cfg_util_1 = require("./backend.cfg.util");
|
|
9
7
|
const deploy_util_1 = require("./deploy.util");
|
|
@@ -58,15 +56,15 @@ async function deployPrepare(opt = {}) {
|
|
|
58
56
|
const backendCfg = (0, backend_cfg_util_1.getBackendCfg)(projectDir);
|
|
59
57
|
const inputPatterns = backendCfg.files || DEFAULT_FILES;
|
|
60
58
|
const appYamlPassEnv = opt.appYamlPassEnv || backendCfg.appYamlPassEnv;
|
|
61
|
-
console.log(`1. Copy files to ${(0,
|
|
59
|
+
console.log(`1. Copy files to ${(0, nodejs_lib_1.dimGrey)(targetDir)}`);
|
|
62
60
|
// Clean targetDir
|
|
63
61
|
(0, nodejs_lib_1._emptyDirSync)(targetDir);
|
|
64
|
-
(0,
|
|
62
|
+
(0, nodejs_lib_1.kpySync)({
|
|
65
63
|
baseDir: defaultFilesDir,
|
|
66
64
|
outputDir: targetDir,
|
|
67
65
|
dotfiles: true,
|
|
68
66
|
});
|
|
69
|
-
(0,
|
|
67
|
+
(0, nodejs_lib_1.kpySync)({
|
|
70
68
|
baseDir: projectDir,
|
|
71
69
|
inputPatterns,
|
|
72
70
|
outputDir: targetDir,
|
|
@@ -78,7 +76,7 @@ async function deployPrepare(opt = {}) {
|
|
|
78
76
|
const npmrc = `//registry.npmjs.org/:_authToken=${NPM_TOKEN}`;
|
|
79
77
|
(0, nodejs_lib_1._writeFileSync)(npmrcPath, npmrc);
|
|
80
78
|
}
|
|
81
|
-
console.log(`2. Generate ${(0,
|
|
79
|
+
console.log(`2. Generate ${(0, nodejs_lib_1.dimGrey)('deployInfo.json')} and ${(0, nodejs_lib_1.dimGrey)('app.yaml')} in targetDir`);
|
|
82
80
|
const deployInfo = await (0, deploy_util_1.createAndSaveDeployInfo)(backendCfg, targetDir);
|
|
83
81
|
(0, deploy_util_1.createAndSaveAppYaml)(backendCfg, deployInfo, projectDir, targetDir, appYamlPassEnv);
|
|
84
82
|
return deployInfo;
|
|
@@ -3,7 +3,6 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.appEngineLogMiddleware = exports.ciLogger = exports.devLogger = exports.gaeLogger = void 0;
|
|
4
4
|
const node_util_1 = require("node:util");
|
|
5
5
|
const nodejs_lib_1 = require("@naturalcycles/nodejs-lib");
|
|
6
|
-
const nodejs_lib_2 = require("@naturalcycles/nodejs-lib");
|
|
7
6
|
const { GOOGLE_CLOUD_PROJECT, GAE_INSTANCE } = process.env;
|
|
8
7
|
const isGAE = !!GAE_INSTANCE;
|
|
9
8
|
// Simple "request counter" (poor man's "correlation id") counter, to use on dev machine (not in the cloud)
|
|
@@ -45,7 +44,7 @@ function logToDev(requestId, args) {
|
|
|
45
44
|
// Run on local machine
|
|
46
45
|
console.log([
|
|
47
46
|
requestId ? [(0, nodejs_lib_1.dimGrey)(`[${requestId}]`)] : [],
|
|
48
|
-
...args.map(a => (0,
|
|
47
|
+
...args.map(a => (0, nodejs_lib_1.inspectAny)(a, { includeErrorStack: true, colors: true })),
|
|
49
48
|
].join(' '));
|
|
50
49
|
}
|
|
51
50
|
/**
|
|
@@ -53,7 +52,7 @@ function logToDev(requestId, args) {
|
|
|
53
52
|
* This is to not confuse e.g Sentry when it picks up messages with colors
|
|
54
53
|
*/
|
|
55
54
|
function logToCI(args) {
|
|
56
|
-
console.log(args.map(a => (0,
|
|
55
|
+
console.log(args.map(a => (0, nodejs_lib_1.inspectAny)(a, { includeErrorStack: true, colors: false })).join(' '));
|
|
57
56
|
}
|
|
58
57
|
function appEngineLogMiddleware() {
|
|
59
58
|
if (!isGAE || !GOOGLE_CLOUD_PROJECT) {
|
|
@@ -5,8 +5,8 @@ const cookieParser = require("cookie-parser");
|
|
|
5
5
|
const cors = require("cors");
|
|
6
6
|
const express = require("express");
|
|
7
7
|
const __1 = require("..");
|
|
8
|
-
const asyncLocalStorageMiddleware_1 = require("./asyncLocalStorageMiddleware");
|
|
9
8
|
const appEngineLogMiddleware_1 = require("./appEngineLogMiddleware");
|
|
9
|
+
const asyncLocalStorageMiddleware_1 = require("./asyncLocalStorageMiddleware");
|
|
10
10
|
const genericErrorMiddleware_1 = require("./genericErrorMiddleware");
|
|
11
11
|
const notFoundMiddleware_1 = require("./notFoundMiddleware");
|
|
12
12
|
const requestTimeoutMiddleware_1 = require("./requestTimeoutMiddleware");
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { Options, OptionsJson, OptionsUrlencoded } from 'body-parser';
|
|
2
2
|
import { CorsOptions } from 'cors';
|
|
3
3
|
import { SentrySharedService } from '../sentry/sentry.shared.service';
|
|
4
|
-
import { BackendRequestHandler } from './server.model';
|
|
5
4
|
import { GenericErrorMiddlewareCfg } from './genericErrorMiddleware';
|
|
5
|
+
import { BackendRequestHandler } from './server.model';
|
|
6
6
|
/**
|
|
7
7
|
* Plain RequestHandler can be provided - then it's mounted to /
|
|
8
8
|
* Otherwise `path` can be provided to specify mounting point.
|
|
@@ -37,6 +37,6 @@ function getServerStatusData(projectDir = process.cwd(), extra) {
|
|
|
37
37
|
}
|
|
38
38
|
exports.getServerStatusData = getServerStatusData;
|
|
39
39
|
function getStartedStr() {
|
|
40
|
-
const started = (0, js_lib_1.
|
|
40
|
+
const started = (0, js_lib_1.localTimeNow)().subtract(process.uptime(), 'second');
|
|
41
41
|
return `${started.toPretty()} (${started.fromNow()})`;
|
|
42
42
|
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { JsonSchema, JsonSchemaBuilder } from '@naturalcycles/js-lib';
|
|
2
2
|
import { AjvSchema, AjvValidationError } from '@naturalcycles/nodejs-lib';
|
|
3
|
-
import { BackendRequestHandler } from './server.model';
|
|
4
3
|
import { ReqValidationOptions } from './reqValidationMiddleware';
|
|
4
|
+
import { BackendRequestHandler } from './server.model';
|
|
5
5
|
export declare function validateBody(schema: JsonSchema | JsonSchemaBuilder | AjvSchema, opt?: ReqValidationOptions<AjvValidationError>): BackendRequestHandler;
|
|
6
6
|
export declare function validateParams(schema: JsonSchema | JsonSchemaBuilder | AjvSchema, opt?: ReqValidationOptions<AjvValidationError>): BackendRequestHandler;
|
|
7
7
|
export declare function validateQuery(schema: JsonSchema | JsonSchemaBuilder | AjvSchema, opt?: ReqValidationOptions<AjvValidationError>): BackendRequestHandler;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { ZodSchema, ZodValidationError } from '@naturalcycles/js-lib';
|
|
2
|
-
import { BackendRequestHandler } from './server.model';
|
|
3
2
|
import { ReqValidationOptions } from './reqValidationMiddleware';
|
|
3
|
+
import { BackendRequestHandler } from './server.model';
|
|
4
4
|
/**
|
|
5
5
|
* Validates req property (body, params or query).
|
|
6
6
|
* Supports Joi schema or AjvSchema (from nodejs-lib).
|
|
@@ -42,11 +42,13 @@ class ExpressTestService {
|
|
|
42
42
|
await (0, js_lib_1.pDelay)();
|
|
43
43
|
});
|
|
44
44
|
fetcher.close = async () => {
|
|
45
|
-
const started = Date.now()
|
|
46
|
-
await new Promise(resolve => server.close(resolve))
|
|
47
|
-
console.log(`close took ${
|
|
45
|
+
// const started = Date.now()
|
|
46
|
+
// await new Promise(resolve => server.close(resolve))
|
|
47
|
+
// console.log(`close took ${_since(started)}`) // todo: investigate why it takes ~5 seconds!
|
|
48
|
+
// Kirill: not awaiting the server-close, otherwise it takes significant waiting time
|
|
49
|
+
// to "teardown" server after it's been hit by Fetcher
|
|
50
|
+
server.close();
|
|
48
51
|
// server.destroy()
|
|
49
|
-
// await pDelay(1000)
|
|
50
52
|
};
|
|
51
53
|
return fetcher;
|
|
52
54
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@naturalcycles/backend-lib",
|
|
3
|
-
"version": "4.19.
|
|
3
|
+
"version": "4.19.2",
|
|
4
4
|
"scripts": {
|
|
5
5
|
"prepare": "husky install",
|
|
6
6
|
"serve": "APP_ENV=dev nodemon",
|
|
@@ -46,10 +46,7 @@
|
|
|
46
46
|
"@types/yargs": "^16.0.0",
|
|
47
47
|
"fastify": "^4.0.0",
|
|
48
48
|
"jest": "^29.0.1",
|
|
49
|
-
"nodemon": "^3.0.1"
|
|
50
|
-
"vue-class-component": "^7.2.6",
|
|
51
|
-
"vuepress": "^1.7.1",
|
|
52
|
-
"vuepress-plugin-typescript": "^0.3.1"
|
|
49
|
+
"nodemon": "^3.0.1"
|
|
53
50
|
},
|
|
54
51
|
"files": [
|
|
55
52
|
"dist",
|
package/readme.md
CHANGED
|
@@ -6,7 +6,7 @@
|
|
|
6
6
|
[](https://codeclimate.com/github/NaturalCycles/backend-lib/maintainability)
|
|
7
7
|
[](https://codeclimate.com/github/NaturalCycles/backend-lib/test_coverage)
|
|
8
8
|
[](https://github.com/prettier/prettier)
|
|
9
|
-
[](https://github.com/NaturalCycles/backend-lib/actions)
|
|
10
10
|
|
|
11
11
|
# [Documentation](https://naturalcycles.github.io/backend-lib/)
|
|
12
12
|
|
|
@@ -31,7 +31,10 @@ const adminInfoDisabled = (): AdminInfo => ({
|
|
|
31
31
|
* Base implementation based on Firebase Auth tokens passed as 'admin_token' cookie.
|
|
32
32
|
*/
|
|
33
33
|
export class BaseAdminService {
|
|
34
|
-
constructor(
|
|
34
|
+
constructor(
|
|
35
|
+
private firebaseAuth: FirebaseAdmin.auth.Auth,
|
|
36
|
+
cfg: AdminServiceCfg,
|
|
37
|
+
) {
|
|
35
38
|
this.cfg = {
|
|
36
39
|
adminTokenKey: 'admin_token',
|
|
37
40
|
authEnabled: true,
|
package/src/admin/login.html
CHANGED
package/src/db/httpDB.ts
CHANGED
|
@@ -1,11 +1,4 @@
|
|
|
1
1
|
import { Readable } from 'node:stream'
|
|
2
|
-
import {
|
|
3
|
-
Fetcher,
|
|
4
|
-
FetcherOptions,
|
|
5
|
-
getFetcher,
|
|
6
|
-
JsonSchemaRootObject,
|
|
7
|
-
ObjectWithId,
|
|
8
|
-
} from '@naturalcycles/js-lib'
|
|
9
2
|
import {
|
|
10
3
|
BaseCommonDB,
|
|
11
4
|
CommonDB,
|
|
@@ -15,6 +8,13 @@ import {
|
|
|
15
8
|
DBQuery,
|
|
16
9
|
RunQueryResult,
|
|
17
10
|
} from '@naturalcycles/db-lib'
|
|
11
|
+
import {
|
|
12
|
+
Fetcher,
|
|
13
|
+
FetcherOptions,
|
|
14
|
+
getFetcher,
|
|
15
|
+
JsonSchemaRootObject,
|
|
16
|
+
ObjectWithId,
|
|
17
|
+
} from '@naturalcycles/js-lib'
|
|
18
18
|
import { ReadableTyped } from '@naturalcycles/nodejs-lib'
|
|
19
19
|
|
|
20
20
|
export interface HttpDBCfg extends FetcherOptions {
|
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
import { UnixTimestampNumber } from '@naturalcycles/js-lib'
|
|
2
|
+
|
|
1
3
|
export interface DeployInfo {
|
|
2
4
|
gaeProject: string
|
|
3
5
|
gaeService: string
|
|
@@ -11,7 +13,7 @@ export interface DeployInfo {
|
|
|
11
13
|
/**
|
|
12
14
|
* Unix timestamp of deployInfo.json being generated.
|
|
13
15
|
*/
|
|
14
|
-
ts:
|
|
16
|
+
ts: UnixTimestampNumber
|
|
15
17
|
}
|
|
16
18
|
|
|
17
19
|
export interface AppYaml extends Record<string, any> {
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import fs from 'node:fs'
|
|
2
|
-
import { _mapValues, _merge, _truncate,
|
|
2
|
+
import { _mapValues, _merge, _truncate, localTimeNow } from '@naturalcycles/js-lib'
|
|
3
3
|
import { dimGrey, white } from '@naturalcycles/nodejs-lib'
|
|
4
4
|
import yaml from 'js-yaml'
|
|
5
5
|
import { BackendCfg } from './backend.cfg.util'
|
|
@@ -42,7 +42,7 @@ export async function createDeployInfo(backendCfg: BackendCfg): Promise<DeployIn
|
|
|
42
42
|
const simpleGit = require('simple-git') // lazy load
|
|
43
43
|
const git = simpleGit('.')
|
|
44
44
|
|
|
45
|
-
const now =
|
|
45
|
+
const now = localTimeNow()
|
|
46
46
|
const gitBranch = (await git.status()).current!
|
|
47
47
|
const gitRev = (await git.revparse(['HEAD'])).slice(0, 7)
|
|
48
48
|
|
|
@@ -151,16 +151,19 @@ export function createAppYaml(
|
|
|
151
151
|
.split(',')
|
|
152
152
|
.filter(Boolean)
|
|
153
153
|
// eslint-disable-next-line unicorn/no-array-reduce
|
|
154
|
-
.reduce(
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
154
|
+
.reduce(
|
|
155
|
+
(map, key) => {
|
|
156
|
+
const v = process.env[key]
|
|
157
|
+
if (!v) {
|
|
158
|
+
throw new Error(
|
|
159
|
+
`appYamlPassEnv.${key} is requested, but process.env.${key} is not defined!`,
|
|
160
|
+
)
|
|
161
|
+
}
|
|
162
|
+
map[key] = v
|
|
163
|
+
return map
|
|
164
|
+
},
|
|
165
|
+
{} as Record<string, string>,
|
|
166
|
+
)
|
|
164
167
|
|
|
165
168
|
if (Object.keys(passEnv).length) {
|
|
166
169
|
console.log(
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import { inspect, InspectOptions } from 'node:util'
|
|
2
|
-
import { execVoidCommandSync } from '@naturalcycles/nodejs-lib'
|
|
3
2
|
import { pDelay, _filterFalsyValues, _ms, _since, getFetcher } from '@naturalcycles/js-lib'
|
|
4
|
-
import { dimGrey, red } from '@naturalcycles/nodejs-lib'
|
|
3
|
+
import { execVoidCommandSync, dimGrey, red } from '@naturalcycles/nodejs-lib'
|
|
5
4
|
import { coloredHttpCode } from '../server/request.log.util'
|
|
6
5
|
|
|
7
6
|
export interface DeployHealthCheckOptions {
|
|
@@ -1,6 +1,4 @@
|
|
|
1
|
-
import { _emptyDirSync, _writeFileSync } from '@naturalcycles/nodejs-lib'
|
|
2
|
-
import { dimGrey } from '@naturalcycles/nodejs-lib'
|
|
3
|
-
import { kpySync } from '@naturalcycles/nodejs-lib'
|
|
1
|
+
import { _emptyDirSync, _writeFileSync, dimGrey, kpySync } from '@naturalcycles/nodejs-lib'
|
|
4
2
|
import { srcDir } from '../paths.cnst'
|
|
5
3
|
import { getBackendCfg } from './backend.cfg.util'
|
|
6
4
|
import { DeployInfo } from './deploy.model'
|
|
@@ -6,7 +6,9 @@ import {
|
|
|
6
6
|
CommonLogLevel,
|
|
7
7
|
} from '@naturalcycles/js-lib'
|
|
8
8
|
import { inspectAny, InspectAnyOptions } from '@naturalcycles/nodejs-lib'
|
|
9
|
+
// eslint-disable-next-line import/no-duplicates
|
|
9
10
|
import type { Breadcrumb, NodeOptions, SeverityLevel } from '@sentry/node'
|
|
11
|
+
// eslint-disable-next-line import/no-duplicates
|
|
10
12
|
import type * as SentryLib from '@sentry/node'
|
|
11
13
|
import { BackendErrorRequestHandler, BackendRequestHandler, getRequestLogger } from '../index'
|
|
12
14
|
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import { inspect } from 'node:util'
|
|
2
|
-
import { dimGrey } from '@naturalcycles/nodejs-lib'
|
|
3
|
-
import { inspectAny } from '@naturalcycles/nodejs-lib'
|
|
4
2
|
import { AnyObject, CommonLogger } from '@naturalcycles/js-lib'
|
|
3
|
+
import { dimGrey, inspectAny } from '@naturalcycles/nodejs-lib'
|
|
5
4
|
import { BackendRequestHandler } from './server.model'
|
|
6
5
|
|
|
7
6
|
const { GOOGLE_CLOUD_PROJECT, GAE_INSTANCE } = process.env
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { AsyncLocalStorage } from 'node:async_hooks'
|
|
2
2
|
import { _lazyValue, CommonLogger } from '@naturalcycles/js-lib'
|
|
3
|
-
import { BackendRequest, BackendRequestHandler } from './server.model'
|
|
4
3
|
import { gaeLogger, devLogger, ciLogger } from './appEngineLogMiddleware'
|
|
4
|
+
import { BackendRequest, BackendRequestHandler } from './server.model'
|
|
5
5
|
|
|
6
6
|
const { GAE_INSTANCE, CI } = process.env
|
|
7
7
|
const isGAE = !!GAE_INSTANCE
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { Options, OptionsJson, OptionsUrlencoded } from 'body-parser'
|
|
2
2
|
import { CorsOptions } from 'cors'
|
|
3
3
|
import { SentrySharedService } from '../sentry/sentry.shared.service'
|
|
4
|
-
import { BackendRequestHandler } from './server.model'
|
|
5
4
|
import { GenericErrorMiddlewareCfg } from './genericErrorMiddleware'
|
|
5
|
+
import { BackendRequestHandler } from './server.model'
|
|
6
6
|
|
|
7
7
|
/**
|
|
8
8
|
* Plain RequestHandler can be provided - then it's mounted to /
|
|
@@ -2,13 +2,13 @@ import cookieParser = require('cookie-parser')
|
|
|
2
2
|
import cors = require('cors')
|
|
3
3
|
import express = require('express')
|
|
4
4
|
import { BackendApplication, isGAE, methodOverrideMiddleware } from '..'
|
|
5
|
+
import { appEngineLogMiddleware } from './appEngineLogMiddleware'
|
|
6
|
+
import { asyncLocalStorageMiddleware } from './asyncLocalStorageMiddleware'
|
|
5
7
|
import {
|
|
6
8
|
DefaultAppCfg,
|
|
7
9
|
BackendRequestHandlerCfg,
|
|
8
10
|
BackendRequestHandlerWithPath,
|
|
9
11
|
} from './createDefaultApp.model'
|
|
10
|
-
import { asyncLocalStorageMiddleware } from './asyncLocalStorageMiddleware'
|
|
11
|
-
import { appEngineLogMiddleware } from './appEngineLogMiddleware'
|
|
12
12
|
import { genericErrorMiddleware } from './genericErrorMiddleware'
|
|
13
13
|
import { notFoundMiddleware } from './notFoundMiddleware'
|
|
14
14
|
import { requestTimeoutMiddleware } from './requestTimeoutMiddleware'
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { _filterNullishValues, localTime } from '@naturalcycles/js-lib'
|
|
1
|
+
import { _filterNullishValues, localTime, localTimeNow } from '@naturalcycles/js-lib'
|
|
2
2
|
import { memoryUsageFull, processSharedUtil } from '@naturalcycles/nodejs-lib'
|
|
3
3
|
import { getDeployInfo } from './deployInfo.util'
|
|
4
4
|
import { BackendRequestHandler } from './server.model'
|
|
@@ -41,6 +41,6 @@ export function getServerStatusData(
|
|
|
41
41
|
}
|
|
42
42
|
|
|
43
43
|
function getStartedStr(): string {
|
|
44
|
-
const started =
|
|
44
|
+
const started = localTimeNow().subtract(process.uptime(), 'second')
|
|
45
45
|
return `${started.toPretty()} (${started.fromNow()})`
|
|
46
46
|
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { JsonSchema, JsonSchemaBuilder, _get, AppError } from '@naturalcycles/js-lib'
|
|
2
2
|
import { AjvSchema, AjvValidationError } from '@naturalcycles/nodejs-lib'
|
|
3
|
-
import { BackendRequestHandler } from './server.model'
|
|
4
3
|
import { ReqValidationOptions } from './reqValidationMiddleware'
|
|
4
|
+
import { BackendRequestHandler } from './server.model'
|
|
5
5
|
|
|
6
6
|
const REDACTED = 'REDACTED'
|
|
7
7
|
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { _get, AppError, ZodSchema, ZodValidationError, zSafeValidate } from '@naturalcycles/js-lib'
|
|
2
|
-
import { BackendRequestHandler } from './server.model'
|
|
3
2
|
import { ReqValidationOptions } from './reqValidationMiddleware'
|
|
3
|
+
import { BackendRequestHandler } from './server.model'
|
|
4
4
|
|
|
5
5
|
const REDACTED = 'REDACTED'
|
|
6
6
|
|
|
@@ -1,13 +1,6 @@
|
|
|
1
1
|
import { Server } from 'node:http'
|
|
2
2
|
import { AddressInfo } from 'node:net'
|
|
3
|
-
import {
|
|
4
|
-
_since,
|
|
5
|
-
Fetcher,
|
|
6
|
-
FetcherOptions,
|
|
7
|
-
FetchFunction,
|
|
8
|
-
getFetcher,
|
|
9
|
-
pDelay,
|
|
10
|
-
} from '@naturalcycles/js-lib'
|
|
3
|
+
import { Fetcher, FetcherOptions, FetchFunction, getFetcher, pDelay } from '@naturalcycles/js-lib'
|
|
11
4
|
import { BackendApplication, createDefaultApp, DefaultAppCfg } from '../index'
|
|
12
5
|
import { BackendRequestHandlerCfg } from '../server/createDefaultApp.model'
|
|
13
6
|
|
|
@@ -70,11 +63,13 @@ class ExpressTestService {
|
|
|
70
63
|
}) as ExpressApp
|
|
71
64
|
|
|
72
65
|
fetcher.close = async () => {
|
|
73
|
-
const started = Date.now()
|
|
74
|
-
await new Promise(resolve => server.close(resolve))
|
|
75
|
-
console.log(`close took ${_since(started)}`) // todo: investigate why it takes ~5 seconds!
|
|
66
|
+
// const started = Date.now()
|
|
67
|
+
// await new Promise(resolve => server.close(resolve))
|
|
68
|
+
// console.log(`close took ${_since(started)}`) // todo: investigate why it takes ~5 seconds!
|
|
69
|
+
// Kirill: not awaiting the server-close, otherwise it takes significant waiting time
|
|
70
|
+
// to "teardown" server after it's been hit by Fetcher
|
|
71
|
+
server.close()
|
|
76
72
|
// server.destroy()
|
|
77
|
-
// await pDelay(1000)
|
|
78
73
|
}
|
|
79
74
|
|
|
80
75
|
return fetcher
|