@platformatic/basic 2.0.0-alpha.3 → 2.0.0-alpha.5
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/NOTICE +13 -0
- package/README.md +13 -0
- package/config.d.ts +11 -0
- package/eslint.config.js +3 -1
- package/index.js +63 -77
- package/lib/base.js +11 -9
- package/lib/errors.js +8 -0
- package/lib/schema.js +31 -15
- package/lib/utils.js +6 -39
- package/lib/worker/child-manager.js +90 -0
- package/lib/worker/child-process.js +150 -0
- package/lib/worker/server-listener.js +29 -0
- package/package.json +18 -11
- package/schema.json +12 -0
- package/test/helper.js +116 -16
- package/lib/server.js +0 -135
- package/test/express.test.js +0 -34
- package/test/fastify.test.js +0 -34
- package/test/fixtures/express/no-build/index.js +0 -16
- package/test/fixtures/express/no-build/package.json +0 -7
- package/test/fixtures/express/no-build/platformatic.app.json +0 -3
- package/test/fixtures/express/no-build/platformatic.as-entrypoint.runtime.json +0 -19
- package/test/fixtures/express/no-build/platformatic.no-entrypoint.runtime.json +0 -16
- package/test/fixtures/express/with-build/index.js +0 -17
- package/test/fixtures/express/with-build/package.json +0 -7
- package/test/fixtures/express/with-build/platformatic.app.json +0 -3
- package/test/fixtures/express/with-build/platformatic.as-entrypoint.runtime.json +0 -19
- package/test/fixtures/express/with-build/platformatic.no-entrypoint.runtime.json +0 -16
- package/test/fixtures/fastify/no-build/index.js +0 -14
- package/test/fixtures/fastify/no-build/package.json +0 -7
- package/test/fixtures/fastify/no-build/platformatic.app.json +0 -3
- package/test/fixtures/fastify/no-build/platformatic.as-entrypoint.runtime.json +0 -19
- package/test/fixtures/fastify/no-build/platformatic.no-entrypoint.runtime.json +0 -16
- package/test/fixtures/fastify/with-build/index.js +0 -15
- package/test/fixtures/fastify/with-build/package.json +0 -7
- package/test/fixtures/fastify/with-build/platformatic.app.json +0 -3
- package/test/fixtures/fastify/with-build/platformatic.as-entrypoint.runtime.json +0 -19
- package/test/fixtures/fastify/with-build/platformatic.no-entrypoint.runtime.json +0 -16
- package/test/fixtures/nodejs/no-build/index.js +0 -21
- package/test/fixtures/nodejs/no-build/package.json +0 -7
- package/test/fixtures/nodejs/no-build/platformatic.app.json +0 -3
- package/test/fixtures/nodejs/no-build/platformatic.as-entrypoint.runtime.json +0 -19
- package/test/fixtures/nodejs/no-build/platformatic.no-entrypoint.runtime.json +0 -16
- package/test/fixtures/nodejs/no-configuration/index.js +0 -21
- package/test/fixtures/nodejs/no-configuration/platformatic.as-entrypoint.runtime.json +0 -18
- package/test/fixtures/nodejs/no-configuration/platformatic.no-entrypoint.runtime.json +0 -16
- package/test/fixtures/nodejs/with-build/index.js +0 -20
- package/test/fixtures/nodejs/with-build/package.json +0 -7
- package/test/fixtures/nodejs/with-build/platformatic.app.json +0 -3
- package/test/fixtures/nodejs/with-build/platformatic.as-entrypoint.runtime.json +0 -19
- package/test/fixtures/nodejs/with-build/platformatic.no-entrypoint.runtime.json +0 -16
- package/test/fixtures/platformatic-service/platformatic.service.json +0 -15
- package/test/fixtures/platformatic-service/plugin.js +0 -12
- package/test/node.test.js +0 -66
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"$schema": "https://schemas.platformatic.dev/@platformatic/runtime/1.52.0.json",
|
|
3
|
-
"entrypoint": "main",
|
|
4
|
-
"watch": false,
|
|
5
|
-
"managementApi": false,
|
|
6
|
-
"metrics": false,
|
|
7
|
-
"server": {
|
|
8
|
-
"logger": {
|
|
9
|
-
"level": "error"
|
|
10
|
-
}
|
|
11
|
-
},
|
|
12
|
-
"services": [
|
|
13
|
-
{
|
|
14
|
-
"id": "main",
|
|
15
|
-
"path": ".",
|
|
16
|
-
"config": "platformatic.app.json"
|
|
17
|
-
}
|
|
18
|
-
]
|
|
19
|
-
}
|
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"$schema": "https://schemas.platformatic.dev/@platformatic/runtime/1.52.0.json",
|
|
3
|
-
"entrypoint": "main",
|
|
4
|
-
"watch": false,
|
|
5
|
-
"managementApi": false,
|
|
6
|
-
"metrics": false,
|
|
7
|
-
"server": {
|
|
8
|
-
"logger": {
|
|
9
|
-
"level": "error"
|
|
10
|
-
}
|
|
11
|
-
},
|
|
12
|
-
"services": [
|
|
13
|
-
{ "id": "main", "path": "../../platformatic-service", "config": "platformatic.service.json" },
|
|
14
|
-
{ "id": "internal", "path": ".", "config": "platformatic.app.json" }
|
|
15
|
-
]
|
|
16
|
-
}
|
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
import { createServer } from 'node:http'
|
|
2
|
-
|
|
3
|
-
const server = createServer((req, res) => {
|
|
4
|
-
if (req.url === '/direct') {
|
|
5
|
-
res.writeHead(200, { 'content-type': 'application/json', connection: 'close' })
|
|
6
|
-
res.end(JSON.stringify({ ok: true }))
|
|
7
|
-
} else if (req.url === '/mesh') {
|
|
8
|
-
fetch('http://main.plt.local/direct')
|
|
9
|
-
.then(response => response.json())
|
|
10
|
-
.then(json => {
|
|
11
|
-
res.writeHead(200, { 'content-type': 'application/json', connection: 'close' })
|
|
12
|
-
res.end(JSON.stringify({ ok: true }))
|
|
13
|
-
})
|
|
14
|
-
} else {
|
|
15
|
-
res.writeHead(404, { 'content-type': 'application/json', connection: 'close' })
|
|
16
|
-
res.end(JSON.stringify({ ok: false }))
|
|
17
|
-
}
|
|
18
|
-
})
|
|
19
|
-
|
|
20
|
-
// This would likely fail if our code doesn't work
|
|
21
|
-
server.listen(1)
|
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"$schema": "https://schemas.platformatic.dev/@platformatic/runtime/1.52.0.json",
|
|
3
|
-
"entrypoint": "main",
|
|
4
|
-
"watch": false,
|
|
5
|
-
"managementApi": true,
|
|
6
|
-
"metrics": false,
|
|
7
|
-
"server": {
|
|
8
|
-
"logger": {
|
|
9
|
-
"level": "warn"
|
|
10
|
-
}
|
|
11
|
-
},
|
|
12
|
-
"services": [
|
|
13
|
-
{
|
|
14
|
-
"id": "main",
|
|
15
|
-
"path": ".",
|
|
16
|
-
"config": "platformatic.app.json"
|
|
17
|
-
}
|
|
18
|
-
]
|
|
19
|
-
}
|
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"$schema": "https://schemas.platformatic.dev/@platformatic/runtime/1.52.0.json",
|
|
3
|
-
"entrypoint": "main",
|
|
4
|
-
"watch": false,
|
|
5
|
-
"managementApi": true,
|
|
6
|
-
"metrics": false,
|
|
7
|
-
"server": {
|
|
8
|
-
"logger": {
|
|
9
|
-
"level": "warn"
|
|
10
|
-
}
|
|
11
|
-
},
|
|
12
|
-
"services": [
|
|
13
|
-
{ "id": "main", "path": "../../platformatic-service", "config": "platformatic.service.json" },
|
|
14
|
-
{ "id": "internal", "path": ".", "config": "platformatic.app.json" }
|
|
15
|
-
]
|
|
16
|
-
}
|
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
import { createServer } from 'node:http'
|
|
2
|
-
|
|
3
|
-
const server = createServer((req, res) => {
|
|
4
|
-
if (req.url === '/direct') {
|
|
5
|
-
res.writeHead(200, { 'content-type': 'application/json', connection: 'close' })
|
|
6
|
-
res.end(JSON.stringify({ ok: true }))
|
|
7
|
-
} else if (req.url === '/mesh') {
|
|
8
|
-
fetch('http://main.plt.local/direct')
|
|
9
|
-
.then(response => response.json())
|
|
10
|
-
.then(json => {
|
|
11
|
-
res.writeHead(200, { 'content-type': 'application/json', connection: 'close' })
|
|
12
|
-
res.end(JSON.stringify({ ok: true }))
|
|
13
|
-
})
|
|
14
|
-
} else {
|
|
15
|
-
res.writeHead(404, { 'content-type': 'application/json', connection: 'close' })
|
|
16
|
-
res.end(JSON.stringify({ ok: false }))
|
|
17
|
-
}
|
|
18
|
-
})
|
|
19
|
-
|
|
20
|
-
// This would likely fail if our code doesn't work
|
|
21
|
-
server.listen(1)
|
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"$schema": "https://schemas.platformatic.dev/@platformatic/runtime/1.52.0.json",
|
|
3
|
-
"entrypoint": "main",
|
|
4
|
-
"watch": false,
|
|
5
|
-
"managementApi": true,
|
|
6
|
-
"metrics": false,
|
|
7
|
-
"server": {
|
|
8
|
-
"logger": {
|
|
9
|
-
"level": "warn"
|
|
10
|
-
}
|
|
11
|
-
},
|
|
12
|
-
"services": [
|
|
13
|
-
{
|
|
14
|
-
"id": "main",
|
|
15
|
-
"path": "."
|
|
16
|
-
}
|
|
17
|
-
]
|
|
18
|
-
}
|
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"$schema": "https://schemas.platformatic.dev/@platformatic/runtime/1.52.0.json",
|
|
3
|
-
"entrypoint": "main",
|
|
4
|
-
"watch": false,
|
|
5
|
-
"managementApi": true,
|
|
6
|
-
"metrics": false,
|
|
7
|
-
"server": {
|
|
8
|
-
"logger": {
|
|
9
|
-
"level": "warn"
|
|
10
|
-
}
|
|
11
|
-
},
|
|
12
|
-
"services": [
|
|
13
|
-
{ "id": "main", "path": "../../platformatic-service", "config": "platformatic.service.json" },
|
|
14
|
-
{ "id": "internal", "path": "." }
|
|
15
|
-
]
|
|
16
|
-
}
|
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
import { createServer } from 'node:http'
|
|
2
|
-
|
|
3
|
-
export function build () {
|
|
4
|
-
return createServer((req, res) => {
|
|
5
|
-
if (req.url === '/direct') {
|
|
6
|
-
res.writeHead(200, { 'content-type': 'application/json', connection: 'close' })
|
|
7
|
-
res.end(JSON.stringify({ ok: true }))
|
|
8
|
-
} else if (req.url === '/mesh') {
|
|
9
|
-
fetch('http://main.plt.local/direct')
|
|
10
|
-
.then(response => response.json())
|
|
11
|
-
.then(json => {
|
|
12
|
-
res.writeHead(200, { 'content-type': 'application/json', connection: 'close' })
|
|
13
|
-
res.end(JSON.stringify({ ok: true }))
|
|
14
|
-
})
|
|
15
|
-
} else {
|
|
16
|
-
res.writeHead(404, { 'content-type': 'application/json', connection: 'close' })
|
|
17
|
-
res.end(JSON.stringify({ ok: false }))
|
|
18
|
-
}
|
|
19
|
-
})
|
|
20
|
-
}
|
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"$schema": "https://schemas.platformatic.dev/@platformatic/runtime/1.52.0.json",
|
|
3
|
-
"entrypoint": "main",
|
|
4
|
-
"watch": false,
|
|
5
|
-
"managementApi": true,
|
|
6
|
-
"metrics": false,
|
|
7
|
-
"server": {
|
|
8
|
-
"logger": {
|
|
9
|
-
"level": "warn"
|
|
10
|
-
}
|
|
11
|
-
},
|
|
12
|
-
"services": [
|
|
13
|
-
{
|
|
14
|
-
"id": "main",
|
|
15
|
-
"path": ".",
|
|
16
|
-
"config": "platformatic.app.json"
|
|
17
|
-
}
|
|
18
|
-
]
|
|
19
|
-
}
|
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"$schema": "https://schemas.platformatic.dev/@platformatic/runtime/1.52.0.json",
|
|
3
|
-
"entrypoint": "main",
|
|
4
|
-
"watch": false,
|
|
5
|
-
"managementApi": true,
|
|
6
|
-
"metrics": false,
|
|
7
|
-
"server": {
|
|
8
|
-
"logger": {
|
|
9
|
-
"level": "warn"
|
|
10
|
-
}
|
|
11
|
-
},
|
|
12
|
-
"services": [
|
|
13
|
-
{ "id": "main", "path": "../../platformatic-service", "config": "platformatic.service.json" },
|
|
14
|
-
{ "id": "internal", "path": ".", "config": "platformatic.app.json" }
|
|
15
|
-
]
|
|
16
|
-
}
|
package/test/node.test.js
DELETED
|
@@ -1,66 +0,0 @@
|
|
|
1
|
-
import { deepStrictEqual, ifError } from 'node:assert'
|
|
2
|
-
import { test } from 'node:test'
|
|
3
|
-
import { createRuntime, getLogs, verifyViaHTTP, verifyViaInject } from './helper.js'
|
|
4
|
-
|
|
5
|
-
test('can detect and start a Node.js application with no configuration files', async t => {
|
|
6
|
-
const { runtime, url } = await createRuntime(t, 'nodejs/no-configuration/platformatic.as-entrypoint.runtime.json')
|
|
7
|
-
|
|
8
|
-
await verifyViaHTTP(url, '/direct', 200, { ok: true })
|
|
9
|
-
await verifyViaInject(runtime, 'main', 'GET', '/direct', 200, { ok: true })
|
|
10
|
-
|
|
11
|
-
const logs = await getLogs(runtime)
|
|
12
|
-
deepStrictEqual(
|
|
13
|
-
logs.map(m => m.msg),
|
|
14
|
-
['The service main had no valid entrypoint defined in the package.json file. Falling back to the file index.js.']
|
|
15
|
-
)
|
|
16
|
-
})
|
|
17
|
-
|
|
18
|
-
test('can detect and start a Node.js application with no configuration files and when not the entrypoint', async t => {
|
|
19
|
-
const { runtime, url } = await createRuntime(t, 'nodejs/no-configuration/platformatic.no-entrypoint.runtime.json')
|
|
20
|
-
|
|
21
|
-
await verifyViaHTTP(url, '/mesh', 200, { ok: true })
|
|
22
|
-
await verifyViaInject(runtime, 'main', 'GET', '/mesh', 200, { ok: true })
|
|
23
|
-
|
|
24
|
-
const logs = await getLogs(runtime)
|
|
25
|
-
|
|
26
|
-
deepStrictEqual(
|
|
27
|
-
logs.map(m => m.msg),
|
|
28
|
-
[
|
|
29
|
-
'The service internal had no valid entrypoint defined in the package.json file. Falling back to the file index.js.',
|
|
30
|
-
]
|
|
31
|
-
)
|
|
32
|
-
})
|
|
33
|
-
|
|
34
|
-
test('can detect and start a Node.js application with no build function defined', async t => {
|
|
35
|
-
const { runtime, url } = await createRuntime(t, 'nodejs/no-build/platformatic.as-entrypoint.runtime.json')
|
|
36
|
-
|
|
37
|
-
await verifyViaHTTP(url, '/direct', 200, { ok: true })
|
|
38
|
-
await verifyViaInject(runtime, 'main', 'GET', '/direct', 200, { ok: true })
|
|
39
|
-
|
|
40
|
-
const logs = await getLogs(runtime)
|
|
41
|
-
deepStrictEqual(logs, [])
|
|
42
|
-
})
|
|
43
|
-
|
|
44
|
-
test('can detect and start a Node.js application with no build function and when not the entrypoint', async t => {
|
|
45
|
-
const { runtime, url } = await createRuntime(t, 'nodejs/no-build/platformatic.no-entrypoint.runtime.json')
|
|
46
|
-
|
|
47
|
-
await verifyViaHTTP(url, '/mesh', 200, { ok: true })
|
|
48
|
-
await verifyViaInject(runtime, 'main', 'GET', '/mesh', 200, { ok: true })
|
|
49
|
-
})
|
|
50
|
-
|
|
51
|
-
test('can detect and start a Node.js application with build function defined', async t => {
|
|
52
|
-
const { runtime, url } = await createRuntime(t, 'nodejs/with-build/platformatic.as-entrypoint.runtime.json')
|
|
53
|
-
|
|
54
|
-
await verifyViaHTTP(url, '/direct', 200, { ok: true })
|
|
55
|
-
await verifyViaInject(runtime, 'main', 'GET', '/direct', 200, { ok: true })
|
|
56
|
-
})
|
|
57
|
-
|
|
58
|
-
test('can detect and start a Node.js application with build function defined and when not the entrypoint', async t => {
|
|
59
|
-
const { runtime, url } = await createRuntime(t, 'nodejs/no-build/platformatic.no-entrypoint.runtime.json')
|
|
60
|
-
|
|
61
|
-
await verifyViaHTTP(url, '/mesh', 200, { ok: true })
|
|
62
|
-
await verifyViaInject(runtime, 'main', 'GET', '/mesh', 200, { ok: true })
|
|
63
|
-
|
|
64
|
-
const details = await runtime.getServiceDetails('internal')
|
|
65
|
-
ifError(details.url)
|
|
66
|
-
})
|