@platformatic/runtime 2.6.0 → 2.7.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/config.d.ts CHANGED
@@ -5,12 +5,13 @@
5
5
  * and run json-schema-to-typescript to regenerate this file.
6
6
  */
7
7
 
8
- export type HttpsSchemasPlatformaticDevPlatformaticRuntime260Json = {
8
+ export type HttpsSchemasPlatformaticDevPlatformaticRuntime270Json = {
9
9
  [k: string]: unknown;
10
10
  } & {
11
11
  $schema?: string;
12
12
  preload?: string;
13
13
  entrypoint?: string;
14
+ basePath?: string;
14
15
  autoload?: {
15
16
  path: string;
16
17
  exclude?: string[];
package/lib/schema.js CHANGED
@@ -49,6 +49,9 @@ const platformaticRuntimeSchema = {
49
49
  entrypoint: {
50
50
  type: 'string'
51
51
  },
52
+ basePath: {
53
+ type: 'string'
54
+ },
52
55
  autoload: {
53
56
  type: 'object',
54
57
  additionalProperties: false,
@@ -5,6 +5,8 @@ const { join } = require('node:path')
5
5
  const { parentPort, workerData, threadId } = require('node:worker_threads')
6
6
  const { pathToFileURL } = require('node:url')
7
7
  const inspector = require('node:inspector')
8
+ const diagnosticChannel = require('node:diagnostics_channel')
9
+ const { ServerResponse } = require('node:http')
8
10
 
9
11
  const pino = require('pino')
10
12
  const { fetch, setGlobalDispatcher, Agent } = require('undici')
@@ -141,6 +143,13 @@ async function main () {
141
143
 
142
144
  await app.init()
143
145
 
146
+ if (service.entrypoint && config.basePath) {
147
+ const meta = await app.stackable.getMeta()
148
+ if (!meta.wantsAbsoluteUrls) {
149
+ stripBasePath(config.basePath)
150
+ }
151
+ }
152
+
144
153
  // Setup interaction with parent port
145
154
  const itc = setupITC(app, service, threadDispatcher)
146
155
 
@@ -152,5 +161,55 @@ async function main () {
152
161
  globalThis[kITC] = itc
153
162
  }
154
163
 
164
+ function stripBasePath (basePath) {
165
+ const kBasePath = Symbol('kBasePath')
166
+
167
+ diagnosticChannel.subscribe('http.server.request.start', ({ request, response }) => {
168
+ if (request.url.startsWith(basePath)) {
169
+ request.url = request.url.slice(basePath.length)
170
+
171
+ if (request.url.charAt(0) !== '/') {
172
+ request.url = '/' + request.url
173
+ }
174
+
175
+ response[kBasePath] = basePath
176
+ }
177
+ })
178
+
179
+ const originWriteHead = ServerResponse.prototype.writeHead
180
+ const originSetHeader = ServerResponse.prototype.setHeader
181
+
182
+ ServerResponse.prototype.writeHead = function (statusCode, statusMessage, headers) {
183
+ if (this[kBasePath] !== undefined) {
184
+ if (headers === undefined && typeof statusMessage === 'object') {
185
+ headers = statusMessage
186
+ statusMessage = undefined
187
+ }
188
+
189
+ if (headers) {
190
+ for (const key in headers) {
191
+ if (
192
+ key.toLowerCase() === 'location' &&
193
+ !headers[key].startsWith(basePath)
194
+ ) {
195
+ headers[key] = basePath + headers[key]
196
+ }
197
+ }
198
+ }
199
+ }
200
+
201
+ return originWriteHead.call(this, statusCode, statusMessage, headers)
202
+ }
203
+
204
+ ServerResponse.prototype.setHeader = function (name, value) {
205
+ if (this[kBasePath]) {
206
+ if (name.toLowerCase() === 'location' && !value.startsWith(basePath)) {
207
+ value = basePath + value
208
+ }
209
+ }
210
+ originSetHeader.call(this, name, value)
211
+ }
212
+ }
213
+
155
214
  // No need to catch this because there is the unhadledRejection handler on top.
156
215
  main()
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@platformatic/runtime",
3
- "version": "2.6.0",
3
+ "version": "2.7.0",
4
4
  "description": "",
5
5
  "main": "index.js",
6
6
  "bin": {
@@ -35,11 +35,12 @@
35
35
  "typescript": "^5.5.4",
36
36
  "undici-oidc-interceptor": "^0.5.0",
37
37
  "why-is-node-running": "^2.2.2",
38
- "@platformatic/composer": "2.6.0",
39
- "@platformatic/db": "2.6.0",
40
- "@platformatic/service": "2.6.0",
41
- "@platformatic/sql-graphql": "2.6.0",
42
- "@platformatic/sql-mapper": "2.6.0"
38
+ "@platformatic/composer": "2.7.0",
39
+ "@platformatic/db": "2.7.0",
40
+ "@platformatic/service": "2.7.0",
41
+ "@platformatic/node": "2.7.0",
42
+ "@platformatic/sql-graphql": "2.7.0",
43
+ "@platformatic/sql-mapper": "2.7.0"
43
44
  },
44
45
  "dependencies": {
45
46
  "@fastify/error": "^4.0.0",
@@ -70,13 +71,13 @@
70
71
  "undici": "^6.9.0",
71
72
  "undici-thread-interceptor": "^0.7.0",
72
73
  "ws": "^8.16.0",
73
- "@platformatic/basic": "2.6.0",
74
- "@platformatic/config": "2.6.0",
75
- "@platformatic/generators": "2.6.0",
76
- "@platformatic/itc": "2.6.0",
77
- "@platformatic/telemetry": "2.6.0",
78
- "@platformatic/ts-compiler": "2.6.0",
79
- "@platformatic/utils": "2.6.0"
74
+ "@platformatic/basic": "2.7.0",
75
+ "@platformatic/config": "2.7.0",
76
+ "@platformatic/generators": "2.7.0",
77
+ "@platformatic/ts-compiler": "2.7.0",
78
+ "@platformatic/itc": "2.7.0",
79
+ "@platformatic/telemetry": "2.7.0",
80
+ "@platformatic/utils": "2.7.0"
80
81
  },
81
82
  "scripts": {
82
83
  "test": "npm run lint && borp --concurrency=1 --timeout=180000 && tsd",
package/schema.json CHANGED
@@ -1,5 +1,5 @@
1
1
  {
2
- "$id": "https://schemas.platformatic.dev/@platformatic/runtime/2.6.0.json",
2
+ "$id": "https://schemas.platformatic.dev/@platformatic/runtime/2.7.0.json",
3
3
  "$schema": "http://json-schema.org/draft-07/schema#",
4
4
  "type": "object",
5
5
  "properties": {
@@ -13,6 +13,9 @@
13
13
  "entrypoint": {
14
14
  "type": "string"
15
15
  },
16
+ "basePath": {
17
+ "type": "string"
18
+ },
16
19
  "autoload": {
17
20
  "type": "object",
18
21
  "additionalProperties": false,