@platformatic/composer 2.36.1 → 2.37.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 +18 -2
  2. package/package.json +12 -11
  3. package/schema.json +1 -1
package/lib/proxy.js CHANGED
@@ -7,6 +7,8 @@ const fp = require('fastify-plugin')
7
7
  const kITC = Symbol.for('plt.runtime.itc')
8
8
  const kProxyRoute = Symbol('plt.composer.proxy.route')
9
9
 
10
+ const urlPattern = /^https?:\/\//
11
+
10
12
  async function resolveServiceProxyParameters (service) {
11
13
  // Get meta information from the service, if any, to eventually hook up to a TCP port
12
14
  const meta = (await globalThis[kITC]?.send('getServiceMeta', service.id))?.composer ?? { prefix: service.id }
@@ -136,6 +138,8 @@ module.exports = fp(async function (app, opts) {
136
138
  })
137
139
  }
138
140
 
141
+ const toReplace = url?.replace(/127\.0\.0\.1/, 'localhost').replace(/\[::\]/, 'localhost')
142
+
139
143
  const proxyOptions = {
140
144
  websocket: true,
141
145
  prefix,
@@ -147,8 +151,19 @@ module.exports = fp(async function (app, opts) {
147
151
  config: {
148
152
  [kProxyRoute]: true
149
153
  },
150
- internalRewriteLocationHeader,
154
+ internalRewriteLocationHeader: false,
151
155
  replyOptions: {
156
+ rewriteHeaders: (headers) => {
157
+ let location = headers.location
158
+ if (location) {
159
+ location = location.replace(toReplace, '')
160
+ if (location && !urlPattern.test(location) && internalRewriteLocationHeader) {
161
+ location = location.replace(rewritePrefix, prefix)
162
+ }
163
+ headers.location = location
164
+ }
165
+ return headers
166
+ },
152
167
  rewriteRequestHeaders: (request, headers) => {
153
168
  const targetUrl = `${origin}${request.url}`
154
169
  const context = request.span?.context
@@ -168,7 +183,8 @@ module.exports = fp(async function (app, opts) {
168
183
  ...headers,
169
184
  ...telemetryHeaders,
170
185
  'x-forwarded-for': request.ip,
171
- 'x-forwarded-host': request.host
186
+ 'x-forwarded-host': request.host,
187
+ 'x-forwarded-proto': request.protocol,
172
188
  }
173
189
 
174
190
  return headers
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@platformatic/composer",
3
- "version": "2.36.1",
3
+ "version": "2.37.0",
4
4
  "description": "",
5
5
  "main": "index.js",
6
6
  "bin": {
@@ -24,15 +24,16 @@
24
24
  "json-schema-to-typescript": "^15.0.0",
25
25
  "neostandard": "^0.12.0",
26
26
  "openapi-schema-validator": "^12.1.3",
27
+ "self-cert": "^2.0.0",
27
28
  "single-user-cache": "^1.0.1",
28
29
  "split2": "^4.2.0",
29
30
  "tsd": "^0.31.0",
30
31
  "typescript": "^5.5.4",
31
32
  "why-is-node-running": "2",
32
33
  "ws": "^8.16.0",
33
- "@platformatic/client": "2.36.1",
34
- "@platformatic/config": "2.36.1",
35
- "@platformatic/db": "2.36.1"
34
+ "@platformatic/client": "2.37.0",
35
+ "@platformatic/db": "2.37.0",
36
+ "@platformatic/config": "2.37.0"
36
37
  },
37
38
  "dependencies": {
38
39
  "@fastify/error": "^4.0.0",
@@ -41,6 +42,7 @@
41
42
  "@fastify/static": "^8.0.0",
42
43
  "@fastify/swagger": "^9.0.0",
43
44
  "@fastify/view": "^10.0.1",
45
+ "@platformatic/fastify-openapi-glue": "^5.0.0",
44
46
  "@platformatic/graphql-composer": "^0.10.0",
45
47
  "@scalar/fastify-api-reference": "^1.19.5",
46
48
  "ajv": "^8.12.0",
@@ -51,7 +53,6 @@
51
53
  "execa": "^9.0.0",
52
54
  "fast-deep-equal": "^3.1.3",
53
55
  "fastify": "^5.0.0",
54
- "@platformatic/fastify-openapi-glue": "^5.0.0",
55
56
  "fastify-plugin": "^5.0.0",
56
57
  "graphql": "^16.8.1",
57
58
  "help-me": "^5.0.0",
@@ -66,12 +67,12 @@
66
67
  "rfdc": "^1.3.1",
67
68
  "semgrator": "^0.3.0",
68
69
  "undici": "^7.0.0",
69
- "@platformatic/config": "2.36.1",
70
- "@platformatic/generators": "2.36.1",
71
- "@platformatic/scalar-theme": "2.36.1",
72
- "@platformatic/telemetry": "2.36.1",
73
- "@platformatic/utils": "^2.36.1",
74
- "@platformatic/service": "2.36.1"
70
+ "@platformatic/config": "2.37.0",
71
+ "@platformatic/generators": "2.37.0",
72
+ "@platformatic/scalar-theme": "2.37.0",
73
+ "@platformatic/utils": "^2.37.0",
74
+ "@platformatic/telemetry": "2.37.0",
75
+ "@platformatic/service": "2.37.0"
75
76
  },
76
77
  "scripts": {
77
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.36.1.json",
2
+ "$id": "https://schemas.platformatic.dev/@platformatic/composer/2.37.0.json",
3
3
  "$schema": "http://json-schema.org/draft-07/schema#",
4
4
  "title": "Platformatic Composer",
5
5
  "type": "object",