@platformatic/composer 2.71.0-alpha.1 → 2.71.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 +15 -31
  2. package/package.json +12 -12
  3. package/schema.json +1 -1
package/lib/proxy.js CHANGED
@@ -45,7 +45,7 @@ async function resolveServiceProxyParameters (service) {
45
45
  prefix,
46
46
  rewritePrefix,
47
47
  internalRewriteLocationHeader,
48
- needsRootRedirect: meta.needsRootRedirect,
48
+ needsRootTrailingSlash: meta.needsRootTrailingSlash,
49
49
  needsRefererBasedRedirect: meta.needsRefererBasedRedirect,
50
50
  upstream: service.proxy?.upstream,
51
51
  ws: service.proxy?.ws
@@ -72,7 +72,7 @@ module.exports = fp(async function (app, opts) {
72
72
  url,
73
73
  rewritePrefix,
74
74
  internalRewriteLocationHeader,
75
- needsRootRedirect,
75
+ needsRootTrailingSlash,
76
76
  needsRefererBasedRedirect,
77
77
  ws
78
78
  } = parameters
@@ -81,34 +81,16 @@ module.exports = fp(async function (app, opts) {
81
81
  const basePath = `/${prefix ?? ''}`.replaceAll(/\/+/g, '/').replace(/\/$/, '')
82
82
  const dispatcher = getGlobalDispatcher()
83
83
 
84
- if (needsRootRedirect) {
85
- app.addHook('preHandler', (req, reply, done) => {
86
- if (req.url === basePath) {
87
- app.inject(
88
- {
89
- method: req.method,
90
- url: `${basePath}/`,
91
- headers: req.headers,
92
- payload: req.body
93
- },
94
- (err, result) => {
95
- if (err) {
96
- done(err)
97
- return
98
- }
99
-
100
- const replyHeaders = result.headers
101
- delete replyHeaders['content-length']
102
- delete replyHeaders['transfer-encoding']
103
-
104
- reply.code(result.statusCode).headers(replyHeaders).send(result.rawPayload)
105
- done()
106
- }
107
- )
108
- } else {
109
- done()
84
+ let preRewrite = null
85
+
86
+ if (needsRootTrailingSlash) {
87
+ preRewrite = function preRewrite (url) {
88
+ if (url === basePath) {
89
+ url += '/'
110
90
  }
111
- })
91
+
92
+ return url
93
+ }
112
94
  }
113
95
 
114
96
  /*
@@ -118,7 +100,7 @@ module.exports = fp(async function (app, opts) {
118
100
  from the Referer header.
119
101
  */
120
102
  if (needsRefererBasedRedirect) {
121
- app.addHook('preHandler', (req, reply, done) => {
103
+ app.addHook('preHandler', function refererBasedRedirectPreHandler (req, reply, done) {
122
104
  // If the URL is already targeted to the service, do nothing
123
105
  if (req.url.startsWith(basePath)) {
124
106
  done()
@@ -164,11 +146,12 @@ module.exports = fp(async function (app, opts) {
164
146
  : null
165
147
 
166
148
  const proxyOptions = {
167
- websocket: true,
168
149
  prefix,
169
150
  rewritePrefix,
170
151
  upstream: service.proxy?.upstream ?? origin,
152
+ preRewrite,
171
153
 
154
+ websocket: true,
172
155
  wsUpstream: ws?.upstream ?? url ?? origin,
173
156
  wsReconnect: ws?.reconnect,
174
157
  wsHooks: {
@@ -185,6 +168,7 @@ module.exports = fp(async function (app, opts) {
185
168
  config: {
186
169
  [kProxyRoute]: true
187
170
  },
171
+
188
172
  internalRewriteLocationHeader: false,
189
173
  replyOptions: {
190
174
  rewriteHeaders: headers => {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@platformatic/composer",
3
- "version": "2.71.0-alpha.1",
3
+ "version": "2.71.0",
4
4
  "description": "",
5
5
  "main": "index.js",
6
6
  "bin": {
@@ -32,20 +32,20 @@
32
32
  "typescript": "^5.5.4",
33
33
  "why-is-node-running": "2",
34
34
  "ws": "^8.16.0",
35
- "@platformatic/client": "2.71.0-alpha.1",
36
- "@platformatic/config": "2.71.0-alpha.1",
37
- "@platformatic/db": "2.71.0-alpha.1"
35
+ "@platformatic/config": "2.71.0",
36
+ "@platformatic/client": "2.71.0",
37
+ "@platformatic/db": "2.71.0"
38
38
  },
39
39
  "dependencies": {
40
40
  "@fastify/error": "^4.0.0",
41
- "@fastify/http-proxy": "^11.1.1",
41
+ "@fastify/http-proxy": "^11.3.0",
42
42
  "@fastify/reply-from": "^12.0.0",
43
43
  "@fastify/static": "^8.0.0",
44
44
  "@fastify/swagger": "^9.0.0",
45
45
  "@fastify/view": "^10.0.1",
46
46
  "@platformatic/fastify-openapi-glue": "^5.1.0",
47
47
  "@platformatic/graphql-composer": "^0.10.0",
48
- "@scalar/fastify-api-reference": "1.31.8",
48
+ "@scalar/fastify-api-reference": "1.31.14",
49
49
  "ajv": "^8.12.0",
50
50
  "commist": "^3.2.0",
51
51
  "console-table-printer": "^2.12.0",
@@ -68,12 +68,12 @@
68
68
  "rfdc": "^1.3.1",
69
69
  "semgrator": "^0.3.0",
70
70
  "undici": "^7.0.0",
71
- "@platformatic/config": "2.71.0-alpha.1",
72
- "@platformatic/generators": "2.71.0-alpha.1",
73
- "@platformatic/scalar-theme": "2.71.0-alpha.1",
74
- "@platformatic/telemetry": "2.71.0-alpha.1",
75
- "@platformatic/utils": "^2.71.0-alpha.1",
76
- "@platformatic/service": "2.71.0-alpha.1"
71
+ "@platformatic/config": "2.71.0",
72
+ "@platformatic/scalar-theme": "2.71.0",
73
+ "@platformatic/generators": "2.71.0",
74
+ "@platformatic/service": "2.71.0",
75
+ "@platformatic/telemetry": "2.71.0",
76
+ "@platformatic/utils": "^2.71.0"
77
77
  },
78
78
  "scripts": {
79
79
  "test": "pnpm run lint && borp -T --timeout=1200000 -c 1 && tsd",
package/schema.json CHANGED
@@ -1,5 +1,5 @@
1
1
  {
2
- "$id": "https://schemas.platformatic.dev/@platformatic/composer/2.71.0-alpha.1.json",
2
+ "$id": "https://schemas.platformatic.dev/@platformatic/composer/2.71.0.json",
3
3
  "$schema": "http://json-schema.org/draft-07/schema#",
4
4
  "title": "Platformatic Composer",
5
5
  "type": "object",