@platformatic/composer 2.41.0 → 2.42.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.
Files changed (3) hide show
  1. package/lib/proxy.js +21 -6
  2. package/package.json +10 -10
  3. package/schema.json +1 -1
package/lib/proxy.js CHANGED
@@ -1,8 +1,9 @@
1
1
  'use strict'
2
2
 
3
- const { getGlobalDispatcher } = require('undici')
4
3
  const httpProxy = require('@fastify/http-proxy')
5
4
  const fp = require('fastify-plugin')
5
+ const { workerData } = require('node:worker_threads')
6
+ const { getGlobalDispatcher } = require('undici')
6
7
 
7
8
  const kITC = Symbol.for('plt.runtime.itc')
8
9
  const kProxyRoute = Symbol('plt.composer.proxy.route')
@@ -14,12 +15,18 @@ async function resolveServiceProxyParameters (service) {
14
15
  const meta = (await globalThis[kITC]?.send('getServiceMeta', service.id))?.composer ?? { prefix: service.id }
15
16
 
16
17
  // If no prefix could be found, assume the service id
17
- const prefix = (service.proxy?.prefix ?? meta.prefix ?? service.id).replace(/(\/$)/g, '')
18
-
18
+ let prefix = (service.proxy?.prefix ?? meta.prefix ?? service.id).replace(/(\/$)/g, '')
19
19
  let rewritePrefix = ''
20
20
  let internalRewriteLocationHeader = true
21
21
 
22
22
  if (meta.wantsAbsoluteUrls) {
23
+ const basePath = workerData.config.basePath
24
+
25
+ // Strip the runtime basepath from the prefix when it comes from the service meta
26
+ if (basePath && !service.proxy?.prefix && prefix.startsWith(basePath)) {
27
+ prefix = prefix.substring(basePath.length)
28
+ }
29
+
23
30
  // The rewritePrefix purposely ignores service.proxy?.prefix to let
24
31
  // the service always being able to configure their value
25
32
  rewritePrefix = meta.prefix ?? service.id
@@ -138,7 +145,14 @@ module.exports = fp(async function (app, opts) {
138
145
  })
139
146
  }
140
147
 
141
- const toReplace = url ? new RegExp(url.replace(/127\.0\.0\.1/, 'localhost').replace(/\[::\]/, 'localhost').replace('http://', 'https?://')) : null
148
+ const toReplace = url
149
+ ? new RegExp(
150
+ url
151
+ .replace(/127\.0\.0\.1/, 'localhost')
152
+ .replace(/\[::\]/, 'localhost')
153
+ .replace('http://', 'https?://')
154
+ )
155
+ : null
142
156
 
143
157
  const proxyOptions = {
144
158
  websocket: true,
@@ -153,7 +167,7 @@ module.exports = fp(async function (app, opts) {
153
167
  },
154
168
  internalRewriteLocationHeader: false,
155
169
  replyOptions: {
156
- rewriteHeaders: (headers) => {
170
+ rewriteHeaders: headers => {
157
171
  let location = headers.location
158
172
  if (location) {
159
173
  if (toReplace) {
@@ -186,7 +200,7 @@ module.exports = fp(async function (app, opts) {
186
200
  ...telemetryHeaders,
187
201
  'x-forwarded-for': request.ip,
188
202
  'x-forwarded-host': request.host,
189
- 'x-forwarded-proto': request.protocol,
203
+ 'x-forwarded-proto': request.protocol
190
204
  }
191
205
 
192
206
  request.log.trace({ headers }, 'rewritten headers before proxying')
@@ -209,6 +223,7 @@ module.exports = fp(async function (app, opts) {
209
223
  if (host) {
210
224
  await app.register(httpProxy, {
211
225
  ...proxyOptions,
226
+ prefix: '/',
212
227
  constraints: { host }
213
228
  })
214
229
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@platformatic/composer",
3
- "version": "2.41.0",
3
+ "version": "2.42.0",
4
4
  "description": "",
5
5
  "main": "index.js",
6
6
  "bin": {
@@ -31,9 +31,9 @@
31
31
  "typescript": "^5.5.4",
32
32
  "why-is-node-running": "2",
33
33
  "ws": "^8.16.0",
34
- "@platformatic/client": "2.41.0",
35
- "@platformatic/config": "2.41.0",
36
- "@platformatic/db": "2.41.0"
34
+ "@platformatic/client": "2.42.0",
35
+ "@platformatic/config": "2.42.0",
36
+ "@platformatic/db": "2.42.0"
37
37
  },
38
38
  "dependencies": {
39
39
  "@fastify/error": "^4.0.0",
@@ -67,12 +67,12 @@
67
67
  "rfdc": "^1.3.1",
68
68
  "semgrator": "^0.3.0",
69
69
  "undici": "^7.0.0",
70
- "@platformatic/config": "2.41.0",
71
- "@platformatic/scalar-theme": "2.41.0",
72
- "@platformatic/generators": "2.41.0",
73
- "@platformatic/utils": "^2.41.0",
74
- "@platformatic/telemetry": "2.41.0",
75
- "@platformatic/service": "2.41.0"
70
+ "@platformatic/generators": "2.42.0",
71
+ "@platformatic/scalar-theme": "2.42.0",
72
+ "@platformatic/telemetry": "2.42.0",
73
+ "@platformatic/service": "2.42.0",
74
+ "@platformatic/utils": "^2.42.0",
75
+ "@platformatic/config": "2.42.0"
76
76
  },
77
77
  "scripts": {
78
78
  "test": "pnpm run lint && borp -T --timeout=300000 -c 1 && tsd",
package/schema.json CHANGED
@@ -1,5 +1,5 @@
1
1
  {
2
- "$id": "https://schemas.platformatic.dev/@platformatic/composer/2.41.0.json",
2
+ "$id": "https://schemas.platformatic.dev/@platformatic/composer/2.42.0.json",
3
3
  "$schema": "http://json-schema.org/draft-07/schema#",
4
4
  "title": "Platformatic Composer",
5
5
  "type": "object",