@stamhoofd/backend-renderer 2.151.1 → 2.153.0

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/.gitignore ADDED
@@ -0,0 +1,223 @@
1
+ /devops/
2
+ node_modules/
3
+ .node_modules/
4
+ built/*
5
+ tests/cases/rwc/*
6
+ tests/cases/test262/*
7
+ tests/cases/perf/*
8
+ !tests/cases/webharness/compilerToString.js
9
+ test-args.txt
10
+ ~*.docx
11
+ \#*\#
12
+ .\#*
13
+ tests/baselines/local/*
14
+ tests/baselines/local.old/*
15
+ tests/services/baselines/local/*
16
+ tests/baselines/prototyping/local/*
17
+ tests/baselines/rwc/*
18
+ tests/baselines/test262/*
19
+ tests/baselines/reference/projectOutput/*
20
+ tests/baselines/local/projectOutput/*
21
+ tests/baselines/reference/testresults.tap
22
+ tests/services/baselines/prototyping/local/*
23
+ tests/services/browser/typescriptServices.js
24
+ src/harness/*.js
25
+ src/compiler/diagnosticInformationMap.generated.ts
26
+ src/compiler/diagnosticMessages.generated.json
27
+ src/parser/diagnosticInformationMap.generated.ts
28
+ src/parser/diagnosticMessages.generated.json
29
+ rwc-report.html
30
+ *.swp
31
+ build.json
32
+ *.actual
33
+ tests/webTestServer.js
34
+ tests/webTestServer.js.map
35
+ tests/webhost/*.d.ts
36
+ tests/webhost/webtsc.js
37
+ tests/cases/**/*.js
38
+ !tests/cases/docker/*.js/
39
+ tests/cases/**/*.js.map
40
+ *.config
41
+ scripts/eslint/built/
42
+ scripts/debug.bat
43
+ scripts/run.bat
44
+ scripts/word2md.js
45
+ scripts/buildProtocol.js
46
+ scripts/ior.js
47
+ scripts/authors.js
48
+ scripts/configurePrerelease.js
49
+ scripts/configureLanguageServiceBuild.js
50
+ scripts/open-user-pr.js
51
+ scripts/open-cherry-pick-pr.js
52
+ scripts/processDiagnosticMessages.d.ts
53
+ scripts/processDiagnosticMessages.js
54
+ scripts/produceLKG.js
55
+ scripts/importDefinitelyTypedTests/importDefinitelyTypedTests.js
56
+ scripts/generateLocalizedDiagnosticMessages.js
57
+ scripts/request-pr-review.js
58
+ scripts/*.js.map
59
+ scripts/typings/
60
+ coverage/
61
+ internal/
62
+ **/.DS_Store
63
+ .settings
64
+ !tests/cases/projects/projectOption/**/node_modules
65
+ !tests/cases/projects/NodeModulesSearch/**/*
66
+ !tests/baselines/reference/project/nodeModules*/**/*
67
+ .idea
68
+ yarn-error.log
69
+ .parallelperf.*
70
+ tests/cases/user/*/package-lock.json
71
+ tests/cases/user/*/node_modules/
72
+ tests/cases/user/*/**/*.js
73
+ tests/cases/user/*/**/*.js.map
74
+ tests/cases/user/*/**/*.d.ts
75
+ !tests/cases/user/zone.js/
76
+ !tests/cases/user/bignumber.js/
77
+ !tests/cases/user/discord.js/
78
+ tests/baselines/reference/dt
79
+ .failed-tests
80
+ TEST-results.xml
81
+ package-lock.json
82
+ tests/cases/user/TypeScript-React-Starter/TypeScript-React-Starter
83
+ tests/cases/user/TypeScript-Node-Starter/TypeScript-Node-Starter
84
+ tests/cases/user/TypeScript-React-Native-Starter/TypeScript-React-Native-Starter
85
+ tests/cases/user/TypeScript-Vue-Starter/TypeScript-Vue-Starter
86
+ tests/cases/user/TypeScript-WeChat-Starter/TypeScript-WeChat-Starter
87
+ tests/cases/user/create-react-app/create-react-app
88
+ tests/cases/user/fp-ts/fp-ts
89
+ tests/cases/user/webpack/webpack
90
+ tests/cases/user/puppeteer/puppeteer
91
+ tests/cases/user/axios-src/axios-src
92
+ tests/cases/user/prettier/prettier
93
+ .eslintcache
94
+
95
+ # Logs
96
+ logs
97
+ *.log
98
+ npm-debug.log*
99
+ yarn-debug.log*
100
+ yarn-error.log*
101
+ lerna-debug.log*
102
+
103
+ # Diagnostic reports (https://nodejs.org/api/report.html)
104
+ report.[0-9]*.[0-9]*.[0-9]*.[0-9]*.json
105
+
106
+ # Runtime data
107
+ pids
108
+ *.pid
109
+ *.seed
110
+ *.pid.lock
111
+
112
+ # Directory for instrumented libs generated by jscoverage/JSCover
113
+ lib-cov
114
+
115
+ # Coverage directory used by tools like istanbul
116
+ coverage
117
+ *.lcov
118
+
119
+ # nyc test coverage
120
+ .nyc_output
121
+
122
+ # Grunt intermediate storage (https://gruntjs.com/creating-plugins#storing-task-files)
123
+ .grunt
124
+
125
+ # Bower dependency directory (https://bower.io/)
126
+ bower_components
127
+
128
+ # node-waf configuration
129
+ .lock-wscript
130
+
131
+ # Compiled binary addons (https://nodejs.org/api/addons.html)
132
+ build/Release
133
+
134
+ # Dependency directories
135
+ node_modules/
136
+ jspm_packages/
137
+
138
+ # Snowpack dependency directory (https://snowpack.dev/)
139
+ web_modules/
140
+
141
+ # TypeScript cache
142
+ *.tsbuildinfo
143
+
144
+ # Optional npm cache directory
145
+ .npm
146
+
147
+ # Optional eslint cache
148
+ .eslintcache
149
+
150
+ # Microbundle cache
151
+ .rpt2_cache/
152
+ .rts2_cache_cjs/
153
+ .rts2_cache_es/
154
+ .rts2_cache_umd/
155
+
156
+ # Optional REPL history
157
+ .node_repl_history
158
+
159
+ # Output of 'npm pack'
160
+ *.tgz
161
+
162
+ # Yarn Integrity file
163
+ .yarn-integrity
164
+
165
+ # dotenv environment variables file
166
+ .env
167
+ .env.test
168
+
169
+ # parcel-bundler cache (https://parceljs.org/)
170
+ .cache
171
+ cache
172
+ .parcel-cache
173
+
174
+ # Next.js build output
175
+ .next
176
+
177
+ # Nuxt.js build / generate output
178
+ .nuxt
179
+ dist
180
+
181
+ # Gatsby files
182
+ .cache/
183
+ # Comment in the public line in if your project uses Gatsby and not Next.js
184
+ # https://nextjs.org/blog/next-9-1#public-directory-support
185
+ # public
186
+
187
+ # vuepress build output
188
+ .vuepress/dist
189
+
190
+ # Serverless directories
191
+ .serverless/
192
+
193
+ # FuseBox cache
194
+ .fusebox/
195
+
196
+ # DynamoDB Local files
197
+ .dynamodb/
198
+
199
+ # TernJS port file
200
+ .tern-port
201
+
202
+ # Stores VSCode versions used for testing VSCode extensions
203
+ .vscode-test
204
+
205
+ # yarn v2
206
+
207
+ .yarn/cache
208
+ .yarn/unplugged
209
+ .yarn/build-state.yml
210
+ .pnp.*
211
+
212
+ .yalc
213
+ yalc.lock
214
+
215
+ .yarn
216
+
217
+ # Yarnrc should be removed from git, because it breaks yarn if the version is not installed yet
218
+ .yarnrc
219
+
220
+ .env.json
221
+ .env.*.json
222
+ !.env.template.json
223
+ /.test-cache
package/dist/index.js ADDED
@@ -0,0 +1,12 @@
1
+ import backendEnv from '@stamhoofd/backend-env';
2
+ process.title = 'stamhoofd-renderer';
3
+ backendEnv.load({ service: 'renderer' }).catch((error) => {
4
+ console.error('Failed to load environment:', error);
5
+ process.exit(1);
6
+ }).then(async () => {
7
+ await import('./boot.js');
8
+ }).catch((error) => {
9
+ console.error('Failed to start the API:', error);
10
+ process.exit(1);
11
+ });
12
+ //# sourceMappingURL=index.js.map
package/package.json CHANGED
@@ -1,57 +1,56 @@
1
1
  {
2
- "name": "@stamhoofd/backend-renderer",
3
- "version": "2.151.1",
4
- "type": "module",
5
- "main": "./dist/index.js",
6
- "exports": {
7
- ".": {
8
- "require": "./dist/index.js"
9
- }
10
- },
11
- "scripts": {
12
- "build": "tsc --build tsconfig.build.json",
13
- "build:full": "yarn -s clear && yarn -s build",
14
- "clear": "rm -rf ./dist && rm -f *.tsbuildinfo",
15
- "dev": "wait-on ../../shared/middleware/dist/index.js && concurrently -r 'yarn -s build --watch --preserveWatchOutput' \"wait-on ./dist/index.js && nodemon --quiet --inspect=5858 --watch dist --watch '../../../shared/*/dist/' --watch '../../shared/*/dist/' --ext .ts,.json,.sql,.js --watch .env.json --delay 1000ms --exec 'node --enable-source-maps ./dist/index.js' --signal SIGTERM\"",
16
- "dev:build": "yarn -s build",
17
- "dev:full": "yarn -s dev",
18
- "lint": "eslint",
19
- "start": "yarn -s build && node --enable-source-maps ./dist/index.js",
20
- "typecheck": "tsc --build tsconfig.test.json",
21
- "test": "vitest",
22
- "test:coverage": "vitest --coverage"
23
- },
24
- "dependencies": {
25
- "@simonbackx/simple-database": "1.40.0",
26
- "@simonbackx/simple-encoding": "2.26.11",
27
- "@simonbackx/simple-endpoints": "1.22.0",
28
- "@simonbackx/simple-errors": "1.5.0",
29
- "@simonbackx/simple-logging": "1.0.1",
30
- "@stamhoofd/backend-env": "2.151.1",
31
- "@stamhoofd/backend-i18n": "2.151.1",
32
- "@stamhoofd/backend-middleware": "2.151.1",
33
- "@stamhoofd/logging": "2.151.1",
34
- "@stamhoofd/queues": "2.151.1",
35
- "@stamhoofd/structures": "2.151.1",
36
- "@stamhoofd/types": "2.151.1",
37
- "@stamhoofd/utility": "2.151.1",
38
- "formidable": "3.5.4",
39
- "luxon": "3.7.2",
40
- "mockdate": "3.0.5",
41
- "mysql2": "3.23.1",
42
- "puppeteer": "25.3.0"
43
- },
44
- "devDependencies": {
45
- "@stamhoofd/test-utils": "2.151.1",
46
- "@types/formidable": "3.5.1",
47
- "@types/luxon": "3.7.2",
48
- "@types/node": "22.20.1",
49
- "nock": "14.0.16",
50
- "vitest": "4.1.10"
51
- },
52
- "license": "UNLICENCED",
53
- "publishConfig": {
54
- "access": "public"
55
- },
56
- "gitHead": "77331fca6a59fa0b0e7bc2e85f7a5e727f87b707"
57
- }
2
+ "name": "@stamhoofd/backend-renderer",
3
+ "version": "2.153.0",
4
+ "type": "module",
5
+ "main": "./dist/index.js",
6
+ "exports": {
7
+ ".": {
8
+ "require": "./dist/index.js"
9
+ }
10
+ },
11
+ "dependencies": {
12
+ "@simonbackx/simple-database": "1.40.1",
13
+ "@simonbackx/simple-encoding": "2.26.11",
14
+ "@simonbackx/simple-endpoints": "1.22.0",
15
+ "@simonbackx/simple-errors": "1.5.0",
16
+ "@simonbackx/simple-logging": "1.0.1",
17
+ "@stamhoofd/backend-env": "2.153.0",
18
+ "@stamhoofd/backend-i18n": "2.153.0",
19
+ "@stamhoofd/backend-middleware": "2.153.0",
20
+ "@stamhoofd/logging": "2.153.0",
21
+ "@stamhoofd/queues": "2.153.0",
22
+ "@stamhoofd/structures": "2.153.0",
23
+ "@stamhoofd/types": "2.153.0",
24
+ "@stamhoofd/utility": "2.153.0",
25
+ "formidable": "3.5.4",
26
+ "luxon": "3.7.2",
27
+ "mockdate": "3.0.5",
28
+ "mysql2": "3.24.4",
29
+ "puppeteer": "25.12.0"
30
+ },
31
+ "devDependencies": {
32
+ "@stamhoofd/test-utils": "2.153.0",
33
+ "@types/formidable": "3.5.1",
34
+ "@types/luxon": "3.7.5",
35
+ "@types/node": "22.20.4",
36
+ "nock": "14.0.17",
37
+ "vitest": "4.1.11"
38
+ },
39
+ "license": "UNLICENCED",
40
+ "publishConfig": {
41
+ "access": "public"
42
+ },
43
+ "scripts": {
44
+ "build": "tsc --build tsconfig.build.json",
45
+ "build:full": "pnpm run clear && pnpm run build",
46
+ "clear": "rm -rf ./dist && rm -f *.tsbuildinfo",
47
+ "dev": "wait-on ../../shared/middleware/dist/index.js && concurrently -r 'pnpm run build --watch --preserveWatchOutput' \"wait-on ./dist/index.js && nodemon --quiet --inspect=5858 --watch dist --watch '../../../shared/*/dist/' --watch '../../shared/*/dist/' --ext .ts,.json,.sql,.js --watch .env.json --delay 1000ms --exec 'node --enable-source-maps ./dist/index.js' --signal SIGTERM\"",
48
+ "dev:build": "pnpm run build",
49
+ "dev:full": "pnpm run dev",
50
+ "lint": "eslint",
51
+ "start": "pnpm run build && node --enable-source-maps ./dist/index.js",
52
+ "typecheck": "tsc --build tsconfig.test.json",
53
+ "test": "vitest",
54
+ "test:coverage": "vitest --coverage"
55
+ }
56
+ }
package/src/boot.ts CHANGED
@@ -3,6 +3,7 @@ import { I18n } from '@stamhoofd/backend-i18n';
3
3
  import { CORSMiddleware, LogMiddleware } from '@stamhoofd/backend-middleware';
4
4
  import { loadLogger } from '@stamhoofd/logging';
5
5
  import { CpuService } from '@stamhoofd/logging/CpuService';
6
+ import { MemoryService } from '@stamhoofd/logging/MemoryService';
6
7
  import { TrustedIPWhitelist } from './classes/TrustedIPWhitelist.js';
7
8
 
8
9
  process.on('unhandledRejection', (error: Error) => {
@@ -45,9 +46,10 @@ const start = async () => {
45
46
 
46
47
  routerServer.listen(STAMHOOFD.PORT ?? 9090);
47
48
 
48
- // Monitor CPU load so the /health endpoint can report an overloaded renderer as unhealthy.
49
+ // Monitor CPU load and memory so the /health endpoint can report an overloaded renderer as unhealthy.
49
50
  if (STAMHOOFD.environment !== 'development' && STAMHOOFD.environment !== 'test') {
50
51
  CpuService.startMonitoring();
52
+ MemoryService.startMonitoring();
51
53
  }
52
54
 
53
55
  if (routerServer.server) {
@@ -1,5 +1,6 @@
1
1
  import { Request, TestServer } from '@simonbackx/simple-endpoints';
2
2
  import { CpuService } from '@stamhoofd/logging/CpuService';
3
+ import { MemoryService } from '@stamhoofd/logging/MemoryService';
3
4
  import { STExpect, TestUtils } from '@stamhoofd/test-utils';
4
5
  import { HealthEndpoint } from './HealthEndpoint.js';
5
6
 
@@ -15,6 +16,7 @@ describe('Endpoint.Health', () => {
15
16
  afterEach(() => {
16
17
  // Reset the CPU samples so a high-load test doesn't leak into the next one.
17
18
  CpuService.samples.fill(0);
19
+ MemoryService.clearForTesting();
18
20
  });
19
21
 
20
22
  test('Returns 200 when healthy', async () => {
@@ -43,6 +45,21 @@ describe('Endpoint.Health', () => {
43
45
  expect(response.body.errors).toContain('CPU usage is too high');
44
46
  });
45
47
 
48
+ test('Returns 503 when the heap has been almost full for a minute', async () => {
49
+ const mib = 1024 * 1024;
50
+ MemoryService.record({ heapUsed: 480 * mib, heapLimit: 512 * mib, rss: 900 * mib, external: 100 * mib, systemTotal: 8192 * mib, systemAvailable: 4096 * mib });
51
+
52
+ const request = Request.get({
53
+ path: '/health',
54
+ query: { key },
55
+ });
56
+
57
+ const response = await testServer.test(endpoint, request);
58
+ expect(response.status).toBe(503);
59
+ expect(response.body.status).toBe('error');
60
+ expect(response.body.errors).toEqual(['Heap memory usage is too high: 480 MiB of 512 MiB (94% average)']);
61
+ });
62
+
46
63
  test('Rejects requests with a wrong key', async () => {
47
64
  const request = Request.get({
48
65
  path: '/health',
@@ -3,6 +3,7 @@ import type { DecodedRequest, Request } from '@simonbackx/simple-endpoints';
3
3
  import { Endpoint, Response } from '@simonbackx/simple-endpoints';
4
4
  import { SimpleError } from '@simonbackx/simple-errors';
5
5
  import { CpuService } from '@stamhoofd/logging/CpuService';
6
+ import { MemoryService } from '@stamhoofd/logging/MemoryService';
6
7
 
7
8
  type Params = Record<string, never>;
8
9
  type Body = undefined;
@@ -71,6 +72,8 @@ export class HealthEndpoint extends Endpoint<Params, Query, Body, ResponseBody>
71
72
  errors.push('CPU usage is too high');
72
73
  }
73
74
 
75
+ errors.push(...MemoryService.getErrors());
76
+
74
77
  const health = ResponseBody.create({
75
78
  status: errors.length > 0 ? 'error' : 'ok',
76
79
  errors: errors.length > 0 ? errors : undefined,