@platformatic/composer 2.27.1 → 2.28.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.
- package/config.d.ts +1 -0
- package/index.js +8 -0
- package/lib/proxy/not-host-constraints.js +33 -0
- package/lib/proxy.js +20 -2
- package/lib/schema.js +2 -1
- package/package.json +12 -12
- package/schema.json +4 -1
package/config.d.ts
CHANGED
package/index.js
CHANGED
|
@@ -12,6 +12,7 @@ const composerHook = require('./lib/composer-hook')
|
|
|
12
12
|
const openapiGenerator = require('./lib/openapi-generator')
|
|
13
13
|
const graphqlGenerator = require('./lib/graphql-generator')
|
|
14
14
|
const { isSameGraphqlSchema, fetchGraphqlSubgraphs } = require('./lib/graphql-fetch')
|
|
15
|
+
const notHostConstraints = require('./lib/proxy/not-host-constraints')
|
|
15
16
|
const { isFetchable } = require('./lib/utils')
|
|
16
17
|
const { ComposerStackable, ensureServices } = require('./lib/stackable')
|
|
17
18
|
const errors = require('./lib/errors')
|
|
@@ -184,6 +185,13 @@ async function watchServices (app, opts) {
|
|
|
184
185
|
}
|
|
185
186
|
|
|
186
187
|
async function buildComposerStackable (options) {
|
|
188
|
+
options.context ??= {}
|
|
189
|
+
options.context.fastifyOptions ??= {
|
|
190
|
+
constraints: {
|
|
191
|
+
notHost: notHostConstraints
|
|
192
|
+
}
|
|
193
|
+
}
|
|
194
|
+
|
|
187
195
|
return buildStackable(options, platformaticComposer, ComposerStackable)
|
|
188
196
|
}
|
|
189
197
|
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
'use strict'
|
|
2
|
+
|
|
3
|
+
module.exports = {
|
|
4
|
+
name: 'notHost',
|
|
5
|
+
storage: () => {
|
|
6
|
+
const store = []
|
|
7
|
+
|
|
8
|
+
return {
|
|
9
|
+
get (host) {
|
|
10
|
+
if (typeof host === 'string') {
|
|
11
|
+
for (const [hosts, value] of store) {
|
|
12
|
+
if (!hosts.includes(host)) {
|
|
13
|
+
return value
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
return null
|
|
19
|
+
},
|
|
20
|
+
set: (hosts, value) => {
|
|
21
|
+
store.push([hosts, value])
|
|
22
|
+
},
|
|
23
|
+
store
|
|
24
|
+
}
|
|
25
|
+
},
|
|
26
|
+
deriveConstraint: req => {
|
|
27
|
+
return req.headers.host || req.headers[':authority']
|
|
28
|
+
},
|
|
29
|
+
mustMatchWhenDerived: false,
|
|
30
|
+
validate () {
|
|
31
|
+
return true
|
|
32
|
+
}
|
|
33
|
+
}
|
package/lib/proxy.js
CHANGED
|
@@ -36,6 +36,7 @@ async function resolveServiceProxyParameters (service) {
|
|
|
36
36
|
|
|
37
37
|
module.exports = fp(async function (app, opts) {
|
|
38
38
|
const meta = { proxies: {} }
|
|
39
|
+
const allDomains = opts.services.map(s => s.proxy?.hostname).filter(Boolean)
|
|
39
40
|
|
|
40
41
|
for (const service of opts.services) {
|
|
41
42
|
if (!service.proxy) {
|
|
@@ -134,7 +135,7 @@ module.exports = fp(async function (app, opts) {
|
|
|
134
135
|
})
|
|
135
136
|
}
|
|
136
137
|
|
|
137
|
-
|
|
138
|
+
const proxyOptions = {
|
|
138
139
|
websocket: true,
|
|
139
140
|
prefix,
|
|
140
141
|
rewritePrefix,
|
|
@@ -173,7 +174,24 @@ module.exports = fp(async function (app, opts) {
|
|
|
173
174
|
reply.send(res.stream)
|
|
174
175
|
}
|
|
175
176
|
}
|
|
176
|
-
}
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
const host = service.proxy?.hostname
|
|
180
|
+
const notHost = allDomains.filter(d => d !== host)
|
|
181
|
+
|
|
182
|
+
if (host) {
|
|
183
|
+
await app.register(httpProxy, {
|
|
184
|
+
...proxyOptions,
|
|
185
|
+
constraints: { host }
|
|
186
|
+
})
|
|
187
|
+
|
|
188
|
+
await app.register(httpProxy, {
|
|
189
|
+
...proxyOptions,
|
|
190
|
+
...(notHost.length ? { constraints: { notHost } } : {})
|
|
191
|
+
})
|
|
192
|
+
} else {
|
|
193
|
+
await app.register(httpProxy, proxyOptions)
|
|
194
|
+
}
|
|
177
195
|
}
|
|
178
196
|
|
|
179
197
|
opts.context?.stackable?.registerMeta(meta)
|
package/lib/schema.js
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@platformatic/composer",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.28.0",
|
|
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.
|
|
34
|
-
"@platformatic/config": "2.
|
|
35
|
-
"@platformatic/db": "2.
|
|
33
|
+
"@platformatic/client": "2.28.0",
|
|
34
|
+
"@platformatic/config": "2.28.0",
|
|
35
|
+
"@platformatic/db": "2.28.0"
|
|
36
36
|
},
|
|
37
37
|
"dependencies": {
|
|
38
38
|
"@fastify/error": "^4.0.0",
|
|
@@ -48,7 +48,7 @@
|
|
|
48
48
|
"console-table-printer": "^2.12.0",
|
|
49
49
|
"desm": "^1.3.1",
|
|
50
50
|
"es-main": "^1.3.0",
|
|
51
|
-
"execa": "^
|
|
51
|
+
"execa": "^9.0.0",
|
|
52
52
|
"fast-deep-equal": "^3.1.3",
|
|
53
53
|
"fastify": "^5.0.0",
|
|
54
54
|
"@platformatic/fastify-openapi-glue": "^5.0.0",
|
|
@@ -61,17 +61,17 @@
|
|
|
61
61
|
"my-ua-parser": "^2.0.2",
|
|
62
62
|
"nunjucks": "^3.2.4",
|
|
63
63
|
"ora": "^6.3.1",
|
|
64
|
-
"pino": "^
|
|
64
|
+
"pino": "^9.0.0",
|
|
65
65
|
"pino-pretty": "^13.0.0",
|
|
66
66
|
"rfdc": "^1.3.1",
|
|
67
67
|
"semgrator": "^0.3.0",
|
|
68
68
|
"undici": "^7.0.0",
|
|
69
|
-
"@platformatic/
|
|
70
|
-
"@platformatic/
|
|
71
|
-
"@platformatic/service": "2.
|
|
72
|
-
"@platformatic/
|
|
73
|
-
"@platformatic/
|
|
74
|
-
"@platformatic/
|
|
69
|
+
"@platformatic/config": "2.28.0",
|
|
70
|
+
"@platformatic/scalar-theme": "2.28.0",
|
|
71
|
+
"@platformatic/service": "2.28.0",
|
|
72
|
+
"@platformatic/utils": "^2.28.0",
|
|
73
|
+
"@platformatic/telemetry": "2.28.0",
|
|
74
|
+
"@platformatic/generators": "2.28.0"
|
|
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.
|
|
2
|
+
"$id": "https://schemas.platformatic.dev/@platformatic/composer/2.28.0.json",
|
|
3
3
|
"$schema": "http://json-schema.org/draft-07/schema#",
|
|
4
4
|
"title": "Platformatic Composer",
|
|
5
5
|
"type": "object",
|
|
@@ -727,6 +727,9 @@
|
|
|
727
727
|
"properties": {
|
|
728
728
|
"prefix": {
|
|
729
729
|
"type": "string"
|
|
730
|
+
},
|
|
731
|
+
"hostname": {
|
|
732
|
+
"type": "string"
|
|
730
733
|
}
|
|
731
734
|
},
|
|
732
735
|
"required": [],
|