@platformatic/runtime 1.4.1 → 1.5.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.
- package/fixtures/express/platformatic.runtime.json +21 -0
- package/fixtures/express/services/a/platformatic.service.json +14 -0
- package/fixtures/express/services/a/plugin.js +26 -0
- package/fixtures/express/services/b/platformatic.service.json +14 -0
- package/fixtures/express/services/b/plugin.js +19 -0
- package/lib/api.js +6 -0
- package/lib/app.js +5 -6
- package/lib/build-server.js +14 -0
- package/lib/config.js +4 -4
- package/lib/schema.js +25 -1
- package/package.json +16 -14
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
{
|
|
2
|
+
"$schema": "https://platformatic.dev/schemas/v1.3.0/runtime",
|
|
3
|
+
"entrypoint": "b",
|
|
4
|
+
"autoload": {
|
|
5
|
+
"path": "./services",
|
|
6
|
+
"mappings": {
|
|
7
|
+
"a": {
|
|
8
|
+
"id": "a",
|
|
9
|
+
"config": "platformatic.service.json",
|
|
10
|
+
"useHttp": true
|
|
11
|
+
}
|
|
12
|
+
}
|
|
13
|
+
},
|
|
14
|
+
"server": {
|
|
15
|
+
"hostname": "127.0.0.1",
|
|
16
|
+
"port": 3000,
|
|
17
|
+
"logger": {
|
|
18
|
+
"level": "warn"
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
'use strict'
|
|
2
|
+
|
|
3
|
+
const fastifyExpress = require('@fastify/express')
|
|
4
|
+
const express = require('express')
|
|
5
|
+
|
|
6
|
+
module.exports = async function (app) {
|
|
7
|
+
const router = express.Router()
|
|
8
|
+
|
|
9
|
+
router.use(function (req, res, next) {
|
|
10
|
+
res.setHeader('x-custom', true)
|
|
11
|
+
next()
|
|
12
|
+
})
|
|
13
|
+
|
|
14
|
+
router.get('/hello', (req, res) => {
|
|
15
|
+
res.status(200)
|
|
16
|
+
res.json({ hello: 'world' })
|
|
17
|
+
})
|
|
18
|
+
|
|
19
|
+
await app.register(fastifyExpress)
|
|
20
|
+
|
|
21
|
+
app.use(router)
|
|
22
|
+
|
|
23
|
+
app.get('/hello2', (req, res) => {
|
|
24
|
+
return { hello: 'world2' }
|
|
25
|
+
})
|
|
26
|
+
}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
'use strict'
|
|
2
|
+
|
|
3
|
+
const { request } = require('undici')
|
|
4
|
+
|
|
5
|
+
module.exports = async function (fastify) {
|
|
6
|
+
fastify.get('/hello', async (_, reply) => {
|
|
7
|
+
const res = await request('http://a.plt.local/hello')
|
|
8
|
+
reply.log.info('response received')
|
|
9
|
+
const data = await res.body.json()
|
|
10
|
+
return data
|
|
11
|
+
})
|
|
12
|
+
|
|
13
|
+
fastify.get('/hello2', async (_, reply) => {
|
|
14
|
+
const res = await request('http://a.plt.local/hello2')
|
|
15
|
+
reply.log.info('response received')
|
|
16
|
+
const data = await res.body.json()
|
|
17
|
+
return data
|
|
18
|
+
})
|
|
19
|
+
}
|
package/lib/api.js
CHANGED
|
@@ -21,6 +21,12 @@ class RuntimeApi {
|
|
|
21
21
|
let serverConfig = null
|
|
22
22
|
if (config.server && service.entrypoint) {
|
|
23
23
|
serverConfig = config.server
|
|
24
|
+
} else if (service.useHttp) {
|
|
25
|
+
serverConfig = {
|
|
26
|
+
port: 0,
|
|
27
|
+
host: '127.0.0.1',
|
|
28
|
+
keepAliveTimeout: 5000
|
|
29
|
+
}
|
|
24
30
|
}
|
|
25
31
|
const app = new PlatformaticApp(service, loaderPort, logger, serviceTelemetryConfig, serverConfig)
|
|
26
32
|
|
package/lib/app.js
CHANGED
|
@@ -126,7 +126,7 @@ class PlatformaticApp {
|
|
|
126
126
|
this.#startFileWatching()
|
|
127
127
|
}
|
|
128
128
|
|
|
129
|
-
if (this.appConfig.entrypoint) {
|
|
129
|
+
if (this.appConfig.entrypoint || this.appConfig.useHttp) {
|
|
130
130
|
try {
|
|
131
131
|
await this.server.start()
|
|
132
132
|
/* c8 ignore next 5 */
|
|
@@ -232,11 +232,10 @@ class PlatformaticApp {
|
|
|
232
232
|
}
|
|
233
233
|
|
|
234
234
|
#setuplogger (configManager) {
|
|
235
|
-
// Set the logger if not present
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
}
|
|
235
|
+
// Set the logger if not present
|
|
236
|
+
configManager.current.server = configManager.current.server || {}
|
|
237
|
+
const childLogger = this.#logger.child({}, { level: configManager.current.server.logger?.level || 'info' })
|
|
238
|
+
configManager.current.server.logger = childLogger
|
|
240
239
|
}
|
|
241
240
|
|
|
242
241
|
#startFileWatching () {
|
package/lib/build-server.js
CHANGED
|
@@ -6,7 +6,17 @@ const { buildServer: buildServerService } = require('@platformatic/service')
|
|
|
6
6
|
const { loadConfig } = require('./load-config')
|
|
7
7
|
|
|
8
8
|
async function buildServerRuntime (options = {}) {
|
|
9
|
+
const {
|
|
10
|
+
serviceMap,
|
|
11
|
+
loggingPort,
|
|
12
|
+
loggingMetadata
|
|
13
|
+
} = options
|
|
14
|
+
|
|
9
15
|
if (!options.configManager) {
|
|
16
|
+
delete options.serviceMap
|
|
17
|
+
delete options.loggingPort
|
|
18
|
+
delete options.loggingMetadata
|
|
19
|
+
|
|
10
20
|
// Instantiate a new config manager from the current options.
|
|
11
21
|
const cm = new ConfigManager({
|
|
12
22
|
...platformaticRuntime.configManagerConfig,
|
|
@@ -14,6 +24,10 @@ async function buildServerRuntime (options = {}) {
|
|
|
14
24
|
})
|
|
15
25
|
await cm.parseAndValidate()
|
|
16
26
|
|
|
27
|
+
cm.current.loggingPort = loggingPort
|
|
28
|
+
cm.current.loggingMetadata = loggingMetadata
|
|
29
|
+
cm.current.serviceMap = serviceMap
|
|
30
|
+
|
|
17
31
|
if (typeof options === 'string') {
|
|
18
32
|
options = { configManager: cm }
|
|
19
33
|
} else {
|
package/lib/config.js
CHANGED
|
@@ -33,13 +33,13 @@ async function _transformConfig (configManager) {
|
|
|
33
33
|
|
|
34
34
|
const config = join(entryPath, configFilename)
|
|
35
35
|
|
|
36
|
-
services.push({ id, config, path: entryPath })
|
|
36
|
+
services.push({ id, config, path: entryPath, useHttp: !!mapping.useHttp })
|
|
37
37
|
}
|
|
38
38
|
}
|
|
39
39
|
|
|
40
40
|
configManager.current.allowCycles = !!configManager.current.allowCycles
|
|
41
41
|
configManager.current.serviceMap = new Map()
|
|
42
|
-
configManager.current.inspectorOptions =
|
|
42
|
+
configManager.current.inspectorOptions = undefined
|
|
43
43
|
|
|
44
44
|
let hasValidEntrypoint = false
|
|
45
45
|
|
|
@@ -276,10 +276,10 @@ async function wrapConfigInRuntimeConfig ({ configManager, args }) {
|
|
|
276
276
|
coerceTypes: true,
|
|
277
277
|
allErrors: true,
|
|
278
278
|
strict: false
|
|
279
|
-
}
|
|
279
|
+
},
|
|
280
|
+
transformConfig () { return _transformConfig(this) }
|
|
280
281
|
})
|
|
281
282
|
|
|
282
|
-
await _transformConfig(cm)
|
|
283
283
|
await cm.parseAndValidate()
|
|
284
284
|
return cm
|
|
285
285
|
}
|
package/lib/schema.js
CHANGED
|
@@ -38,6 +38,9 @@ const platformaticRuntimeSchema = {
|
|
|
38
38
|
},
|
|
39
39
|
config: {
|
|
40
40
|
type: 'string'
|
|
41
|
+
},
|
|
42
|
+
useHttp: {
|
|
43
|
+
type: 'boolean'
|
|
41
44
|
}
|
|
42
45
|
}
|
|
43
46
|
}
|
|
@@ -62,6 +65,9 @@ const platformaticRuntimeSchema = {
|
|
|
62
65
|
},
|
|
63
66
|
config: {
|
|
64
67
|
type: 'string'
|
|
68
|
+
},
|
|
69
|
+
useHttp: {
|
|
70
|
+
type: 'boolean'
|
|
65
71
|
}
|
|
66
72
|
}
|
|
67
73
|
}
|
|
@@ -82,6 +88,23 @@ const platformaticRuntimeSchema = {
|
|
|
82
88
|
allowCycles: {
|
|
83
89
|
type: 'boolean'
|
|
84
90
|
},
|
|
91
|
+
inspectorOptions: {
|
|
92
|
+
type: 'object',
|
|
93
|
+
properties: {
|
|
94
|
+
host: {
|
|
95
|
+
type: 'string'
|
|
96
|
+
},
|
|
97
|
+
port: {
|
|
98
|
+
type: 'number'
|
|
99
|
+
},
|
|
100
|
+
breakFirstLine: {
|
|
101
|
+
type: 'boolean'
|
|
102
|
+
},
|
|
103
|
+
hotReloadDisabled: {
|
|
104
|
+
type: 'boolean'
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
},
|
|
85
108
|
$schema: {
|
|
86
109
|
type: 'string'
|
|
87
110
|
}
|
|
@@ -89,7 +112,8 @@ const platformaticRuntimeSchema = {
|
|
|
89
112
|
anyOf: [
|
|
90
113
|
{ required: ['autoload', 'entrypoint'] },
|
|
91
114
|
{ required: ['services', 'entrypoint'] }
|
|
92
|
-
]
|
|
115
|
+
],
|
|
116
|
+
additionalProperties: false
|
|
93
117
|
}
|
|
94
118
|
|
|
95
119
|
module.exports.schema = platformaticRuntimeSchema
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@platformatic/runtime",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.5.1",
|
|
4
4
|
"description": "",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"bin": {
|
|
@@ -17,19 +17,21 @@
|
|
|
17
17
|
},
|
|
18
18
|
"homepage": "https://github.com/platformatic/platformatic#readme",
|
|
19
19
|
"devDependencies": {
|
|
20
|
+
"@fastify/express": "^2.3.0",
|
|
20
21
|
"c8": "^8.0.1",
|
|
21
22
|
"execa": "^8.0.1",
|
|
23
|
+
"express": "^4.18.2",
|
|
22
24
|
"glob": "^10.3.10",
|
|
23
25
|
"snazzy": "^9.0.0",
|
|
24
26
|
"split2": "^4.2.0",
|
|
25
27
|
"standard": "^17.1.0",
|
|
26
28
|
"tsd": "^0.29.0",
|
|
27
29
|
"typescript": "^5.2.2",
|
|
28
|
-
"@platformatic/sql-graphql": "1.
|
|
29
|
-
"@platformatic/sql-mapper": "1.
|
|
30
|
+
"@platformatic/sql-graphql": "1.5.1",
|
|
31
|
+
"@platformatic/sql-mapper": "1.5.1"
|
|
30
32
|
},
|
|
31
33
|
"dependencies": {
|
|
32
|
-
"@fastify/error": "^3.
|
|
34
|
+
"@fastify/error": "^3.4.0",
|
|
33
35
|
"@hapi/topo": "^6.0.2",
|
|
34
36
|
"close-with-grace": "^1.2.0",
|
|
35
37
|
"commist": "^3.2.0",
|
|
@@ -37,19 +39,19 @@
|
|
|
37
39
|
"desm": "^1.3.0",
|
|
38
40
|
"es-main": "^1.3.0",
|
|
39
41
|
"fastest-levenshtein": "^1.0.16",
|
|
40
|
-
"fastify": "^4.
|
|
42
|
+
"fastify": "^4.24.1",
|
|
41
43
|
"fastify-undici-dispatcher": "^0.5.0",
|
|
42
44
|
"help-me": "^4.2.0",
|
|
43
45
|
"minimist": "^1.2.8",
|
|
44
|
-
"pino": "^8.
|
|
45
|
-
"pino-pretty": "^10.2.
|
|
46
|
-
"undici": "^5.
|
|
47
|
-
"@platformatic/composer": "1.
|
|
48
|
-
"@platformatic/config": "1.
|
|
49
|
-
"@platformatic/db": "1.
|
|
50
|
-
"@platformatic/service": "1.
|
|
51
|
-
"@platformatic/telemetry": "1.
|
|
52
|
-
"@platformatic/utils": "1.
|
|
46
|
+
"pino": "^8.16.0",
|
|
47
|
+
"pino-pretty": "^10.2.3",
|
|
48
|
+
"undici": "^5.26.3",
|
|
49
|
+
"@platformatic/composer": "1.5.1",
|
|
50
|
+
"@platformatic/config": "1.5.1",
|
|
51
|
+
"@platformatic/db": "1.5.1",
|
|
52
|
+
"@platformatic/service": "1.5.1",
|
|
53
|
+
"@platformatic/telemetry": "1.5.1",
|
|
54
|
+
"@platformatic/utils": "1.5.1"
|
|
53
55
|
},
|
|
54
56
|
"standard": {
|
|
55
57
|
"ignore": [
|