@platformatic/node 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/LICENSE +201 -0
- package/NOTICE +13 -0
- package/README.md +13 -0
- package/config.d.ts +153 -0
- package/eslint.config.js +3 -0
- package/index.js +230 -0
- package/lib/schema.js +25 -0
- package/package.json +42 -0
- package/schema.json +497 -0
- package/test/express.test.js +54 -0
- package/test/fastify.test.js +54 -0
- package/test/fixtures/express/no-build/index.js +16 -0
- package/test/fixtures/express/no-build/package.json +7 -0
- package/test/fixtures/express/no-build/platformatic.application.json +3 -0
- package/test/fixtures/express/no-build/platformatic.as-entrypoint.runtime.json +19 -0
- package/test/fixtures/express/no-build/platformatic.no-entrypoint.runtime.json +16 -0
- package/test/fixtures/express/with-build/index.js +17 -0
- package/test/fixtures/express/with-build/package.json +7 -0
- package/test/fixtures/express/with-build/platformatic.application.json +3 -0
- package/test/fixtures/express/with-build/platformatic.as-entrypoint.runtime.json +19 -0
- package/test/fixtures/express/with-build/platformatic.no-entrypoint.runtime.json +16 -0
- package/test/fixtures/fastify/no-build/index.js +14 -0
- package/test/fixtures/fastify/no-build/package.json +7 -0
- package/test/fixtures/fastify/no-build/platformatic.application.json +3 -0
- package/test/fixtures/fastify/no-build/platformatic.as-entrypoint.runtime.json +19 -0
- package/test/fixtures/fastify/no-build/platformatic.no-entrypoint.runtime.json +16 -0
- package/test/fixtures/fastify/with-build/index.js +15 -0
- package/test/fixtures/fastify/with-build/package.json +7 -0
- package/test/fixtures/fastify/with-build/platformatic.application.json +3 -0
- package/test/fixtures/fastify/with-build/platformatic.as-entrypoint.runtime.json +19 -0
- package/test/fixtures/fastify/with-build/platformatic.no-entrypoint.runtime.json +16 -0
- package/test/fixtures/nodejs/no-build/index.js +21 -0
- package/test/fixtures/nodejs/no-build/package.json +7 -0
- package/test/fixtures/nodejs/no-build/platformatic.application.json +3 -0
- package/test/fixtures/nodejs/no-build/platformatic.as-entrypoint.runtime.json +19 -0
- package/test/fixtures/nodejs/no-build/platformatic.no-entrypoint.runtime.json +16 -0
- package/test/fixtures/nodejs/no-configuration/index.js +21 -0
- package/test/fixtures/nodejs/no-configuration/platformatic.as-entrypoint.runtime.json +18 -0
- package/test/fixtures/nodejs/no-configuration/platformatic.no-entrypoint.runtime.json +16 -0
- package/test/fixtures/nodejs/with-build/index.js +20 -0
- package/test/fixtures/nodejs/with-build/package.json +7 -0
- package/test/fixtures/nodejs/with-build/platformatic.application.json +3 -0
- package/test/fixtures/nodejs/with-build/platformatic.as-entrypoint.runtime.json +19 -0
- package/test/fixtures/nodejs/with-build/platformatic.no-entrypoint.runtime.json +16 -0
- package/test/fixtures/platformatic-service/platformatic.service.json +15 -0
- package/test/fixtures/platformatic-service/plugin.js +12 -0
- package/test/node.test.js +100 -0
|
@@ -0,0 +1,19 @@
|
|
|
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.application.json"
|
|
17
|
+
}
|
|
18
|
+
]
|
|
19
|
+
}
|
|
@@ -0,0 +1,16 @@
|
|
|
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.application.json" }
|
|
15
|
+
]
|
|
16
|
+
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import fastify from 'fastify'
|
|
2
|
+
|
|
3
|
+
const app = fastify()
|
|
4
|
+
|
|
5
|
+
app.get('/direct', async () => {
|
|
6
|
+
return { ok: true }
|
|
7
|
+
})
|
|
8
|
+
|
|
9
|
+
app.get('/internal', () => {
|
|
10
|
+
return fetch('http://main.plt.local/direct').then(response => response.json())
|
|
11
|
+
})
|
|
12
|
+
|
|
13
|
+
// This would likely fail if our code doesn't work
|
|
14
|
+
app.listen({ port: 1 })
|
|
@@ -0,0 +1,19 @@
|
|
|
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.application.json"
|
|
17
|
+
}
|
|
18
|
+
]
|
|
19
|
+
}
|
|
@@ -0,0 +1,16 @@
|
|
|
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.application.json" }
|
|
15
|
+
]
|
|
16
|
+
}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import fastify from 'fastify'
|
|
2
|
+
|
|
3
|
+
export function build () {
|
|
4
|
+
const app = fastify()
|
|
5
|
+
|
|
6
|
+
app.get('/direct', async () => {
|
|
7
|
+
return { ok: true }
|
|
8
|
+
})
|
|
9
|
+
|
|
10
|
+
app.get('/internal', () => {
|
|
11
|
+
return fetch('http://main.plt.local/direct').then(response => response.json())
|
|
12
|
+
})
|
|
13
|
+
|
|
14
|
+
return app
|
|
15
|
+
}
|
|
@@ -0,0 +1,19 @@
|
|
|
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.application.json"
|
|
17
|
+
}
|
|
18
|
+
]
|
|
19
|
+
}
|
|
@@ -0,0 +1,16 @@
|
|
|
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.application.json" }
|
|
15
|
+
]
|
|
16
|
+
}
|
|
@@ -0,0 +1,21 @@
|
|
|
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)
|
|
@@ -0,0 +1,19 @@
|
|
|
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.application.json"
|
|
17
|
+
}
|
|
18
|
+
]
|
|
19
|
+
}
|
|
@@ -0,0 +1,16 @@
|
|
|
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.application.json" }
|
|
15
|
+
]
|
|
16
|
+
}
|
|
@@ -0,0 +1,21 @@
|
|
|
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)
|
|
@@ -0,0 +1,18 @@
|
|
|
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
|
+
}
|
|
@@ -0,0 +1,16 @@
|
|
|
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
|
+
}
|
|
@@ -0,0 +1,20 @@
|
|
|
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
|
+
}
|
|
@@ -0,0 +1,19 @@
|
|
|
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.application.json"
|
|
17
|
+
}
|
|
18
|
+
]
|
|
19
|
+
}
|
|
@@ -0,0 +1,16 @@
|
|
|
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.application.json" }
|
|
15
|
+
]
|
|
16
|
+
}
|
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
import { deepStrictEqual, ifError } from 'node:assert'
|
|
2
|
+
import { resolve } from 'node:path'
|
|
3
|
+
import { test } from 'node:test'
|
|
4
|
+
import {
|
|
5
|
+
createRuntime,
|
|
6
|
+
getLogs,
|
|
7
|
+
setFixturesDir,
|
|
8
|
+
verifyJSONViaHTTP,
|
|
9
|
+
verifyJSONViaInject,
|
|
10
|
+
} from '../../basic/test/helper.js'
|
|
11
|
+
|
|
12
|
+
const packageRoot = resolve(import.meta.dirname, '..')
|
|
13
|
+
setFixturesDir(resolve(import.meta.dirname, './fixtures'))
|
|
14
|
+
|
|
15
|
+
test('can detect and start a Node.js application with no configuration files', async t => {
|
|
16
|
+
const { runtime, url } = await createRuntime(
|
|
17
|
+
t,
|
|
18
|
+
'nodejs/no-configuration/platformatic.as-entrypoint.runtime.json',
|
|
19
|
+
packageRoot
|
|
20
|
+
)
|
|
21
|
+
|
|
22
|
+
await verifyJSONViaHTTP(url, '/direct', 200, { ok: true })
|
|
23
|
+
await verifyJSONViaInject(runtime, 'main', 'GET', '/direct', 200, { ok: true })
|
|
24
|
+
|
|
25
|
+
const logs = await getLogs(runtime)
|
|
26
|
+
deepStrictEqual(
|
|
27
|
+
logs.map(m => m.msg),
|
|
28
|
+
['The service main had no valid entrypoint defined in the package.json file. Falling back to the file index.js.']
|
|
29
|
+
)
|
|
30
|
+
})
|
|
31
|
+
|
|
32
|
+
test('can detect and start a Node.js application with no configuration files and when not the entrypoint', async t => {
|
|
33
|
+
const { runtime, url } = await createRuntime(
|
|
34
|
+
t,
|
|
35
|
+
'nodejs/no-configuration/platformatic.no-entrypoint.runtime.json',
|
|
36
|
+
packageRoot
|
|
37
|
+
)
|
|
38
|
+
|
|
39
|
+
await verifyJSONViaHTTP(url, '/mesh', 200, { ok: true })
|
|
40
|
+
await verifyJSONViaInject(runtime, 'main', 'GET', '/mesh', 200, { ok: true })
|
|
41
|
+
|
|
42
|
+
const logs = await getLogs(runtime)
|
|
43
|
+
|
|
44
|
+
deepStrictEqual(
|
|
45
|
+
logs.map(m => m.msg),
|
|
46
|
+
[
|
|
47
|
+
'The service internal had no valid entrypoint defined in the package.json file. Falling back to the file index.js.',
|
|
48
|
+
]
|
|
49
|
+
)
|
|
50
|
+
})
|
|
51
|
+
|
|
52
|
+
test('can detect and start a Node.js application with no build function defined', async t => {
|
|
53
|
+
const { runtime, url } = await createRuntime(
|
|
54
|
+
t,
|
|
55
|
+
'nodejs/no-build/platformatic.as-entrypoint.runtime.json',
|
|
56
|
+
packageRoot
|
|
57
|
+
)
|
|
58
|
+
|
|
59
|
+
await verifyJSONViaHTTP(url, '/direct', 200, { ok: true })
|
|
60
|
+
await verifyJSONViaInject(runtime, 'main', 'GET', '/direct', 200, { ok: true })
|
|
61
|
+
|
|
62
|
+
const logs = await getLogs(runtime)
|
|
63
|
+
deepStrictEqual(logs, [])
|
|
64
|
+
})
|
|
65
|
+
|
|
66
|
+
test('can detect and start a Node.js application with no build function and when not the entrypoint', async t => {
|
|
67
|
+
const { runtime, url } = await createRuntime(
|
|
68
|
+
t,
|
|
69
|
+
'nodejs/no-build/platformatic.no-entrypoint.runtime.json',
|
|
70
|
+
packageRoot
|
|
71
|
+
)
|
|
72
|
+
|
|
73
|
+
await verifyJSONViaHTTP(url, '/mesh', 200, { ok: true })
|
|
74
|
+
await verifyJSONViaInject(runtime, 'main', 'GET', '/mesh', 200, { ok: true })
|
|
75
|
+
})
|
|
76
|
+
|
|
77
|
+
test('can detect and start a Node.js application with build function defined', async t => {
|
|
78
|
+
const { runtime, url } = await createRuntime(
|
|
79
|
+
t,
|
|
80
|
+
'nodejs/with-build/platformatic.as-entrypoint.runtime.json',
|
|
81
|
+
packageRoot
|
|
82
|
+
)
|
|
83
|
+
|
|
84
|
+
await verifyJSONViaHTTP(url, '/direct', 200, { ok: true })
|
|
85
|
+
await verifyJSONViaInject(runtime, 'main', 'GET', '/direct', 200, { ok: true })
|
|
86
|
+
})
|
|
87
|
+
|
|
88
|
+
test('can detect and start a Node.js application with build function defined and when not the entrypoint', async t => {
|
|
89
|
+
const { runtime, url } = await createRuntime(
|
|
90
|
+
t,
|
|
91
|
+
'nodejs/no-build/platformatic.no-entrypoint.runtime.json',
|
|
92
|
+
packageRoot
|
|
93
|
+
)
|
|
94
|
+
|
|
95
|
+
await verifyJSONViaHTTP(url, '/mesh', 200, { ok: true })
|
|
96
|
+
await verifyJSONViaInject(runtime, 'main', 'GET', '/mesh', 200, { ok: true })
|
|
97
|
+
|
|
98
|
+
const details = await runtime.getServiceDetails('internal')
|
|
99
|
+
ifError(details.url)
|
|
100
|
+
})
|