react-on-rails-pro-node-renderer 16.2.0-beta.10
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/CHANGELOG.md +570 -0
- package/LICENSE +98 -0
- package/LICENSE_SETUP.md +272 -0
- package/README.md +577 -0
- package/package.json +159 -0
- package/packages/node-renderer/dist/ReactOnRailsProNodeRenderer.d.ts +3 -0
- package/packages/node-renderer/dist/ReactOnRailsProNodeRenderer.d.ts.map +1 -0
- package/packages/node-renderer/dist/ReactOnRailsProNodeRenderer.js +48 -0
- package/packages/node-renderer/dist/ReactOnRailsProNodeRenderer.js.map +1 -0
- package/packages/node-renderer/dist/default-node-renderer.d.ts +2 -0
- package/packages/node-renderer/dist/default-node-renderer.d.ts.map +1 -0
- package/packages/node-renderer/dist/default-node-renderer.js +9 -0
- package/packages/node-renderer/dist/default-node-renderer.js.map +1 -0
- package/packages/node-renderer/dist/integrations/api.d.ts +29 -0
- package/packages/node-renderer/dist/integrations/api.d.ts.map +1 -0
- package/packages/node-renderer/dist/integrations/api.js +43 -0
- package/packages/node-renderer/dist/integrations/api.js.map +1 -0
- package/packages/node-renderer/dist/integrations/honeybadger.d.ts +4 -0
- package/packages/node-renderer/dist/integrations/honeybadger.d.ts.map +1 -0
- package/packages/node-renderer/dist/integrations/honeybadger.js +52 -0
- package/packages/node-renderer/dist/integrations/honeybadger.js.map +1 -0
- package/packages/node-renderer/dist/integrations/sentry.d.ts +11 -0
- package/packages/node-renderer/dist/integrations/sentry.d.ts.map +1 -0
- package/packages/node-renderer/dist/integrations/sentry.js +59 -0
- package/packages/node-renderer/dist/integrations/sentry.js.map +1 -0
- package/packages/node-renderer/dist/integrations/sentry6.d.ts +13 -0
- package/packages/node-renderer/dist/integrations/sentry6.d.ts.map +1 -0
- package/packages/node-renderer/dist/integrations/sentry6.js +43 -0
- package/packages/node-renderer/dist/integrations/sentry6.js.map +1 -0
- package/packages/node-renderer/dist/master/restartWorkers.d.ts +12 -0
- package/packages/node-renderer/dist/master/restartWorkers.d.ts.map +1 -0
- package/packages/node-renderer/dist/master/restartWorkers.js +48 -0
- package/packages/node-renderer/dist/master/restartWorkers.js.map +1 -0
- package/packages/node-renderer/dist/master.d.ts +4 -0
- package/packages/node-renderer/dist/master.d.ts.map +1 -0
- package/packages/node-renderer/dist/master.js +85 -0
- package/packages/node-renderer/dist/master.js.map +1 -0
- package/packages/node-renderer/dist/shared/configBuilder.d.ts +34 -0
- package/packages/node-renderer/dist/shared/configBuilder.d.ts.map +1 -0
- package/packages/node-renderer/dist/shared/configBuilder.js +200 -0
- package/packages/node-renderer/dist/shared/configBuilder.js.map +1 -0
- package/packages/node-renderer/dist/shared/debug.d.ts +3 -0
- package/packages/node-renderer/dist/shared/debug.d.ts.map +1 -0
- package/packages/node-renderer/dist/shared/debug.js +4 -0
- package/packages/node-renderer/dist/shared/debug.js.map +1 -0
- package/packages/node-renderer/dist/shared/errorReporter.d.ts +25 -0
- package/packages/node-renderer/dist/shared/errorReporter.d.ts.map +1 -0
- package/packages/node-renderer/dist/shared/errorReporter.js +57 -0
- package/packages/node-renderer/dist/shared/errorReporter.js.map +1 -0
- package/packages/node-renderer/dist/shared/fileExistsAsync.d.ts +3 -0
- package/packages/node-renderer/dist/shared/fileExistsAsync.d.ts.map +1 -0
- package/packages/node-renderer/dist/shared/fileExistsAsync.js +21 -0
- package/packages/node-renderer/dist/shared/fileExistsAsync.js.map +1 -0
- package/packages/node-renderer/dist/shared/licensePublicKey.d.ts +2 -0
- package/packages/node-renderer/dist/shared/licensePublicKey.d.ts.map +1 -0
- package/packages/node-renderer/dist/shared/licensePublicKey.js +23 -0
- package/packages/node-renderer/dist/shared/licensePublicKey.js.map +1 -0
- package/packages/node-renderer/dist/shared/licenseValidator.d.ts +34 -0
- package/packages/node-renderer/dist/shared/licenseValidator.d.ts.map +1 -0
- package/packages/node-renderer/dist/shared/licenseValidator.js +240 -0
- package/packages/node-renderer/dist/shared/licenseValidator.js.map +1 -0
- package/packages/node-renderer/dist/shared/locks.d.ts +13 -0
- package/packages/node-renderer/dist/shared/locks.d.ts.map +1 -0
- package/packages/node-renderer/dist/shared/locks.js +73 -0
- package/packages/node-renderer/dist/shared/locks.js.map +1 -0
- package/packages/node-renderer/dist/shared/log.d.ts +5 -0
- package/packages/node-renderer/dist/shared/log.d.ts.map +1 -0
- package/packages/node-renderer/dist/shared/log.js +56 -0
- package/packages/node-renderer/dist/shared/log.js.map +1 -0
- package/packages/node-renderer/dist/shared/packageJson.d.ts +3 -0
- package/packages/node-renderer/dist/shared/packageJson.d.ts.map +1 -0
- package/packages/node-renderer/dist/shared/packageJson.js +7 -0
- package/packages/node-renderer/dist/shared/packageJson.js.map +1 -0
- package/packages/node-renderer/dist/shared/sharedConsoleHistory.d.ts +17 -0
- package/packages/node-renderer/dist/shared/sharedConsoleHistory.d.ts.map +1 -0
- package/packages/node-renderer/dist/shared/sharedConsoleHistory.js +88 -0
- package/packages/node-renderer/dist/shared/sharedConsoleHistory.js.map +1 -0
- package/packages/node-renderer/dist/shared/tracing.d.ts +53 -0
- package/packages/node-renderer/dist/shared/tracing.d.ts.map +1 -0
- package/packages/node-renderer/dist/shared/tracing.js +39 -0
- package/packages/node-renderer/dist/shared/tracing.js.map +1 -0
- package/packages/node-renderer/dist/shared/truthy.d.ts +3 -0
- package/packages/node-renderer/dist/shared/truthy.d.ts.map +1 -0
- package/packages/node-renderer/dist/shared/truthy.js +5 -0
- package/packages/node-renderer/dist/shared/truthy.js.map +1 -0
- package/packages/node-renderer/dist/shared/utils.d.ts +45 -0
- package/packages/node-renderer/dist/shared/utils.d.ts.map +1 -0
- package/packages/node-renderer/dist/shared/utils.js +169 -0
- package/packages/node-renderer/dist/shared/utils.js.map +1 -0
- package/packages/node-renderer/dist/tsconfig.tsbuildinfo +1 -0
- package/packages/node-renderer/dist/worker/authHandler.d.ts +16 -0
- package/packages/node-renderer/dist/worker/authHandler.d.ts.map +1 -0
- package/packages/node-renderer/dist/worker/authHandler.js +21 -0
- package/packages/node-renderer/dist/worker/authHandler.js.map +1 -0
- package/packages/node-renderer/dist/worker/checkProtocolVersionHandler.d.ts +14 -0
- package/packages/node-renderer/dist/worker/checkProtocolVersionHandler.d.ts.map +1 -0
- package/packages/node-renderer/dist/worker/checkProtocolVersionHandler.js +89 -0
- package/packages/node-renderer/dist/worker/checkProtocolVersionHandler.js.map +1 -0
- package/packages/node-renderer/dist/worker/handleGracefulShutdown.d.ts +4 -0
- package/packages/node-renderer/dist/worker/handleGracefulShutdown.d.ts.map +1 -0
- package/packages/node-renderer/dist/worker/handleGracefulShutdown.js +45 -0
- package/packages/node-renderer/dist/worker/handleGracefulShutdown.js.map +1 -0
- package/packages/node-renderer/dist/worker/handleRenderRequest.d.ts +24 -0
- package/packages/node-renderer/dist/worker/handleRenderRequest.d.ts.map +1 -0
- package/packages/node-renderer/dist/worker/handleRenderRequest.js +200 -0
- package/packages/node-renderer/dist/worker/handleRenderRequest.js.map +1 -0
- package/packages/node-renderer/dist/worker/types.d.ts +6 -0
- package/packages/node-renderer/dist/worker/types.d.ts.map +1 -0
- package/packages/node-renderer/dist/worker/types.js +3 -0
- package/packages/node-renderer/dist/worker/types.js.map +1 -0
- package/packages/node-renderer/dist/worker/vm.d.ts +50 -0
- package/packages/node-renderer/dist/worker/vm.d.ts.map +1 -0
- package/packages/node-renderer/dist/worker/vm.js +297 -0
- package/packages/node-renderer/dist/worker/vm.js.map +1 -0
- package/packages/node-renderer/dist/worker.d.ts +25 -0
- package/packages/node-renderer/dist/worker.d.ts.map +1 -0
- package/packages/node-renderer/dist/worker.js +374 -0
- package/packages/node-renderer/dist/worker.js.map +1 -0
- package/readme-gen-docs.md +1 -0
- package/script/preinstall.js +31 -0
- package/spec/dummy/.nvmrc +1 -0
- package/spec/execjs-compatible-dummy/log/.keep +0 -0
- package/spec/execjs-compatible-dummy/storage/.keep +0 -0
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Isolates logic for handling render request. We don't want this module to
|
|
3
|
+
* Fastify server and its Request and Reply objects. This allows to test
|
|
4
|
+
* module in isolation and without async calls.
|
|
5
|
+
* @module worker/handleRenderRequest
|
|
6
|
+
*/
|
|
7
|
+
import { Asset, ResponseResult } from '../shared/utils';
|
|
8
|
+
export type ProvidedNewBundle = {
|
|
9
|
+
timestamp: string | number;
|
|
10
|
+
bundle: Asset;
|
|
11
|
+
};
|
|
12
|
+
/**
|
|
13
|
+
* Creates the result for the Fastify server to use.
|
|
14
|
+
* @returns Promise where the result contains { status, data, headers } to
|
|
15
|
+
* send back to the browser.
|
|
16
|
+
*/
|
|
17
|
+
export declare function handleRenderRequest({ renderingRequest, bundleTimestamp, dependencyBundleTimestamps, providedNewBundles, assetsToCopy, }: {
|
|
18
|
+
renderingRequest: string;
|
|
19
|
+
bundleTimestamp: string | number;
|
|
20
|
+
dependencyBundleTimestamps?: string[] | number[];
|
|
21
|
+
providedNewBundles?: ProvidedNewBundle[] | null;
|
|
22
|
+
assetsToCopy?: Asset[] | null;
|
|
23
|
+
}): Promise<ResponseResult>;
|
|
24
|
+
//# sourceMappingURL=handleRenderRequest.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"handleRenderRequest.d.ts","sourceRoot":"","sources":["../../src/worker/handleRenderRequest.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAQH,OAAO,EACL,KAAK,EAKL,cAAc,EAMf,MAAM,iBAAiB,CAAC;AAKzB,MAAM,MAAM,iBAAiB,GAAG;IAC9B,SAAS,EAAE,MAAM,GAAG,MAAM,CAAC;IAC3B,MAAM,EAAE,KAAK,CAAC;CACf,CAAC;AA8IF;;;;GAIG;AACH,wBAAsB,mBAAmB,CAAC,EACxC,gBAAgB,EAChB,eAAe,EACf,0BAA0B,EAC1B,kBAAkB,EAClB,YAAY,GACb,EAAE;IACD,gBAAgB,EAAE,MAAM,CAAC;IACzB,eAAe,EAAE,MAAM,GAAG,MAAM,CAAC;IACjC,0BAA0B,CAAC,EAAE,MAAM,EAAE,GAAG,MAAM,EAAE,CAAC;IACjD,kBAAkB,CAAC,EAAE,iBAAiB,EAAE,GAAG,IAAI,CAAC;IAChD,YAAY,CAAC,EAAE,KAAK,EAAE,GAAG,IAAI,CAAC;CAC/B,GAAG,OAAO,CAAC,cAAc,CAAC,CAmE1B"}
|
|
@@ -0,0 +1,200 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Isolates logic for handling render request. We don't want this module to
|
|
4
|
+
* Fastify server and its Request and Reply objects. This allows to test
|
|
5
|
+
* module in isolation and without async calls.
|
|
6
|
+
* @module worker/handleRenderRequest
|
|
7
|
+
*/
|
|
8
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
9
|
+
if (k2 === undefined) k2 = k;
|
|
10
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
11
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
12
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
13
|
+
}
|
|
14
|
+
Object.defineProperty(o, k2, desc);
|
|
15
|
+
}) : (function(o, m, k, k2) {
|
|
16
|
+
if (k2 === undefined) k2 = k;
|
|
17
|
+
o[k2] = m[k];
|
|
18
|
+
}));
|
|
19
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
20
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
21
|
+
}) : function(o, v) {
|
|
22
|
+
o["default"] = v;
|
|
23
|
+
});
|
|
24
|
+
var __importStar = (this && this.__importStar) || function (mod) {
|
|
25
|
+
if (mod && mod.__esModule) return mod;
|
|
26
|
+
var result = {};
|
|
27
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
28
|
+
__setModuleDefault(result, mod);
|
|
29
|
+
return result;
|
|
30
|
+
};
|
|
31
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
32
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
33
|
+
};
|
|
34
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
35
|
+
exports.handleRenderRequest = handleRenderRequest;
|
|
36
|
+
const cluster_1 = __importDefault(require("cluster"));
|
|
37
|
+
const path_1 = __importDefault(require("path"));
|
|
38
|
+
const promises_1 = require("fs/promises");
|
|
39
|
+
const locks_1 = require("../shared/locks");
|
|
40
|
+
const fileExistsAsync_1 = __importDefault(require("../shared/fileExistsAsync"));
|
|
41
|
+
const log_1 = __importDefault(require("../shared/log"));
|
|
42
|
+
const utils_1 = require("../shared/utils");
|
|
43
|
+
const configBuilder_1 = require("../shared/configBuilder");
|
|
44
|
+
const errorReporter = __importStar(require("../shared/errorReporter"));
|
|
45
|
+
const vm_1 = require("./vm");
|
|
46
|
+
async function prepareResult(renderingRequest, bundleFilePathPerTimestamp) {
|
|
47
|
+
try {
|
|
48
|
+
const result = await (0, vm_1.runInVM)(renderingRequest, bundleFilePathPerTimestamp, cluster_1.default);
|
|
49
|
+
let exceptionMessage = null;
|
|
50
|
+
if (!result) {
|
|
51
|
+
const error = new Error('INVALID NIL or NULL result for rendering');
|
|
52
|
+
exceptionMessage = (0, utils_1.formatExceptionMessage)(renderingRequest, error, 'INVALID result for prepareResult');
|
|
53
|
+
}
|
|
54
|
+
else if ((0, utils_1.isErrorRenderResult)(result)) {
|
|
55
|
+
({ exceptionMessage } = result);
|
|
56
|
+
}
|
|
57
|
+
if (exceptionMessage) {
|
|
58
|
+
return (0, utils_1.errorResponseResult)(exceptionMessage);
|
|
59
|
+
}
|
|
60
|
+
if ((0, utils_1.isReadableStream)(result)) {
|
|
61
|
+
return {
|
|
62
|
+
headers: { 'Cache-Control': 'public, max-age=31536000' },
|
|
63
|
+
status: 200,
|
|
64
|
+
stream: result,
|
|
65
|
+
};
|
|
66
|
+
}
|
|
67
|
+
return {
|
|
68
|
+
headers: { 'Cache-Control': 'public, max-age=31536000' },
|
|
69
|
+
status: 200,
|
|
70
|
+
data: result,
|
|
71
|
+
};
|
|
72
|
+
}
|
|
73
|
+
catch (err) {
|
|
74
|
+
const exceptionMessage = (0, utils_1.formatExceptionMessage)(renderingRequest, err, 'Unknown error calling runInVM');
|
|
75
|
+
return (0, utils_1.errorResponseResult)(exceptionMessage);
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
/**
|
|
79
|
+
* @param bundleFilePathPerTimestamp
|
|
80
|
+
* @param providedNewBundle
|
|
81
|
+
* @param renderingRequest
|
|
82
|
+
* @param assetsToCopy might be null
|
|
83
|
+
*/
|
|
84
|
+
async function handleNewBundleProvided(renderingRequest, providedNewBundle, assetsToCopy) {
|
|
85
|
+
const bundleFilePathPerTimestamp = (0, utils_1.getRequestBundleFilePath)(providedNewBundle.timestamp);
|
|
86
|
+
const bundleDirectory = path_1.default.dirname(bundleFilePathPerTimestamp);
|
|
87
|
+
await (0, promises_1.mkdir)(bundleDirectory, { recursive: true });
|
|
88
|
+
log_1.default.info('Worker received new bundle: %s', bundleFilePathPerTimestamp);
|
|
89
|
+
let lockAcquired = false;
|
|
90
|
+
let lockfileName;
|
|
91
|
+
try {
|
|
92
|
+
const { lockfileName: name, wasLockAcquired, errorMessage } = await (0, locks_1.lock)(bundleFilePathPerTimestamp);
|
|
93
|
+
lockfileName = name;
|
|
94
|
+
lockAcquired = wasLockAcquired;
|
|
95
|
+
if (!wasLockAcquired) {
|
|
96
|
+
const msg = (0, utils_1.formatExceptionMessage)(renderingRequest, errorMessage, `Failed to acquire lock ${lockfileName}. Worker: ${(0, utils_1.workerIdLabel)()}.`);
|
|
97
|
+
return (0, utils_1.errorResponseResult)(msg);
|
|
98
|
+
}
|
|
99
|
+
try {
|
|
100
|
+
log_1.default.info(`Moving uploaded file ${providedNewBundle.bundle.savedFilePath} to ${bundleFilePathPerTimestamp}`);
|
|
101
|
+
await (0, utils_1.moveUploadedAsset)(providedNewBundle.bundle, bundleFilePathPerTimestamp);
|
|
102
|
+
if (assetsToCopy) {
|
|
103
|
+
await (0, utils_1.copyUploadedAssets)(assetsToCopy, bundleDirectory);
|
|
104
|
+
}
|
|
105
|
+
log_1.default.info(`Completed moving uploaded file ${providedNewBundle.bundle.savedFilePath} to ${bundleFilePathPerTimestamp}`);
|
|
106
|
+
}
|
|
107
|
+
catch (error) {
|
|
108
|
+
const fileExists = await (0, fileExistsAsync_1.default)(bundleFilePathPerTimestamp);
|
|
109
|
+
if (!fileExists) {
|
|
110
|
+
const msg = (0, utils_1.formatExceptionMessage)(renderingRequest, error, `Unexpected error when moving the bundle from ${providedNewBundle.bundle.savedFilePath} \
|
|
111
|
+
to ${bundleFilePathPerTimestamp})`);
|
|
112
|
+
log_1.default.error(msg);
|
|
113
|
+
return (0, utils_1.errorResponseResult)(msg);
|
|
114
|
+
}
|
|
115
|
+
log_1.default.info('File exists when trying to overwrite bundle %s. Assuming bundle written by other thread', bundleFilePathPerTimestamp);
|
|
116
|
+
}
|
|
117
|
+
return undefined;
|
|
118
|
+
}
|
|
119
|
+
finally {
|
|
120
|
+
if (lockAcquired) {
|
|
121
|
+
log_1.default.info('About to unlock %s from worker %i', lockfileName, (0, utils_1.workerIdLabel)());
|
|
122
|
+
try {
|
|
123
|
+
if (lockfileName) {
|
|
124
|
+
await (0, locks_1.unlock)(lockfileName);
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
catch (error) {
|
|
128
|
+
const msg = (0, utils_1.formatExceptionMessage)(renderingRequest, error, `Error unlocking ${lockfileName} from worker ${(0, utils_1.workerIdLabel)()}.`);
|
|
129
|
+
log_1.default.warn(msg);
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
async function handleNewBundlesProvided(renderingRequest, providedNewBundles, assetsToCopy) {
|
|
135
|
+
log_1.default.info('Worker received new bundles: %s', providedNewBundles);
|
|
136
|
+
const handlingPromises = providedNewBundles.map((providedNewBundle) => handleNewBundleProvided(renderingRequest, providedNewBundle, assetsToCopy));
|
|
137
|
+
const results = await Promise.all(handlingPromises);
|
|
138
|
+
if (assetsToCopy) {
|
|
139
|
+
await (0, utils_1.deleteUploadedAssets)(assetsToCopy);
|
|
140
|
+
}
|
|
141
|
+
const errorResult = results.find((result) => result !== undefined);
|
|
142
|
+
return errorResult;
|
|
143
|
+
}
|
|
144
|
+
/**
|
|
145
|
+
* Creates the result for the Fastify server to use.
|
|
146
|
+
* @returns Promise where the result contains { status, data, headers } to
|
|
147
|
+
* send back to the browser.
|
|
148
|
+
*/
|
|
149
|
+
async function handleRenderRequest({ renderingRequest, bundleTimestamp, dependencyBundleTimestamps, providedNewBundles, assetsToCopy, }) {
|
|
150
|
+
try {
|
|
151
|
+
// const bundleFilePathPerTimestamp = getRequestBundleFilePath(bundleTimestamp);
|
|
152
|
+
const allBundleFilePaths = Array.from(new Set([...(dependencyBundleTimestamps ?? []), bundleTimestamp].map(utils_1.getRequestBundleFilePath)));
|
|
153
|
+
const entryBundleFilePath = (0, utils_1.getRequestBundleFilePath)(bundleTimestamp);
|
|
154
|
+
const { maxVMPoolSize } = (0, configBuilder_1.getConfig)();
|
|
155
|
+
if (allBundleFilePaths.length > maxVMPoolSize) {
|
|
156
|
+
return {
|
|
157
|
+
headers: { 'Cache-Control': 'no-cache, no-store, max-age=0, must-revalidate' },
|
|
158
|
+
status: 410,
|
|
159
|
+
data: `Too many bundles uploaded. The maximum allowed is ${maxVMPoolSize}. Please reduce the number of bundles or increase maxVMPoolSize in your configuration.`,
|
|
160
|
+
};
|
|
161
|
+
}
|
|
162
|
+
// If the current VM has the correct bundle and is ready
|
|
163
|
+
if (allBundleFilePaths.every((bundleFilePath) => (0, vm_1.hasVMContextForBundle)(bundleFilePath))) {
|
|
164
|
+
return await prepareResult(renderingRequest, entryBundleFilePath);
|
|
165
|
+
}
|
|
166
|
+
// If gem has posted updated bundle:
|
|
167
|
+
if (providedNewBundles && providedNewBundles.length > 0) {
|
|
168
|
+
const result = await handleNewBundlesProvided(renderingRequest, providedNewBundles, assetsToCopy);
|
|
169
|
+
if (result) {
|
|
170
|
+
return result;
|
|
171
|
+
}
|
|
172
|
+
}
|
|
173
|
+
// Check if the bundle exists:
|
|
174
|
+
const missingBundles = (await Promise.all([...(dependencyBundleTimestamps ?? []), bundleTimestamp].map(async (timestamp) => {
|
|
175
|
+
const bundleFilePath = (0, utils_1.getRequestBundleFilePath)(timestamp);
|
|
176
|
+
const fileExists = await (0, fileExistsAsync_1.default)(bundleFilePath);
|
|
177
|
+
return fileExists ? null : timestamp;
|
|
178
|
+
}))).filter((timestamp) => timestamp !== null);
|
|
179
|
+
if (missingBundles.length > 0) {
|
|
180
|
+
const missingBundlesText = missingBundles.length > 1 ? 'bundles' : 'bundle';
|
|
181
|
+
log_1.default.info(`No saved ${missingBundlesText}: ${missingBundles.join(', ')}`);
|
|
182
|
+
return {
|
|
183
|
+
headers: { 'Cache-Control': 'no-cache, no-store, max-age=0, must-revalidate' },
|
|
184
|
+
status: 410,
|
|
185
|
+
data: 'No bundle uploaded',
|
|
186
|
+
};
|
|
187
|
+
}
|
|
188
|
+
// The bundle exists, but the VM has not yet been created.
|
|
189
|
+
// Another worker must have written it or it was saved during deployment.
|
|
190
|
+
log_1.default.info('Bundle %s exists. Building VM for worker %s.', entryBundleFilePath, (0, utils_1.workerIdLabel)());
|
|
191
|
+
await Promise.all(allBundleFilePaths.map((bundleFilePath) => (0, vm_1.buildVM)(bundleFilePath)));
|
|
192
|
+
return await prepareResult(renderingRequest, entryBundleFilePath);
|
|
193
|
+
}
|
|
194
|
+
catch (error) {
|
|
195
|
+
const msg = (0, utils_1.formatExceptionMessage)(renderingRequest, error, 'Caught top level error in handleRenderRequest');
|
|
196
|
+
errorReporter.message(msg);
|
|
197
|
+
return Promise.reject(error);
|
|
198
|
+
}
|
|
199
|
+
}
|
|
200
|
+
//# sourceMappingURL=handleRenderRequest.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
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AC,YAAY,kBAAkB,KAAK,cAAc,CAAC,IAAI,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC;YACzE,OAAO;gBACL,OAAO,EAAE,EAAE,eAAe,EAAE,gDAAgD,EAAE;gBAC9E,MAAM,EAAE,GAAG;gBACX,IAAI,EAAE,oBAAoB;aAC3B,CAAC;QACJ,CAAC;QAED,0DAA0D;QAC1D,yEAAyE;QACzE,aAAG,CAAC,IAAI,CAAC,8CAA8C,EAAE,mBAAmB,EAAE,IAAA,qBAAa,GAAE,CAAC,CAAC;QAC/F,MAAM,OAAO,CAAC,GAAG,CAAC,kBAAkB,CAAC,GAAG,CAAC,CAAC,cAAc,EAAE,EAAE,CAAC,IAAA,YAAO,EAAC,cAAc,CAAC,CAAC,CAAC,CAAC;QAEvF,OAAO,MAAM,aAAa,CAAC,gBAAgB,EAAE,mBAAmB,CAAC,CAAC;IACpE,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QACf,MAAM,GAAG,GAAG,IAAA,8BAAsB,EAChC,gBAAgB,EAChB,KAAK,EACL,+CAA+C,CAChD,CAAC;QACF,aAAa,CAAC,OAAO,CAAC,GAAG,CAAC,CAAC;QAC3B,OAAO,OAAO,CAAC,MAAM,CAAC,KAAc,CAAC,CAAC;IACxC,CAAC;AACH,CAAC"}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { FastifyInstance as LibFastifyInstance, FastifyRequest as LibFastifyRequest, FastifyReply as LibFastifyReply, RouteGenericInterface } from 'fastify';
|
|
2
|
+
import { Http2Server } from 'http2';
|
|
3
|
+
export type FastifyInstance = LibFastifyInstance<Http2Server>;
|
|
4
|
+
export type FastifyRequest = LibFastifyRequest<RouteGenericInterface, Http2Server>;
|
|
5
|
+
export type FastifyReply = LibFastifyReply<RouteGenericInterface, Http2Server>;
|
|
6
|
+
//# sourceMappingURL=types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/worker/types.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,eAAe,IAAI,kBAAkB,EACrC,cAAc,IAAI,iBAAiB,EACnC,YAAY,IAAI,eAAe,EAC/B,qBAAqB,EACtB,MAAM,SAAS,CAAC;AACjB,OAAO,EAAE,WAAW,EAAE,MAAM,OAAO,CAAC;AAEpC,MAAM,MAAM,eAAe,GAAG,kBAAkB,CAAC,WAAW,CAAC,CAAC;AAE9D,MAAM,MAAM,cAAc,GAAG,iBAAiB,CAAC,qBAAqB,EAAE,WAAW,CAAC,CAAC;AAEnF,MAAM,MAAM,YAAY,GAAG,eAAe,CAAC,qBAAqB,EAAE,WAAW,CAAC,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../src/worker/types.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Manages the virtual machine for rendering code in isolated context.
|
|
3
|
+
* @module worker/vm
|
|
4
|
+
*/
|
|
5
|
+
import cluster from 'cluster';
|
|
6
|
+
import type { Readable } from 'stream';
|
|
7
|
+
import type { ReactOnRails as ROR } from 'react-on-rails' with { 'resolution-mode': 'import' };
|
|
8
|
+
import type { Context } from 'vm';
|
|
9
|
+
import SharedConsoleHistory from '../shared/sharedConsoleHistory';
|
|
10
|
+
interface VMContext {
|
|
11
|
+
context: Context;
|
|
12
|
+
sharedConsoleHistory: SharedConsoleHistory;
|
|
13
|
+
lastUsed: number;
|
|
14
|
+
}
|
|
15
|
+
/**
|
|
16
|
+
* Returns all bundle paths that have a VM context
|
|
17
|
+
*/
|
|
18
|
+
export declare function hasVMContextForBundle(bundlePath: string): boolean;
|
|
19
|
+
/**
|
|
20
|
+
* Get a specific VM context by bundle path
|
|
21
|
+
*/
|
|
22
|
+
export declare function getVMContext(bundlePath: string): VMContext | undefined;
|
|
23
|
+
/**
|
|
24
|
+
* The type of the result returned by executing the code payload sent in the rendering request.
|
|
25
|
+
*/
|
|
26
|
+
export type RenderCodeResult = string | Promise<string> | Readable;
|
|
27
|
+
/**
|
|
28
|
+
* The type of the result returned by the `runInVM` function.
|
|
29
|
+
*
|
|
30
|
+
* Similar to {@link RenderCodeResult} returned by executing the code payload sent in the rendering request,
|
|
31
|
+
* but after awaiting the promise if present and handling exceptions if any.
|
|
32
|
+
*/
|
|
33
|
+
export type RenderResult = string | Readable | {
|
|
34
|
+
exceptionMessage: string;
|
|
35
|
+
};
|
|
36
|
+
declare global {
|
|
37
|
+
var ReactOnRails: ROR | undefined;
|
|
38
|
+
}
|
|
39
|
+
/**
|
|
40
|
+
*
|
|
41
|
+
* @param renderingRequest JS Code to execute for SSR
|
|
42
|
+
* @param filePath
|
|
43
|
+
* @param vmCluster
|
|
44
|
+
*/
|
|
45
|
+
export declare function runInVM(renderingRequest: string, filePath: string, vmCluster?: typeof cluster): Promise<RenderResult>;
|
|
46
|
+
export declare function buildVM(filePath: string): Promise<boolean | undefined>;
|
|
47
|
+
export declare function resetVM(): void;
|
|
48
|
+
export declare function removeVM(bundlePath: string): void;
|
|
49
|
+
export {};
|
|
50
|
+
//# sourceMappingURL=vm.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"vm.d.ts","sourceRoot":"","sources":["../../src/worker/vm.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAMH,OAAO,OAAO,MAAM,SAAS,CAAC;AAC9B,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,QAAQ,CAAC;AAGvC,OAAO,KAAK,EAAE,YAAY,IAAI,GAAG,EAAE,MAAM,gBAAgB,CAAC,OAAO,iBAAiB,EAAE,QAAQ,EAAE,CAAC;AAC/F,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,IAAI,CAAC;AAElC,OAAO,oBAAoB,MAAM,gCAAgC,CAAC;AAelE,UAAU,SAAS;IACjB,OAAO,EAAE,OAAO,CAAC;IACjB,oBAAoB,EAAE,oBAAoB,CAAC;IAC3C,QAAQ,EAAE,MAAM,CAAC;CAClB;AAQD;;GAEG;AACH,wBAAgB,qBAAqB,CAAC,UAAU,EAAE,MAAM,WAEvD;AAED;;GAEG;AACH,wBAAgB,YAAY,CAAC,UAAU,EAAE,MAAM,GAAG,SAAS,GAAG,SAAS,CAEtE;AAED;;GAEG;AACH,MAAM,MAAM,gBAAgB,GAAG,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC,GAAG,QAAQ,CAAC;AAEnE;;;;;GAKG;AACH,MAAM,MAAM,YAAY,GAAG,MAAM,GAAG,QAAQ,GAAG;IAAE,gBAAgB,EAAE,MAAM,CAAA;CAAE,CAAC;AAE5E,OAAO,CAAC,MAAM,CAAC;IAIb,IAAI,YAAY,EAAE,GAAG,GAAG,SAAS,CAAC;CACnC;AA4BD;;;;;GAKG;AACH,wBAAsB,OAAO,CAC3B,gBAAgB,EAAE,MAAM,EACxB,QAAQ,EAAE,MAAM,EAChB,SAAS,CAAC,EAAE,OAAO,OAAO,GACzB,OAAO,CAAC,YAAY,CAAC,CAiEvB;AAED,wBAAsB,OAAO,CAAC,QAAQ,EAAE,MAAM,gCAwK7C;AAED,wBAAgB,OAAO,SAGtB;AAGD,wBAAgB,QAAQ,CAAC,UAAU,EAAE,MAAM,QAE1C"}
|
|
@@ -0,0 +1,297 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Manages the virtual machine for rendering code in isolated context.
|
|
4
|
+
* @module worker/vm
|
|
5
|
+
*/
|
|
6
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
7
|
+
if (k2 === undefined) k2 = k;
|
|
8
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
9
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
10
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
11
|
+
}
|
|
12
|
+
Object.defineProperty(o, k2, desc);
|
|
13
|
+
}) : (function(o, m, k, k2) {
|
|
14
|
+
if (k2 === undefined) k2 = k;
|
|
15
|
+
o[k2] = m[k];
|
|
16
|
+
}));
|
|
17
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
18
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
19
|
+
}) : function(o, v) {
|
|
20
|
+
o["default"] = v;
|
|
21
|
+
});
|
|
22
|
+
var __importStar = (this && this.__importStar) || function (mod) {
|
|
23
|
+
if (mod && mod.__esModule) return mod;
|
|
24
|
+
var result = {};
|
|
25
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
26
|
+
__setModuleDefault(result, mod);
|
|
27
|
+
return result;
|
|
28
|
+
};
|
|
29
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
30
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
31
|
+
};
|
|
32
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
33
|
+
exports.hasVMContextForBundle = hasVMContextForBundle;
|
|
34
|
+
exports.getVMContext = getVMContext;
|
|
35
|
+
exports.runInVM = runInVM;
|
|
36
|
+
exports.buildVM = buildVM;
|
|
37
|
+
exports.resetVM = resetVM;
|
|
38
|
+
exports.removeVM = removeVM;
|
|
39
|
+
const fs_1 = __importDefault(require("fs"));
|
|
40
|
+
const path_1 = __importDefault(require("path"));
|
|
41
|
+
const vm_1 = __importDefault(require("vm"));
|
|
42
|
+
const module_1 = __importDefault(require("module"));
|
|
43
|
+
const cluster_1 = __importDefault(require("cluster"));
|
|
44
|
+
const web_1 = require("stream/web");
|
|
45
|
+
const util_1 = require("util");
|
|
46
|
+
const sharedConsoleHistory_1 = __importDefault(require("../shared/sharedConsoleHistory"));
|
|
47
|
+
const log_1 = __importDefault(require("../shared/log"));
|
|
48
|
+
const configBuilder_1 = require("../shared/configBuilder");
|
|
49
|
+
const utils_1 = require("../shared/utils");
|
|
50
|
+
const errorReporter = __importStar(require("../shared/errorReporter"));
|
|
51
|
+
const readFileAsync = (0, util_1.promisify)(fs_1.default.readFile);
|
|
52
|
+
const writeFileAsync = (0, util_1.promisify)(fs_1.default.writeFile);
|
|
53
|
+
// Store contexts by their bundle file paths
|
|
54
|
+
const vmContexts = new Map();
|
|
55
|
+
// Track VM creation promises to handle concurrent buildVM requests
|
|
56
|
+
const vmCreationPromises = new Map();
|
|
57
|
+
/**
|
|
58
|
+
* Returns all bundle paths that have a VM context
|
|
59
|
+
*/
|
|
60
|
+
function hasVMContextForBundle(bundlePath) {
|
|
61
|
+
return vmContexts.has(bundlePath);
|
|
62
|
+
}
|
|
63
|
+
/**
|
|
64
|
+
* Get a specific VM context by bundle path
|
|
65
|
+
*/
|
|
66
|
+
function getVMContext(bundlePath) {
|
|
67
|
+
return vmContexts.get(bundlePath);
|
|
68
|
+
}
|
|
69
|
+
const extendContext = (contextObject, additionalContext) => {
|
|
70
|
+
if (log_1.default.level === 'debug') {
|
|
71
|
+
log_1.default.debug(`Adding ${Object.keys(additionalContext).join(', ')} to context object.`);
|
|
72
|
+
}
|
|
73
|
+
Object.assign(contextObject, additionalContext);
|
|
74
|
+
};
|
|
75
|
+
// Helper function to manage VM pool size
|
|
76
|
+
function manageVMPoolSize() {
|
|
77
|
+
const { maxVMPoolSize } = (0, configBuilder_1.getConfig)();
|
|
78
|
+
if (vmContexts.size <= maxVMPoolSize) {
|
|
79
|
+
return;
|
|
80
|
+
}
|
|
81
|
+
const sortedEntries = Array.from(vmContexts.entries()).sort(([, a], [, b]) => a.lastUsed - b.lastUsed);
|
|
82
|
+
while (sortedEntries.length > maxVMPoolSize) {
|
|
83
|
+
const oldestPath = sortedEntries.shift()?.[0];
|
|
84
|
+
if (oldestPath) {
|
|
85
|
+
vmContexts.delete(oldestPath);
|
|
86
|
+
log_1.default.debug(`Removed VM for bundle ${oldestPath} due to pool size limit (max: ${maxVMPoolSize})`);
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
/**
|
|
91
|
+
*
|
|
92
|
+
* @param renderingRequest JS Code to execute for SSR
|
|
93
|
+
* @param filePath
|
|
94
|
+
* @param vmCluster
|
|
95
|
+
*/
|
|
96
|
+
async function runInVM(renderingRequest, filePath, vmCluster) {
|
|
97
|
+
const { serverBundleCachePath } = (0, configBuilder_1.getConfig)();
|
|
98
|
+
try {
|
|
99
|
+
// Wait for VM creation if it's in progress
|
|
100
|
+
if (vmCreationPromises.has(filePath)) {
|
|
101
|
+
await vmCreationPromises.get(filePath);
|
|
102
|
+
}
|
|
103
|
+
// Get the correct VM context based on the provided bundle path
|
|
104
|
+
const vmContext = getVMContext(filePath);
|
|
105
|
+
if (!vmContext) {
|
|
106
|
+
throw new Error(`No VM context found for bundle ${filePath}`);
|
|
107
|
+
}
|
|
108
|
+
// Update last used timestamp
|
|
109
|
+
vmContext.lastUsed = Date.now();
|
|
110
|
+
const { context, sharedConsoleHistory } = vmContext;
|
|
111
|
+
if (log_1.default.level === 'debug') {
|
|
112
|
+
// worker is nullable in the primary process
|
|
113
|
+
const workerId = vmCluster?.worker?.id;
|
|
114
|
+
log_1.default.debug(`worker ${workerId ? `${workerId} ` : ''}received render request for bundle ${filePath} with code
|
|
115
|
+
${(0, utils_1.smartTrim)(renderingRequest)}`);
|
|
116
|
+
const debugOutputPathCode = path_1.default.join(serverBundleCachePath, 'code.js');
|
|
117
|
+
log_1.default.debug(`Full code executed written to: ${debugOutputPathCode}`);
|
|
118
|
+
await writeFileAsync(debugOutputPathCode, renderingRequest);
|
|
119
|
+
}
|
|
120
|
+
let result = sharedConsoleHistory.trackConsoleHistoryInRenderRequest(() => {
|
|
121
|
+
context.renderingRequest = renderingRequest;
|
|
122
|
+
try {
|
|
123
|
+
return vm_1.default.runInContext(renderingRequest, context);
|
|
124
|
+
}
|
|
125
|
+
finally {
|
|
126
|
+
context.renderingRequest = undefined;
|
|
127
|
+
}
|
|
128
|
+
});
|
|
129
|
+
if ((0, utils_1.isReadableStream)(result)) {
|
|
130
|
+
const newStreamAfterHandlingError = (0, utils_1.handleStreamError)(result, (error) => {
|
|
131
|
+
const msg = (0, utils_1.formatExceptionMessage)(renderingRequest, error, 'Error in a rendering stream');
|
|
132
|
+
errorReporter.message(msg);
|
|
133
|
+
});
|
|
134
|
+
return newStreamAfterHandlingError;
|
|
135
|
+
}
|
|
136
|
+
if (typeof result !== 'string') {
|
|
137
|
+
const objectResult = await result;
|
|
138
|
+
result = JSON.stringify(objectResult);
|
|
139
|
+
}
|
|
140
|
+
if (log_1.default.level === 'debug') {
|
|
141
|
+
log_1.default.debug(`result from JS:
|
|
142
|
+
${(0, utils_1.smartTrim)(result)}`);
|
|
143
|
+
const debugOutputPathResult = path_1.default.join(serverBundleCachePath, 'result.json');
|
|
144
|
+
log_1.default.debug(`Wrote result to file: ${debugOutputPathResult}`);
|
|
145
|
+
await writeFileAsync(debugOutputPathResult, result);
|
|
146
|
+
}
|
|
147
|
+
return result;
|
|
148
|
+
}
|
|
149
|
+
catch (exception) {
|
|
150
|
+
const exceptionMessage = (0, utils_1.formatExceptionMessage)(renderingRequest, exception);
|
|
151
|
+
log_1.default.debug('Caught exception in rendering request', exceptionMessage);
|
|
152
|
+
return Promise.resolve({ exceptionMessage });
|
|
153
|
+
}
|
|
154
|
+
}
|
|
155
|
+
async function buildVM(filePath) {
|
|
156
|
+
// Return existing promise if VM is already being created
|
|
157
|
+
if (vmCreationPromises.has(filePath)) {
|
|
158
|
+
return vmCreationPromises.get(filePath);
|
|
159
|
+
}
|
|
160
|
+
// Check if VM for this bundle already exists
|
|
161
|
+
const vmContext = vmContexts.get(filePath);
|
|
162
|
+
if (vmContext) {
|
|
163
|
+
// Update last used time when accessing existing VM
|
|
164
|
+
vmContext.lastUsed = Date.now();
|
|
165
|
+
return Promise.resolve(true);
|
|
166
|
+
}
|
|
167
|
+
// Create a new promise for this VM creation
|
|
168
|
+
const vmCreationPromise = (async () => {
|
|
169
|
+
try {
|
|
170
|
+
const { supportModules, stubTimers, additionalContext } = (0, configBuilder_1.getConfig)();
|
|
171
|
+
const additionalContextIsObject = additionalContext !== null && additionalContext.constructor === Object;
|
|
172
|
+
const sharedConsoleHistory = new sharedConsoleHistory_1.default();
|
|
173
|
+
const runOnOtherBundle = async (bundleTimestamp, renderingRequest) => {
|
|
174
|
+
const bundlePath = (0, utils_1.getRequestBundleFilePath)(bundleTimestamp);
|
|
175
|
+
return runInVM(renderingRequest, bundlePath, cluster_1.default);
|
|
176
|
+
};
|
|
177
|
+
const contextObject = { sharedConsoleHistory, runOnOtherBundle };
|
|
178
|
+
if (supportModules) {
|
|
179
|
+
// IMPORTANT: When adding anything to this object, update:
|
|
180
|
+
// 1. docs/node-renderer/js-configuration.md
|
|
181
|
+
// 2. packages/node-renderer/src/shared/configBuilder.ts
|
|
182
|
+
extendContext(contextObject, {
|
|
183
|
+
Buffer,
|
|
184
|
+
TextDecoder,
|
|
185
|
+
TextEncoder: util_1.TextEncoder,
|
|
186
|
+
URLSearchParams,
|
|
187
|
+
ReadableStream: web_1.ReadableStream,
|
|
188
|
+
process,
|
|
189
|
+
setTimeout,
|
|
190
|
+
setInterval,
|
|
191
|
+
setImmediate,
|
|
192
|
+
clearTimeout,
|
|
193
|
+
clearInterval,
|
|
194
|
+
clearImmediate,
|
|
195
|
+
queueMicrotask,
|
|
196
|
+
});
|
|
197
|
+
}
|
|
198
|
+
if (additionalContextIsObject) {
|
|
199
|
+
extendContext(contextObject, additionalContext);
|
|
200
|
+
}
|
|
201
|
+
const context = vm_1.default.createContext(contextObject);
|
|
202
|
+
// Create explicit reference to global context, just in case (some libs can use it):
|
|
203
|
+
vm_1.default.runInContext('global = this', context);
|
|
204
|
+
// Reimplement console methods for replaying on the client:
|
|
205
|
+
vm_1.default.runInContext(`
|
|
206
|
+
console = {
|
|
207
|
+
get history() {
|
|
208
|
+
return sharedConsoleHistory.getConsoleHistory();
|
|
209
|
+
},
|
|
210
|
+
set history(value) {
|
|
211
|
+
// Do nothing. It's just for the backward compatibility.
|
|
212
|
+
},
|
|
213
|
+
};
|
|
214
|
+
['error', 'log', 'info', 'warn'].forEach(function (level) {
|
|
215
|
+
console[level] = function () {
|
|
216
|
+
var argArray = Array.prototype.slice.call(arguments);
|
|
217
|
+
if (argArray.length > 0) {
|
|
218
|
+
argArray[0] = '[SERVER] ' + argArray[0];
|
|
219
|
+
}
|
|
220
|
+
sharedConsoleHistory.addToConsoleHistory({level: level, arguments: argArray});
|
|
221
|
+
};
|
|
222
|
+
});`, context);
|
|
223
|
+
// Define global getStackTrace() function:
|
|
224
|
+
vm_1.default.runInContext(`
|
|
225
|
+
function getStackTrace() {
|
|
226
|
+
var stack;
|
|
227
|
+
try {
|
|
228
|
+
throw new Error('');
|
|
229
|
+
}
|
|
230
|
+
catch (error) {
|
|
231
|
+
stack = error.stack || '';
|
|
232
|
+
}
|
|
233
|
+
stack = stack.split('\\n').map(function (line) { return line.trim(); });
|
|
234
|
+
return stack.splice(stack[0] == 'Error' ? 2 : 1);
|
|
235
|
+
}`, context);
|
|
236
|
+
if (stubTimers) {
|
|
237
|
+
// Define timer polyfills:
|
|
238
|
+
vm_1.default.runInContext(`function setInterval() {}`, context);
|
|
239
|
+
vm_1.default.runInContext(`function setTimeout() {}`, context);
|
|
240
|
+
vm_1.default.runInContext(`function setImmediate() {}`, context);
|
|
241
|
+
vm_1.default.runInContext(`function clearTimeout() {}`, context);
|
|
242
|
+
vm_1.default.runInContext(`function clearInterval() {}`, context);
|
|
243
|
+
vm_1.default.runInContext(`function clearImmediate() {}`, context);
|
|
244
|
+
vm_1.default.runInContext(`function queueMicrotask() {}`, context);
|
|
245
|
+
}
|
|
246
|
+
// Run bundle code in created context:
|
|
247
|
+
const bundleContents = await readFileAsync(filePath, 'utf8');
|
|
248
|
+
// If node-specific code is provided then it must be wrapped into a module wrapper. The bundle
|
|
249
|
+
// may need the `require` function, which is not available when running in vm unless passed in.
|
|
250
|
+
if (additionalContextIsObject || supportModules) {
|
|
251
|
+
// eslint-disable-next-line @typescript-eslint/no-unsafe-call
|
|
252
|
+
vm_1.default.runInContext(module_1.default.wrap(bundleContents), context)(exports, require, module, filePath, path_1.default.dirname(filePath));
|
|
253
|
+
}
|
|
254
|
+
else {
|
|
255
|
+
vm_1.default.runInContext(bundleContents, context);
|
|
256
|
+
}
|
|
257
|
+
// Only now, after VM is fully initialized, store the context
|
|
258
|
+
vmContexts.set(filePath, {
|
|
259
|
+
context,
|
|
260
|
+
sharedConsoleHistory,
|
|
261
|
+
lastUsed: Date.now(),
|
|
262
|
+
});
|
|
263
|
+
// Manage pool size after adding new VM
|
|
264
|
+
manageVMPoolSize();
|
|
265
|
+
// isWorker check is required for JS unit testing:
|
|
266
|
+
if (cluster_1.default.isWorker && cluster_1.default.worker !== undefined) {
|
|
267
|
+
log_1.default.debug(`Built VM for worker #${cluster_1.default.worker.id} with bundle ${filePath}`);
|
|
268
|
+
}
|
|
269
|
+
if (log_1.default.level === 'debug') {
|
|
270
|
+
log_1.default.debug('Required objects now in VM sandbox context: %s', vm_1.default.runInContext('global.ReactOnRails', context) !== undefined);
|
|
271
|
+
log_1.default.debug('Required objects should not leak to the global context (true means OK): %s', !!global.ReactOnRails);
|
|
272
|
+
}
|
|
273
|
+
return true;
|
|
274
|
+
}
|
|
275
|
+
catch (error) {
|
|
276
|
+
log_1.default.error('Caught Error when creating context in buildVM, %O', error);
|
|
277
|
+
errorReporter.error(error);
|
|
278
|
+
throw error;
|
|
279
|
+
}
|
|
280
|
+
finally {
|
|
281
|
+
// Always remove the promise from the map when done
|
|
282
|
+
vmCreationPromises.delete(filePath);
|
|
283
|
+
}
|
|
284
|
+
})();
|
|
285
|
+
// Store the promise
|
|
286
|
+
vmCreationPromises.set(filePath, vmCreationPromise);
|
|
287
|
+
return vmCreationPromise;
|
|
288
|
+
}
|
|
289
|
+
function resetVM() {
|
|
290
|
+
// Clear all VM contexts
|
|
291
|
+
vmContexts.clear();
|
|
292
|
+
}
|
|
293
|
+
// Optional: Add a method to remove a specific VM if needed
|
|
294
|
+
function removeVM(bundlePath) {
|
|
295
|
+
vmContexts.delete(bundlePath);
|
|
296
|
+
}
|
|
297
|
+
//# sourceMappingURL=vm.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"vm.js","sourceRoot":"","sources":["../../src/worker/vm.ts"],"names":[],"mappings":";AAAA;;;GAGG;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA2CH,sDAEC;AAKD,oCAEC;AAsDD,0BAqEC;AAED,0BAwKC;AAED,0BAGC;AAGD,4BAEC;AAjWD,4CAAoB;AACpB,gDAAwB;AACxB,4CAAoB;AACpB,oDAAuB;AACvB,sDAA8B;AAE9B,oCAA4C;AAC5C,+BAA8C;AAI9C,0FAAkE;AAClE,wDAAgC;AAChC,2DAAoD;AACpD,2CAMyB;AACzB,uEAAyD;AAEzD,MAAM,aAAa,GAAG,IAAA,gBAAS,EAAC,YAAE,CAAC,QAAQ,CAAC,CAAC;AAC7C,MAAM,cAAc,GAAG,IAAA,gBAAS,EAAC,YAAE,CAAC,SAAS,CAAC,CAAC;AAQ/C,4CAA4C;AAC5C,MAAM,UAAU,GAAG,IAAI,GAAG,EAAqB,CAAC;AAEhD,mEAAmE;AACnE,MAAM,kBAAkB,GAAG,IAAI,GAAG,EAA4B,CAAC;AAE/D;;GAEG;AACH,SAAgB,qBAAqB,CAAC,UAAkB;IACtD,OAAO,UAAU,CAAC,GAAG,CAAC,UAAU,CAAC,CAAC;AACpC,CAAC;AAED;;GAEG;AACH,SAAgB,YAAY,CAAC,UAAkB;IAC7C,OAAO,UAAU,CAAC,GAAG,CAAC,UAAU,CAAC,CAAC;AACpC,CAAC;AAsBD,MAAM,aAAa,GAAG,CAAC,aAAyB,EAAE,iBAA0C,EAAE,EAAE;IAC9F,IAAI,aAAG,CAAC,KAAK,KAAK,OAAO,EAAE,CAAC;QAC1B,aAAG,CAAC,KAAK,CAAC,UAAU,MAAM,CAAC,IAAI,CAAC,iBAAiB,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AAC;AAC3B,CAAC;AAED,SAAgB,OAAO;IACrB,wBAAwB;IACxB,UAAU,CAAC,KAAK,EAAE,CAAC;AACrB,CAAC;AAED,2DAA2D;AAC3D,SAAgB,QAAQ,CAAC,UAAkB;IACzC,UAAU,CAAC,MAAM,CAAC,UAAU,CAAC,CAAC;AAChC,CAAC"}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Entry point for worker process that handles requests.
|
|
3
|
+
* @module worker
|
|
4
|
+
*/
|
|
5
|
+
import { Config } from './shared/configBuilder';
|
|
6
|
+
import type { FastifyInstance } from './worker/types';
|
|
7
|
+
import { Asset } from './shared/utils';
|
|
8
|
+
declare module '@fastify/multipart' {
|
|
9
|
+
interface MultipartFile {
|
|
10
|
+
value: Asset;
|
|
11
|
+
}
|
|
12
|
+
}
|
|
13
|
+
export type FastifyConfigFunction = (app: FastifyInstance) => void;
|
|
14
|
+
/**
|
|
15
|
+
* Configures Fastify instance before starting the server.
|
|
16
|
+
* @param configFunction The configuring function. Normally it will be something like `(app) => { app.register(...); }`
|
|
17
|
+
* or `(app) => { app.addHook(...); }` to report data from Fastify to an external service.
|
|
18
|
+
* Note that we call `await app.ready()` in our code, so you don't need to `await` the results.
|
|
19
|
+
*/
|
|
20
|
+
export declare function configureFastify(configFunction: FastifyConfigFunction): void;
|
|
21
|
+
export declare const disableHttp2: () => void;
|
|
22
|
+
export default function run(config: Partial<Config>): import("fastify").FastifyInstance<import("http2").Http2Server, import("http2").Http2ServerRequest, import("http2").Http2ServerResponse, import("fastify").FastifyBaseLogger, import("fastify").FastifyTypeProviderDefault> & PromiseLike<import("fastify").FastifyInstance<import("http2").Http2Server, import("http2").Http2ServerRequest, import("http2").Http2ServerResponse, import("fastify").FastifyBaseLogger, import("fastify").FastifyTypeProviderDefault>> & {
|
|
23
|
+
__linterBrands: "SafePromiseLike";
|
|
24
|
+
};
|
|
25
|
+
//# sourceMappingURL=worker.d.ts.map
|