@platformatic/service 0.46.1 → 0.46.2

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.
Files changed (119) hide show
  1. package/package.json +6 -6
  2. package/fixtures/hello/no-server-logger.json +0 -13
  3. package/fixtures/hello/platformatic.service.json +0 -18
  4. package/fixtures/hello/plugin.js +0 -7
  5. package/fixtures/hello/warn-log.service.json +0 -18
  6. package/fixtures/hello-client/hello/hello.cjs +0 -21
  7. package/fixtures/hello-client/hello/hello.d.ts +0 -34
  8. package/fixtures/hello-client/hello/hello.openapi.json +0 -22
  9. package/fixtures/hello-client/hello/package.json +0 -5
  10. package/fixtures/hello-client/platformatic.service.json +0 -19
  11. package/fixtures/hello-client/plugin.js +0 -8
  12. package/fixtures/hello-client-ts/hello/hello.cjs +0 -21
  13. package/fixtures/hello-client-ts/hello/hello.d.ts +0 -34
  14. package/fixtures/hello-client-ts/hello/hello.openapi.json +0 -22
  15. package/fixtures/hello-client-ts/hello/package.json +0 -5
  16. package/fixtures/hello-client-ts/platformatic.service.json +0 -21
  17. package/fixtures/hello-client-ts/plugin.ts +0 -8
  18. package/fixtures/hello-client-ts/tsconfig.json +0 -23
  19. package/fixtures/hello-client-ts-without-deps/hello.d.ts +0 -34
  20. package/fixtures/hello-client-ts-without-deps/hello.openapi.json +0 -22
  21. package/fixtures/hello-client-ts-without-deps/platformatic.service.json +0 -23
  22. package/fixtures/hello-client-ts-without-deps/plugin.ts +0 -8
  23. package/fixtures/hello-client-ts-without-deps/tsconfig.json +0 -22
  24. package/fixtures/hello-client-without-deps/hello.d.ts +0 -34
  25. package/fixtures/hello-client-without-deps/hello.openapi.json +0 -22
  26. package/fixtures/hello-client-without-deps/platformatic.service.json +0 -21
  27. package/fixtures/hello-client-without-deps/plugin.js +0 -8
  28. package/fixtures/https/embedded-pem.json +0 -20
  29. package/fixtures/https/https.crt +0 -25
  30. package/fixtures/https/https.key +0 -27
  31. package/fixtures/https/pem-path.json +0 -20
  32. package/fixtures/https/plugin.js +0 -7
  33. package/fixtures/options/platformatic.service.yml +0 -9
  34. package/fixtures/options/plugin.js +0 -7
  35. package/test/autoload.test.js +0 -486
  36. package/test/cli/compile-1.test.mjs +0 -352
  37. package/test/cli/compile-2.test.mjs +0 -310
  38. package/test/cli/gen-schema.test.mjs +0 -44
  39. package/test/cli/gen-types.test.mjs +0 -30
  40. package/test/cli/helper.mjs +0 -67
  41. package/test/cli/start.test.mjs +0 -126
  42. package/test/cli/tap-parallel-not-ok +0 -0
  43. package/test/cli/validations.test.mjs +0 -33
  44. package/test/clients.test.js +0 -87
  45. package/test/config.test.js +0 -316
  46. package/test/cors.test.js +0 -291
  47. package/test/fixtures/bad-typescript-plugin/platformatic.service.json +0 -16
  48. package/test/fixtures/bad-typescript-plugin/plugin.ts +0 -5
  49. package/test/fixtures/bad-typescript-plugin/tsconfig.json +0 -22
  50. package/test/fixtures/custom-port-placeholder.json +0 -10
  51. package/test/fixtures/default-env-var-names.json +0 -7
  52. package/test/fixtures/directories/platformatic.service.json +0 -13
  53. package/test/fixtures/directories/plugins/decorator.js +0 -7
  54. package/test/fixtures/directories/routes/foo/bar.js +0 -11
  55. package/test/fixtures/directories/routes/foo/baz/index.js +0 -7
  56. package/test/fixtures/directories/routes/foo/baz/index2.js +0 -11
  57. package/test/fixtures/directories/routes/oof/auto.hooks.js +0 -5
  58. package/test/fixtures/directories/routes/oof/index.js +0 -7
  59. package/test/fixtures/directories/routes/root.js +0 -7
  60. package/test/fixtures/hello-ts-with-config/global.d.ts +0 -8
  61. package/test/fixtures/hello-ts-with-config/platformatic.service.json +0 -16
  62. package/test/fixtures/hello-ts-with-config/plugin.ts +0 -8
  63. package/test/fixtures/hello-ts-with-config/tsconfig.json +0 -23
  64. package/test/fixtures/hello-world-resolver.js +0 -16
  65. package/test/fixtures/missing-property.config.json +0 -1
  66. package/test/fixtures/nested-directories/modules/catalogue/index.js +0 -11
  67. package/test/fixtures/nested-directories/modules/catalogue/routes/products.js +0 -14
  68. package/test/fixtures/nested-directories/modules/inventory/index.js +0 -33
  69. package/test/fixtures/nested-directories/modules/inventory/routes/product.js +0 -15
  70. package/test/fixtures/nested-directories/package.json +0 -3
  71. package/test/fixtures/nested-directories/platformatic.service.json +0 -23
  72. package/test/fixtures/nested-directories/plugins/decorator.js +0 -3
  73. package/test/fixtures/nested-directories/plugins/handlers.js +0 -17
  74. package/test/fixtures/not-load.js +0 -8
  75. package/test/fixtures/not-load.service.json +0 -13
  76. package/test/fixtures/other-side.js +0 -9
  77. package/test/fixtures/request-id.js +0 -9
  78. package/test/fixtures/root-endpoint-plugin.js +0 -8
  79. package/test/fixtures/throw-resolver.js +0 -16
  80. package/test/fixtures/typescript-autoload/platformatic.service.json +0 -16
  81. package/test/fixtures/typescript-autoload/routes/plugin.ts +0 -5
  82. package/test/fixtures/typescript-autoload/tsconfig.json +0 -22
  83. package/test/fixtures/typescript-compiled/compiled/plugin.js +0 -6
  84. package/test/fixtures/typescript-compiled/platformatic.service.json +0 -18
  85. package/test/fixtures/typescript-plugin/platformatic.service.json +0 -16
  86. package/test/fixtures/typescript-plugin/plugin.ts +0 -5
  87. package/test/fixtures/typescript-plugin/tsconfig.json +0 -22
  88. package/test/fixtures/typescript-plugin-custom-flags/platformatic.service.json +0 -18
  89. package/test/fixtures/typescript-plugin-custom-flags/plugin.ts +0 -5
  90. package/test/fixtures/typescript-plugin-custom-flags/tsconfig.json +0 -22
  91. package/test/fixtures/typescript-plugin-custom-tsconfig/a-config-for-ts.json +0 -22
  92. package/test/fixtures/typescript-plugin-custom-tsconfig/platformatic.service.json +0 -18
  93. package/test/fixtures/typescript-plugin-custom-tsconfig/plugin.ts +0 -5
  94. package/test/fixtures/typescript-plugin-nocompile/platformatic.service.json +0 -16
  95. package/test/fixtures/typescript-plugin-nocompile/plugin.ts +0 -5
  96. package/test/fixtures/typescript-plugin-nocompile/tsconfig.json +0 -22
  97. package/test/fixtures/typescript-plugin-nocompile-enabled/platformatic.service.json +0 -18
  98. package/test/fixtures/typescript-plugin-nocompile-enabled/plugin.ts +0 -5
  99. package/test/fixtures/typescript-plugin-nocompile-enabled/tsconfig.json +0 -22
  100. package/test/fixtures/typescript-plugin-nocompile-string/platformatic.service.json +0 -16
  101. package/test/fixtures/typescript-plugin-nocompile-string/plugin.ts +0 -5
  102. package/test/fixtures/typescript-plugin-nocompile-string/tsconfig.json +0 -22
  103. package/test/fixtures/typescript-plugin-string/platformatic.service.json +0 -16
  104. package/test/fixtures/typescript-plugin-string/plugin.ts +0 -5
  105. package/test/fixtures/typescript-plugin-string/tsconfig.json +0 -22
  106. package/test/fixtures/undici-plugin.js +0 -15
  107. package/test/graphql.test.js +0 -219
  108. package/test/healthcheck.test.js +0 -92
  109. package/test/helper.js +0 -30
  110. package/test/https.test.js +0 -64
  111. package/test/lambda.test.js +0 -103
  112. package/test/load-and-reload-files.test.js +0 -180
  113. package/test/load-plugin.test.js +0 -67
  114. package/test/metrics.test.js +0 -220
  115. package/test/routes.test.js +0 -230
  116. package/test/schema.test.js +0 -12
  117. package/test/tap-parallel-ok +0 -0
  118. package/test/telemetry.test.js +0 -87
  119. package/test/utils.test.js +0 -37
@@ -1,30 +0,0 @@
1
- import { cliPath } from './helper.mjs'
2
- import { test } from 'tap'
3
- import { join } from 'desm'
4
- import { execa } from 'execa'
5
- import { readFile, unlink } from 'fs/promises'
6
-
7
- const GLOBAL_TYPES_TEMPLATE = `
8
- import { FastifyInstance } from 'fastify'
9
- import { PlatformaticApp, PlatformaticServiceConfig } from '@platformatic/service'
10
-
11
- declare module 'fastify' {
12
- interface FastifyInstance {
13
- platformatic: PlatformaticApp<PlatformaticServiceConfig>
14
- }
15
- }
16
- `
17
-
18
- test('generate global.d.ts', async ({ equal }) => {
19
- const fileNameOrThen = join(import.meta.url, '..', '..', 'fixtures', 'hello', 'global.d.ts')
20
- try {
21
- await unlink(fileNameOrThen)
22
- } catch {}
23
-
24
- await execa('node', [cliPath, 'types', '-c', join(import.meta.url, '..', '..', 'fixtures', 'hello', 'platformatic.service.json')])
25
-
26
- const data = await readFile(fileNameOrThen, 'utf-8')
27
- await unlink(fileNameOrThen)
28
-
29
- equal(data, GLOBAL_TYPES_TEMPLATE)
30
- })
@@ -1,67 +0,0 @@
1
- import { Agent, setGlobalDispatcher } from 'undici'
2
- import { on } from 'events'
3
- import { execa } from 'execa'
4
- import split from 'split2'
5
- import { join } from 'desm'
6
- import tap from 'tap'
7
- import os from 'node:os'
8
-
9
- setGlobalDispatcher(new Agent({
10
- keepAliveTimeout: 10,
11
- keepAliveMaxTimeout: 10,
12
- tls: {
13
- rejectUnauthorized: false
14
- }
15
- }))
16
-
17
- // This should not be needed, but a weird combination
18
- // of node-tap, Windows, c8 and ESM makes this necessary.
19
- tap.teardown(() => {
20
- process.exit(0)
21
- })
22
-
23
- export const cliPath = join(import.meta.url, '..', '..', 'service.mjs')
24
-
25
- export async function start (commandOpts, exacaOpts = {}) {
26
- const child = execa('node', [cliPath, 'start', ...commandOpts], exacaOpts)
27
- child.stderr.pipe(process.stdout)
28
-
29
- const output = child.stdout.pipe(split(function (line) {
30
- try {
31
- const obj = JSON.parse(line)
32
- return obj
33
- } catch (err) {
34
- console.log(line)
35
- }
36
- }))
37
- child.ndj = output
38
-
39
- const errorTimeout = setTimeout(() => {
40
- throw new Error('Couldn\'t start server')
41
- }, 30000)
42
-
43
- for await (const messages of on(output, 'data')) {
44
- for (const message of messages) {
45
- const text = message.msg
46
- if (text && text.includes('Server listening at')) {
47
- const url = text.match(/Server listening at (.*)/)[1]
48
- clearTimeout(errorTimeout)
49
- return { child, url, output }
50
- }
51
- }
52
- }
53
- }
54
-
55
- export async function safeKill (child) {
56
- child.kill('SIGINT')
57
- if (os.platform() === 'win32') {
58
- try {
59
- await execa('taskkill', ['/pid', child.pid, '/f', '/t'])
60
- } catch (err) {
61
- if (err.stderr.indexOf('not found') === 0) {
62
- console.error(`Failed to kill process ${child.pid}`)
63
- console.error(err)
64
- }
65
- }
66
- }
67
- }
@@ -1,126 +0,0 @@
1
- import { start, cliPath } from './helper.mjs'
2
- import { test } from 'tap'
3
- import { join } from 'desm'
4
- import { request } from 'undici'
5
- import { execa } from 'execa'
6
-
7
- test('autostart', async ({ equal, same, match, teardown }) => {
8
- const { child, url } = await start(['-c', join(import.meta.url, '..', '..', 'fixtures', 'hello', 'platformatic.service.json')])
9
-
10
- const res = await request(`${url}`)
11
- equal(res.statusCode, 200)
12
- const body = await res.body.json()
13
- match(body, {
14
- hello: 'world'
15
- }, 'response')
16
-
17
- child.kill('SIGINT')
18
- })
19
-
20
- test('start command', async ({ equal, same, match, teardown }) => {
21
- const { child, url } = await start(['-c', join(import.meta.url, '..', '..', 'fixtures', 'hello', 'platformatic.service.json')])
22
-
23
- const res = await request(`${url}`)
24
- equal(res.statusCode, 200)
25
- const body = await res.body.json()
26
- match(body, {
27
- hello: 'world'
28
- }, 'response')
29
-
30
- child.kill('SIGINT')
31
- })
32
-
33
- test('allow custom env properties', async ({ equal, same, match, teardown }) => {
34
- const { child, url } = await start(
35
- [
36
- '-c', join(import.meta.url, '..', 'fixtures', 'custom-port-placeholder.json'),
37
- '--allow-env', 'A_CUSTOM_PORT'
38
- ],
39
- {
40
- env: {
41
- A_CUSTOM_PORT: '11111'
42
- }
43
- }
44
- )
45
- equal(url, 'http://127.0.0.1:11111', 'A_CUSTOM_PORT env variable has been used')
46
- const res = await request(`${url}`)
47
- equal(res.statusCode, 200)
48
- const body = await res.body.json()
49
- match(body, {}, 'response')
50
-
51
- child.kill('SIGINT')
52
- delete process.env.A_CUSTOM_PORT
53
- })
54
-
55
- test('use default env variables names', async ({ equal, match }) => {
56
- const { child, url } = await start(
57
- [
58
- '-c', join(import.meta.url, '..', 'fixtures', 'default-env-var-names.json')
59
- ],
60
- {
61
- env: {
62
- PORT: '11111',
63
- HOSTNAME: '127.0.0.1'
64
- }
65
- }
66
- )
67
-
68
- equal(url, 'http://127.0.0.1:11111', 'default env variable names has been used')
69
- const res = await request(`${url}`)
70
- equal(res.statusCode, 200)
71
- const body = await res.body.json()
72
- match(body, {}, 'response')
73
-
74
- child.kill('SIGINT')
75
- delete process.env.A_CUSTOM_PORT
76
- })
77
-
78
- test('default logger', async ({ equal, same, match, teardown }) => {
79
- const { child, url } = await start(['-c', join(import.meta.url, '..', '..', 'fixtures', 'hello', 'no-server-logger.json')])
80
- match(url, /http:\/\/127.0.0.1:[0-9]+/)
81
- child.kill('SIGINT')
82
- })
83
-
84
- test('plugin options', async ({ equal, same, match, teardown }) => {
85
- const { child, url } = await start(['-c', join(import.meta.url, '..', '..', 'fixtures', 'options', 'platformatic.service.yml')])
86
- const res = await request(`${url}`)
87
- equal(res.statusCode, 200)
88
- const body = await res.body.json()
89
- match(body, {
90
- something: 'else'
91
- }, 'response')
92
-
93
- child.kill('SIGINT')
94
- })
95
-
96
- test('https embedded pem', async ({ equal, same, match, teardown }) => {
97
- const { child, url } = await start(['-c', join(import.meta.url, '..', '..', 'fixtures', 'https', 'embedded-pem.json')])
98
-
99
- match(url, /https:\/\//)
100
- const res = await request(`${url}`)
101
- equal(res.statusCode, 200)
102
- const body = await res.body.json()
103
- match(body, {
104
- hello: 'world'
105
- }, 'response')
106
-
107
- child.kill('SIGINT')
108
- })
109
-
110
- test('https pem path', async ({ equal, same, match, teardown }) => {
111
- const { child, url } = await start(['-c', join(import.meta.url, '..', '..', 'fixtures', 'https', 'pem-path.json')])
112
-
113
- match(url, /https:\/\//)
114
- const res = await request(`${url}`)
115
- equal(res.statusCode, 200)
116
- const body = await res.body.json()
117
- match(body, {
118
- hello: 'world'
119
- }, 'response')
120
-
121
- child.kill('SIGINT')
122
- })
123
-
124
- test('not load', async ({ rejects }) => {
125
- await rejects(execa('node', [cliPath, 'start', '-c', join(import.meta.url, '..', 'fixtures', 'not-load.service.json')]))
126
- })
File without changes
@@ -1,33 +0,0 @@
1
- import { cliPath } from './helper.mjs'
2
- import { test } from 'tap'
3
- import { join } from 'desm'
4
- import { readFile } from 'fs/promises'
5
- import { execa } from 'execa'
6
- import stripAnsi from 'strip-ansi'
7
-
8
- const version = JSON.parse(await readFile(join(import.meta.url, '..', '..', 'package.json'))).version
9
-
10
- test('version', async (t) => {
11
- const { stdout } = await execa('node', [cliPath, '--version'])
12
- t.ok(stdout.includes('v' + version))
13
- })
14
-
15
- test('missing config', async (t) => {
16
- await t.rejects(execa('node', [cliPath, 'start']))
17
- })
18
-
19
- test('print validation errors', async ({ equal, plan }) => {
20
- plan(2)
21
- try {
22
- await execa('node', [cliPath, 'start', '--config', join(import.meta.url, '..', 'fixtures', 'missing-property.config.json')])
23
- } catch (err) {
24
- equal(err.exitCode, 1)
25
- equal(stripAnsi(err.stdout), `
26
- ┌─────────┬──────┬─────────────────────────────────────────────────────────────────────┐
27
- │ (index) │ path │ message │
28
- ├─────────┼──────┼─────────────────────────────────────────────────────────────────────┤
29
- │ 0 │ '/' │ \`must have required property 'server' {"missingProperty":"server"}\` │
30
- └─────────┴──────┴─────────────────────────────────────────────────────────────────────┘
31
- `.trim())
32
- }
33
- })
@@ -1,87 +0,0 @@
1
- 'use strict'
2
-
3
- require('./helper')
4
- const { test } = require('tap')
5
- const { buildServer } = require('..')
6
- const { join } = require('path')
7
- const { request } = require('undici')
8
- const { compile } = require('../lib/compile')
9
- const { rm } = require('fs/promises')
10
-
11
- test('client is loaded', async ({ teardown, equal, same }) => {
12
- const app1 = await buildServer(join(__dirname, '..', 'fixtures', 'hello', 'warn-log.service.json'))
13
-
14
- teardown(async () => {
15
- await app1.close()
16
- })
17
- await app1.start()
18
-
19
- process.env.PLT_CLIENT_URL = app1.url
20
-
21
- const app2 = await buildServer(join(__dirname, '..', 'fixtures', 'hello-client', 'platformatic.service.json'))
22
-
23
- teardown(async () => {
24
- await app2.close()
25
- })
26
- await app2.start()
27
-
28
- const res = await request(`${app2.url}/`)
29
- equal(res.statusCode, 200, 'status code')
30
- const data = await res.body.json()
31
- same(data, { hello: 'world' })
32
- })
33
-
34
- test('client is loaded (ts)', async ({ teardown, equal, pass, same }) => {
35
- const app1 = await buildServer(join(__dirname, '..', 'fixtures', 'hello', 'warn-log.service.json'))
36
-
37
- teardown(async () => {
38
- await app1.close()
39
- })
40
- await app1.start()
41
-
42
- process.env.PLT_CLIENT_URL = app1.url
43
-
44
- const targetDir = join(__dirname, '..', 'fixtures', 'hello-client-ts')
45
-
46
- try {
47
- await rm(join(targetDir, 'dist'), { recursive: true })
48
- } catch {}
49
-
50
- console.time('compile')
51
- await compile(targetDir, { server: { logger: { level: 'warn' } } })
52
- console.timeEnd('compile')
53
-
54
- const app2 = await buildServer(join(targetDir, 'platformatic.service.json'))
55
- teardown(async () => {
56
- await app2.close()
57
- })
58
- await app2.start()
59
-
60
- const res = await request(`${app2.url}/`)
61
- equal(res.statusCode, 200, 'status code')
62
- const data = await res.body.json()
63
- same(data, { hello: 'world' })
64
- })
65
-
66
- test('client is loaded dependencyless', async ({ teardown, equal, same }) => {
67
- const app1 = await buildServer(join(__dirname, '..', 'fixtures', 'hello', 'warn-log.service.json'))
68
-
69
- teardown(async () => {
70
- await app1.close()
71
- })
72
- await app1.start()
73
-
74
- process.env.PLT_CLIENT_URL = app1.url
75
-
76
- const app2 = await buildServer(join(__dirname, '..', 'fixtures', 'hello-client-without-deps', 'platformatic.service.json'))
77
-
78
- teardown(async () => {
79
- await app2.close()
80
- })
81
- await app2.start()
82
-
83
- const res = await request(`${app2.url}/`)
84
- equal(res.statusCode, 200, 'status code')
85
- const data = await res.body.json()
86
- same(data, { hello: 'world' })
87
- })
@@ -1,316 +0,0 @@
1
- 'use strict'
2
-
3
- require('./helper')
4
- const { test } = require('tap')
5
- const { buildServer } = require('..')
6
- const { request } = require('undici')
7
- const { join } = require('path')
8
- const os = require('os')
9
- const { writeFile, rm } = require('fs/promises')
10
-
11
- test('config reloads', async ({ teardown, equal, pass, same }) => {
12
- const file = join(os.tmpdir(), `${process.pid}-1.js`)
13
-
14
- await writeFile(file, `
15
- module.exports = async function (app, options) {
16
- app.get('/', () => options.message)
17
- }`)
18
-
19
- const app = await buildServer({
20
- server: {
21
- hostname: '127.0.0.1',
22
- port: 0
23
- },
24
- plugins: {
25
- paths: [{
26
- path: file,
27
- options: {
28
- message: 'hello'
29
- }
30
- }]
31
- },
32
- watch: false,
33
- metrics: false
34
- })
35
-
36
- teardown(async () => {
37
- await app.close()
38
- })
39
- await app.start()
40
-
41
- {
42
- const res = await request(`${app.url}/`)
43
- equal(res.statusCode, 200, 'add status code')
44
- same(await res.body.text(), 'hello', 'response')
45
- }
46
-
47
- await app.platformatic.configManager.update({
48
- server: {
49
- hostname: '127.0.0.1',
50
- port: 0
51
- },
52
- plugins: {
53
- paths: [{
54
- path: file,
55
- options: {
56
- message: 'ciao mondo'
57
- }
58
- }]
59
- },
60
- metrics: false
61
- })
62
-
63
- await app.restart()
64
-
65
- {
66
- const res = await request(`${app.url}/`)
67
- equal(res.statusCode, 200, 'add status code')
68
- same(await res.body.text(), 'ciao mondo', 'response')
69
- }
70
- })
71
-
72
- test('config reloads from a written file', async ({ teardown, equal, pass, same }) => {
73
- const config = join(os.tmpdir(), `${process.pid}-2.json`)
74
- const file = join(os.tmpdir(), `${process.pid}-2.js`)
75
-
76
- await writeFile(config, JSON.stringify({
77
- server: {
78
- hostname: '127.0.0.1',
79
- port: 0
80
- },
81
- plugins: {
82
- paths: [{
83
- path: file,
84
- options: {
85
- message: 'hello'
86
- }
87
- }]
88
- },
89
- metrics: false
90
- }))
91
-
92
- await writeFile(file, `
93
- module.exports = async function (app, options) {
94
- app.get('/', () => options.message)
95
- }`)
96
-
97
- const app = await buildServer(config)
98
-
99
- teardown(async () => {
100
- await app.close()
101
- })
102
- await app.start()
103
-
104
- {
105
- const res = await request(`${app.url}/`)
106
- equal(res.statusCode, 200, 'add status code')
107
- same(await res.body.text(), 'hello', 'response')
108
- }
109
-
110
- await app.platformatic.configManager.update({
111
- server: {
112
- hostname: '127.0.0.1',
113
- port: 0
114
- },
115
- plugins: {
116
- paths: [{
117
- path: file,
118
- options: {
119
- message: 'ciao mondo'
120
- }
121
- }]
122
- },
123
- metrics: false
124
- })
125
-
126
- await app.restart()
127
-
128
- {
129
- const res = await request(`${app.url}/`)
130
- equal(res.statusCode, 200, 'add status code')
131
- same(await res.body.text(), 'ciao mondo', 'response')
132
- }
133
- })
134
-
135
- test('config reloads from a written file from a route', async ({ teardown, equal, pass, same }) => {
136
- const config = join(os.tmpdir(), `${process.pid}-3.json`)
137
- const file = join(os.tmpdir(), `${process.pid}-3.js`)
138
-
139
- await writeFile(config, JSON.stringify({
140
- server: {
141
- hostname: '127.0.0.1',
142
- logger: { level: 'error' },
143
- port: 0
144
- },
145
- plugins: {
146
- paths: [{
147
- path: file,
148
- options: {
149
- message: 'hello'
150
- }
151
- }]
152
- },
153
- metrics: false
154
- }))
155
-
156
- await writeFile(file, `
157
- module.exports = async function (app, options) {
158
- app.get('/', () => options.message)
159
-
160
- app.post('/restart', async (req, res) => {
161
- await app.platformatic.configManager.update({
162
- server: {
163
- hostname: '127.0.0.1',
164
- port: 0
165
- },
166
- plugins: {
167
- paths: [{
168
- path: '${file.replace(/\\/g, '\\\\')}',
169
- options: {
170
- message: 'ciao mondo'
171
- }
172
- }]
173
- },
174
- metrics: false
175
- })
176
-
177
- await app.restart()
178
-
179
- return true
180
- })
181
- }`)
182
-
183
- const app = await buildServer(config)
184
-
185
- teardown(async () => {
186
- await app.close()
187
- })
188
- await app.start()
189
-
190
- {
191
- const res = await request(`${app.url}/`)
192
- equal(res.statusCode, 200, 'add status code')
193
- same(await res.body.text(), 'hello', 'response')
194
- }
195
-
196
- {
197
- const res = await request(`${app.url}/restart`, {
198
- method: 'POST'
199
- })
200
- equal(res.statusCode, 200, 'add status code')
201
- }
202
-
203
- {
204
- const res = await request(`${app.url}/`)
205
- equal(res.statusCode, 200, 'add status code')
206
- same(await res.body.text(), 'ciao mondo', 'response')
207
- }
208
- })
209
-
210
- test('config is adjusted to handle custom loggers', async (t) => {
211
- const options = {
212
- server: {
213
- hostname: '127.0.0.1',
214
- port: 0,
215
- logger: {
216
- info () {},
217
- error () {},
218
- debug () {},
219
- fatal () {},
220
- warn () {},
221
- trace () {}
222
- }
223
- }
224
- }
225
-
226
- let called = false
227
- Object.defineProperty(options.server.logger, 'child', {
228
- value: function child () {
229
- called = true
230
- return this
231
- },
232
- enumerable: false
233
- })
234
-
235
- await buildServer(options)
236
- t.equal(called, true)
237
- })
238
-
239
- test('config reloads', async ({ teardown, equal, pass, same }) => {
240
- const file = join(os.tmpdir(), `${process.pid}-1.js`)
241
-
242
- await writeFile(file, `
243
- module.exports = async function (app, options) {
244
- app.get('/', () => options.message)
245
- }`)
246
-
247
- const app = await buildServer({
248
- server: {
249
- hostname: '127.0.0.1',
250
- port: 0
251
- },
252
- plugins: {
253
- paths: [{
254
- path: file,
255
- options: {
256
- message: 'hello'
257
- }
258
- }]
259
- },
260
- metrics: false
261
- })
262
-
263
- teardown(async () => {
264
- await app.close()
265
- })
266
- await app.start()
267
-
268
- {
269
- const res = await request(`${app.url}/`)
270
- equal(res.statusCode, 200, 'add status code')
271
- same(await res.body.text(), 'hello', 'response')
272
- }
273
-
274
- await app.platformatic.configManager.update({
275
- server: {
276
- hostname: '127.0.0.1',
277
- port: 0
278
- },
279
- plugins: {
280
- paths: [{
281
- path: file,
282
- options: {
283
- message: 'ciao mondo'
284
- }
285
- }]
286
- },
287
- metrics: false
288
- })
289
-
290
- await app.restart()
291
-
292
- {
293
- const res = await request(`${app.url}/`)
294
- equal(res.statusCode, 200, 'add status code')
295
- same(await res.body.text(), 'ciao mondo', 'response')
296
- }
297
- })
298
-
299
- test('do not watch typescript outDir', async ({ teardown, equal, pass, same }) => {
300
- process.env.PLT_CLIENT_URL = 'http://localhost:3042'
301
- const targetDir = join(__dirname, '..', 'fixtures', 'hello-client-ts')
302
-
303
- try {
304
- await rm(join(targetDir, 'dist'), { recursive: true })
305
- } catch {}
306
-
307
- const app = await buildServer(join(targetDir, 'platformatic.service.json'))
308
- teardown(async () => {
309
- await app.close()
310
- })
311
-
312
- same(app.platformatic.configManager.current.watch, {
313
- enabled: false,
314
- ignore: ['dist/**/*']
315
- })
316
- })