@platformatic/composer 2.70.1 → 2.71.0-alpha.1

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 +29 -12
  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
- needsRootTrailingSlash: meta.needsRootTrailingSlash,
48
+ needsRootRedirect: meta.needsRootRedirect,
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
- needsRootTrailingSlash,
75
+ needsRootRedirect,
76
76
  needsRefererBasedRedirect,
77
77
  ws
78
78
  } = parameters
@@ -81,15 +81,33 @@ module.exports = fp(async function (app, opts) {
81
81
  const basePath = `/${prefix ?? ''}`.replaceAll(/\/+/g, '/').replace(/\/$/, '')
82
82
  const dispatcher = getGlobalDispatcher()
83
83
 
84
- if (needsRootTrailingSlash) {
85
- app.addHook('preHandler', function rootTrailingSlashPreHandler (req, reply, done) {
86
- if (req.url !== basePath) {
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 {
87
109
  done()
88
- return
89
110
  }
90
-
91
- const { url, options } = reply.fromParameters(req.url + '/', req.params, prefix)
92
- reply.from(url.replace(/\/+$/, '/'), options)
93
111
  })
94
112
  }
95
113
 
@@ -100,7 +118,7 @@ module.exports = fp(async function (app, opts) {
100
118
  from the Referer header.
101
119
  */
102
120
  if (needsRefererBasedRedirect) {
103
- app.addHook('preHandler', function refererBasedRedirectPreHandler (req, reply, done) {
121
+ app.addHook('preHandler', (req, reply, done) => {
104
122
  // If the URL is already targeted to the service, do nothing
105
123
  if (req.url.startsWith(basePath)) {
106
124
  done()
@@ -146,11 +164,11 @@ module.exports = fp(async function (app, opts) {
146
164
  : null
147
165
 
148
166
  const proxyOptions = {
167
+ websocket: true,
149
168
  prefix,
150
169
  rewritePrefix,
151
170
  upstream: service.proxy?.upstream ?? origin,
152
171
 
153
- websocket: true,
154
172
  wsUpstream: ws?.upstream ?? url ?? origin,
155
173
  wsReconnect: ws?.reconnect,
156
174
  wsHooks: {
@@ -167,7 +185,6 @@ module.exports = fp(async function (app, opts) {
167
185
  config: {
168
186
  [kProxyRoute]: true
169
187
  },
170
-
171
188
  internalRewriteLocationHeader: false,
172
189
  replyOptions: {
173
190
  rewriteHeaders: headers => {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@platformatic/composer",
3
- "version": "2.70.1",
3
+ "version": "2.71.0-alpha.1",
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/config": "2.70.1",
36
- "@platformatic/client": "2.70.1",
37
- "@platformatic/db": "2.70.1"
35
+ "@platformatic/client": "2.71.0-alpha.1",
36
+ "@platformatic/config": "2.71.0-alpha.1",
37
+ "@platformatic/db": "2.71.0-alpha.1"
38
38
  },
39
39
  "dependencies": {
40
40
  "@fastify/error": "^4.0.0",
41
- "@fastify/http-proxy": "^11.2.0",
41
+ "@fastify/http-proxy": "^11.1.1",
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.14",
48
+ "@scalar/fastify-api-reference": "1.31.8",
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.70.1",
72
- "@platformatic/scalar-theme": "2.70.1",
73
- "@platformatic/service": "2.70.1",
74
- "@platformatic/telemetry": "2.70.1",
75
- "@platformatic/generators": "2.70.1",
76
- "@platformatic/utils": "^2.70.1"
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"
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.70.1.json",
2
+ "$id": "https://schemas.platformatic.dev/@platformatic/composer/2.71.0-alpha.1.json",
3
3
  "$schema": "http://json-schema.org/draft-07/schema#",
4
4
  "title": "Platformatic Composer",
5
5
  "type": "object",