@platformatic/runtime 1.4.1 → 1.5.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/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/config.js +1 -1
- package/lib/schema.js +6 -0
- 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/config.js
CHANGED
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
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@platformatic/runtime",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.5.0",
|
|
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.0",
|
|
31
|
+
"@platformatic/sql-mapper": "1.5.0"
|
|
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.0",
|
|
50
|
+
"@platformatic/config": "1.5.0",
|
|
51
|
+
"@platformatic/db": "1.5.0",
|
|
52
|
+
"@platformatic/service": "1.5.0",
|
|
53
|
+
"@platformatic/telemetry": "1.5.0",
|
|
54
|
+
"@platformatic/utils": "1.5.0"
|
|
53
55
|
},
|
|
54
56
|
"standard": {
|
|
55
57
|
"ignore": [
|