@platformatic/composer 2.35.1 → 2.36.2

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 -2
  2. package/package.json +11 -11
  3. package/schema.json +1 -1
package/lib/proxy.js CHANGED
@@ -5,6 +5,9 @@ const httpProxy = require('@fastify/http-proxy')
5
5
  const fp = require('fastify-plugin')
6
6
 
7
7
  const kITC = Symbol.for('plt.runtime.itc')
8
+ const kProxyRoute = Symbol('plt.composer.proxy.route')
9
+
10
+ const urlPattern = /^https?:\/\//
8
11
 
9
12
  async function resolveServiceProxyParameters (service) {
10
13
  // Get meta information from the service, if any, to eventually hook up to a TCP port
@@ -128,13 +131,15 @@ module.exports = fp(async function (app, opts) {
128
131
  // Do not show proxied services in Swagger
129
132
  if (!service.openapi) {
130
133
  app.addHook('onRoute', routeOptions => {
131
- if (routeOptions.url.startsWith(basePath)) {
134
+ if (routeOptions.config?.[kProxyRoute] && routeOptions.url.startsWith(basePath)) {
132
135
  routeOptions.schema ??= {}
133
136
  routeOptions.schema.hide = true
134
137
  }
135
138
  })
136
139
  }
137
140
 
141
+ const toReplace = url?.replace(/127\.0\.0\.1/, 'localhost').replace(/\[::\]/, 'localhost')
142
+
138
143
  const proxyOptions = {
139
144
  websocket: true,
140
145
  prefix,
@@ -143,8 +148,22 @@ module.exports = fp(async function (app, opts) {
143
148
  wsUpstream: url ?? origin,
144
149
  undici: dispatcher,
145
150
  destroyAgent: false,
146
- internalRewriteLocationHeader,
151
+ config: {
152
+ [kProxyRoute]: true
153
+ },
154
+ internalRewriteLocationHeader: false,
147
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
+ },
148
167
  rewriteRequestHeaders: (request, headers) => {
149
168
  const targetUrl = `${origin}${request.url}`
150
169
  const context = request.span?.context
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@platformatic/composer",
3
- "version": "2.35.1",
3
+ "version": "2.36.2",
4
4
  "description": "",
5
5
  "main": "index.js",
6
6
  "bin": {
@@ -30,9 +30,9 @@
30
30
  "typescript": "^5.5.4",
31
31
  "why-is-node-running": "2",
32
32
  "ws": "^8.16.0",
33
- "@platformatic/client": "2.35.1",
34
- "@platformatic/db": "2.35.1",
35
- "@platformatic/config": "2.35.1"
33
+ "@platformatic/config": "2.36.2",
34
+ "@platformatic/client": "2.36.2",
35
+ "@platformatic/db": "2.36.2"
36
36
  },
37
37
  "dependencies": {
38
38
  "@fastify/error": "^4.0.0",
@@ -56,7 +56,7 @@
56
56
  "graphql": "^16.8.1",
57
57
  "help-me": "^5.0.0",
58
58
  "json-schema-traverse": "^1.0.0",
59
- "mercurius": "^15.0.0",
59
+ "mercurius": "^16.0.0",
60
60
  "minimist": "^1.2.8",
61
61
  "my-ua-parser": "^2.0.2",
62
62
  "nunjucks": "^3.2.4",
@@ -66,12 +66,12 @@
66
66
  "rfdc": "^1.3.1",
67
67
  "semgrator": "^0.3.0",
68
68
  "undici": "^7.0.0",
69
- "@platformatic/generators": "2.35.1",
70
- "@platformatic/config": "2.35.1",
71
- "@platformatic/service": "2.35.1",
72
- "@platformatic/telemetry": "2.35.1",
73
- "@platformatic/utils": "^2.35.1",
74
- "@platformatic/scalar-theme": "2.35.1"
69
+ "@platformatic/config": "2.36.2",
70
+ "@platformatic/generators": "2.36.2",
71
+ "@platformatic/service": "2.36.2",
72
+ "@platformatic/telemetry": "2.36.2",
73
+ "@platformatic/utils": "^2.36.2",
74
+ "@platformatic/scalar-theme": "2.36.2"
75
75
  },
76
76
  "scripts": {
77
77
  "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.35.1.json",
2
+ "$id": "https://schemas.platformatic.dev/@platformatic/composer/2.36.2.json",
3
3
  "$schema": "http://json-schema.org/draft-07/schema#",
4
4
  "title": "Platformatic Composer",
5
5
  "type": "object",