@platformatic/service 0.8.0 → 0.9.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/index.js CHANGED
@@ -132,7 +132,7 @@ async function buildServer (options, app = platformaticService) {
132
132
  if (!options.configManager) {
133
133
  // instantiate a new config manager from current options
134
134
  const cm = new ConfigManager({
135
- source: { ...options },
135
+ source: options,
136
136
  schema
137
137
  })
138
138
  await cm.parseAndValidate()
@@ -164,25 +164,26 @@ async function buildServer (options, app = platformaticService) {
164
164
  }
165
165
 
166
166
  addLoggerToTheConfig(opts)
167
+ const configManager = handler.app.platformatic.configManager
168
+
169
+ if (!opts) {
170
+ opts = configManager.current
171
+ }
167
172
 
168
173
  // Ignore because not tested on Windows
169
174
  // TODO: remove the ignore, we shoduld be testing
170
175
  // this on Windows
171
- /* c8 ignore start */
172
- if (opts) {
173
- const fileWatcher = handler.app.platformatic.fileWatcher
174
- const configManager = handler.app.platformatic.configManager
175
- opts.fileWatcher = fileWatcher
176
- opts.configManager = configManager
177
- opts = createServerConfig(opts)
178
- opts.app = app
179
- }
176
+ const fileWatcher = handler.app.platformatic.fileWatcher
177
+ opts.fileWatcher = fileWatcher
178
+ opts.configManager = configManager
179
+ opts = createServerConfig(opts)
180
+ opts.app = app
181
+
180
182
  debounce = _restart(opts).then(() => {
181
183
  handler.app.log.info('restarted')
182
184
  }).finally(() => {
183
185
  debounce = null
184
186
  })
185
- /* c8 ignore stop */
186
187
  return debounce
187
188
  }
188
189
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@platformatic/service",
3
- "version": "0.8.0",
3
+ "version": "0.9.0",
4
4
  "description": "",
5
5
  "main": "index.js",
6
6
  "author": "Matteo Collina <hello@matteocollina.com>",
@@ -28,15 +28,15 @@
28
28
  "dependencies": {
29
29
  "@fastify/accepts": "^4.0.1",
30
30
  "@fastify/autoload": "^5.5.0",
31
- "@fastify/basic-auth": "^4.0.0",
31
+ "@fastify/basic-auth": "^5.0.0",
32
32
  "@fastify/cors": "^8.0.0",
33
33
  "@fastify/deepmerge": "^1.1.0",
34
34
  "@fastify/restartable": "^1.3.1",
35
35
  "@fastify/static": "^6.5.0",
36
36
  "@fastify/swagger": "^8.0.0",
37
37
  "@fastify/under-pressure": "^8.0.0",
38
- "@platformatic/config": "0.8.0",
39
- "@platformatic/utils": "0.8.0",
38
+ "@platformatic/config": "0.9.0",
39
+ "@platformatic/utils": "0.9.0",
40
40
  "close-with-grace": "^1.1.0",
41
41
  "commist": "^3.1.2",
42
42
  "desm": "^1.2.0",
@@ -0,0 +1,118 @@
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 } = require('fs/promises')
10
+
11
+ test('config reloads', async ({ teardown, equal, pass, same }) => {
12
+ const file = join(os.tmpdir(), `some-plugin-${process.pid}.js`)
13
+
14
+ await writeFile(file, `
15
+ module.exports = async function (app, options) {
16
+ app.get('/', () => options.message)
17
+ }`)
18
+
19
+ const server = await buildServer({
20
+ server: {
21
+ hostname: '127.0.0.1',
22
+ port: 0
23
+ },
24
+ plugin: {
25
+ path: file,
26
+ options: {
27
+ message: 'hello'
28
+ }
29
+ },
30
+ metrics: false
31
+ })
32
+ teardown(server.stop)
33
+ await server.listen()
34
+
35
+ {
36
+ const res = await request(`${server.url}/`)
37
+ equal(res.statusCode, 200, 'add status code')
38
+ same(await res.body.text(), 'hello', 'response')
39
+ }
40
+
41
+ await server.app.platformatic.configManager.update({
42
+ server: {
43
+ hostname: '127.0.0.1',
44
+ port: 0
45
+ },
46
+ plugin: {
47
+ path: file,
48
+ options: {
49
+ message: 'ciao mondo'
50
+ }
51
+ },
52
+ metrics: false
53
+ })
54
+
55
+ await server.restart()
56
+
57
+ {
58
+ const res = await request(`${server.url}/`)
59
+ equal(res.statusCode, 200, 'add status code')
60
+ same(await res.body.text(), 'ciao mondo', 'response')
61
+ }
62
+ })
63
+
64
+ test('config reloads from a written file', async ({ teardown, equal, pass, same }) => {
65
+ const config = join(os.tmpdir(), `some-config-${process.pid}-2.json`)
66
+ const file = join(os.tmpdir(), `some-plugin-${process.pid}-2.js`)
67
+
68
+ await writeFile(config, JSON.stringify({
69
+ server: {
70
+ hostname: '127.0.0.1',
71
+ port: 0
72
+ },
73
+ plugin: {
74
+ path: file,
75
+ options: {
76
+ message: 'hello'
77
+ }
78
+ },
79
+ metrics: false
80
+ }))
81
+
82
+ await writeFile(file, `
83
+ module.exports = async function (app, options) {
84
+ app.get('/', () => options.message)
85
+ }`)
86
+
87
+ const server = await buildServer(config)
88
+ teardown(server.stop)
89
+ await server.listen()
90
+
91
+ {
92
+ const res = await request(`${server.url}/`)
93
+ equal(res.statusCode, 200, 'add status code')
94
+ same(await res.body.text(), 'hello', 'response')
95
+ }
96
+
97
+ await server.app.platformatic.configManager.update({
98
+ server: {
99
+ hostname: '127.0.0.1',
100
+ port: 0
101
+ },
102
+ plugin: {
103
+ path: file,
104
+ options: {
105
+ message: 'ciao mondo'
106
+ }
107
+ },
108
+ metrics: false
109
+ })
110
+
111
+ await server.restart()
112
+
113
+ {
114
+ const res = await request(`${server.url}/`)
115
+ equal(res.statusCode, 200, 'add status code')
116
+ same(await res.body.text(), 'ciao mondo', 'response')
117
+ }
118
+ })