@platformatic/gateway 3.43.0 → 3.45.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 CHANGED
@@ -252,6 +252,7 @@ export interface PlatformaticGatewayConfig {
252
252
  routes?: string[];
253
253
  upstream?: string;
254
254
  prefix?: string;
255
+ rewritePrefix?: string;
255
256
  hostname?: string;
256
257
  custom?: {
257
258
  path: string;
package/lib/proxy.js CHANGED
@@ -2,6 +2,7 @@ import httpProxy from '@fastify/http-proxy'
2
2
  import { ensureLoggableError, loadModule } from '@platformatic/foundation'
3
3
  import fp from 'fastify-plugin'
4
4
  import { createRequire } from 'node:module'
5
+ import { resolve } from 'node:path'
5
6
  import { workerData } from 'node:worker_threads'
6
7
  import { getGlobalDispatcher } from 'undici'
7
8
  import { initMetrics } from './metrics.js'
@@ -19,7 +20,7 @@ function isLocalApplication (application) {
19
20
  return application.origin.endsWith('.plt.local')
20
21
  }
21
22
 
22
- async function resolveApplicationProxyParameters (application) {
23
+ async function resolveApplicationProxyParameters (application, root) {
23
24
  // Get meta information from the application, if any, to eventually hook up to a TCP port
24
25
  // Only fetch meta for local applications - remote applications won't be in the runtime
25
26
  let allMeta = {}
@@ -30,7 +31,7 @@ async function resolveApplicationProxyParameters (application) {
30
31
 
31
32
  // If no prefix could be found, assume the application id
32
33
  let prefix = (application.proxy?.prefix ?? meta.prefix ?? application.id).replace(/(\/$)/g, '')
33
- let rewritePrefix = ''
34
+ let rewritePrefix = application.proxy?.rewritePrefix ?? ''
34
35
  let internalRewriteLocationHeader = true
35
36
 
36
37
  if (meta.wantsAbsoluteUrls) {
@@ -43,17 +44,21 @@ async function resolveApplicationProxyParameters (application) {
43
44
 
44
45
  // The rewritePrefix purposely ignores application.proxy?.prefix to let
45
46
  // the application always being able to configure their value
46
- rewritePrefix = meta.prefix ?? application.id
47
- internalRewriteLocationHeader = false
47
+ if (!application.proxy?.rewritePrefix) {
48
+ rewritePrefix = meta.prefix ?? application.id
49
+ internalRewriteLocationHeader = false
50
+ }
48
51
  }
49
52
 
53
+ const require = createRequire(import.meta.filename)
54
+
50
55
  if (application.proxy?.custom) {
51
- const custom = await loadModule(createRequire(import.meta.filename), application.proxy.custom.path)
56
+ const custom = await loadModule(require, resolve(root, application.proxy.custom.path))
52
57
  application.proxy.custom = custom
53
58
  }
54
59
 
55
60
  if (application.proxy?.ws?.hooks) {
56
- const hooks = await loadModule(createRequire(import.meta.filename), application.proxy.ws.hooks.path)
61
+ const hooks = await loadModule(require, resolve(root, application.proxy.ws.hooks.path))
57
62
  application.proxy.ws.hooks = hooks
58
63
  }
59
64
 
@@ -77,6 +82,7 @@ let metrics
77
82
  async function proxyPlugin (app, opts) {
78
83
  const meta = { proxies: {} }
79
84
  const hostnameLessProxies = []
85
+ const root = opts.capability?.root ?? import.meta.dirname
80
86
 
81
87
  for (const application of opts.applications) {
82
88
  if (!application.proxy) {
@@ -87,7 +93,7 @@ async function proxyPlugin (app, opts) {
87
93
  }
88
94
  }
89
95
 
90
- const parameters = await resolveApplicationProxyParameters(application)
96
+ const parameters = await resolveApplicationProxyParameters(application, root)
91
97
  const {
92
98
  prefix,
93
99
  origin,
@@ -181,7 +187,7 @@ async function proxyPlugin (app, opts) {
181
187
  prefix,
182
188
  rewritePrefix,
183
189
  upstream,
184
- preRewrite,
190
+ preRewrite: application.proxy?.custom?.preRewrite ?? preRewrite,
185
191
  preValidation: application.proxy?.custom?.preValidation,
186
192
 
187
193
  websocket: true,
package/lib/schema.js CHANGED
@@ -149,6 +149,7 @@ export const gateway = {
149
149
  },
150
150
  upstream: { type: 'string' },
151
151
  prefix: { type: 'string' },
152
+ rewritePrefix: { type: 'string' },
152
153
  hostname: { type: 'string' },
153
154
  custom: {
154
155
  type: 'object',
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@platformatic/gateway",
3
- "version": "3.43.0",
3
+ "version": "3.45.0",
4
4
  "description": "",
5
5
  "main": "index.js",
6
6
  "types": "index.d.ts",
@@ -32,7 +32,7 @@
32
32
  "typescript": "^5.5.4",
33
33
  "why-is-node-running": "2",
34
34
  "ws": "^8.16.0",
35
- "@platformatic/db": "3.43.0"
35
+ "@platformatic/db": "3.45.0"
36
36
  },
37
37
  "dependencies": {
38
38
  "@fastify/error": "^4.0.0",
@@ -63,11 +63,11 @@
63
63
  "rfdc": "^1.3.1",
64
64
  "semgrator": "^0.3.0",
65
65
  "undici": "^7.0.0",
66
- "@platformatic/basic": "3.43.0",
67
- "@platformatic/scalar-theme": "3.43.0",
68
- "@platformatic/telemetry": "3.43.0",
69
- "@platformatic/service": "3.43.0",
70
- "@platformatic/foundation": "^3.43.0"
66
+ "@platformatic/basic": "3.45.0",
67
+ "@platformatic/foundation": "^3.45.0",
68
+ "@platformatic/scalar-theme": "3.45.0",
69
+ "@platformatic/service": "3.45.0",
70
+ "@platformatic/telemetry": "3.45.0"
71
71
  },
72
72
  "engines": {
73
73
  "node": ">=22.19.0"
package/schema.json CHANGED
@@ -1,5 +1,5 @@
1
1
  {
2
- "$id": "https://schemas.platformatic.dev/@platformatic/gateway/3.43.0.json",
2
+ "$id": "https://schemas.platformatic.dev/@platformatic/gateway/3.45.0.json",
3
3
  "$schema": "http://json-schema.org/draft-07/schema#",
4
4
  "title": "Platformatic Gateway Config",
5
5
  "type": "object",
@@ -837,6 +837,9 @@
837
837
  "prefix": {
838
838
  "type": "string"
839
839
  },
840
+ "rewritePrefix": {
841
+ "type": "string"
842
+ },
840
843
  "hostname": {
841
844
  "type": "string"
842
845
  },