@platformatic/service 0.9.0 → 0.9.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.
package/index.js CHANGED
@@ -187,6 +187,8 @@ async function buildServer (options, app = platformaticService) {
187
187
  return debounce
188
188
  }
189
189
 
190
+ handler.app.restart = handler.restart
191
+
190
192
  return handler
191
193
  }
192
194
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@platformatic/service",
3
- "version": "0.9.0",
3
+ "version": "0.9.2",
4
4
  "description": "",
5
5
  "main": "index.js",
6
6
  "author": "Matteo Collina <hello@matteocollina.com>",
@@ -35,8 +35,8 @@
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.9.0",
39
- "@platformatic/utils": "0.9.0",
38
+ "@platformatic/config": "0.9.2",
39
+ "@platformatic/utils": "0.9.2",
40
40
  "close-with-grace": "^1.1.0",
41
41
  "commist": "^3.1.2",
42
42
  "desm": "^1.2.0",
@@ -9,7 +9,7 @@ const os = require('os')
9
9
  const { writeFile } = require('fs/promises')
10
10
 
11
11
  test('config reloads', async ({ teardown, equal, pass, same }) => {
12
- const file = join(os.tmpdir(), `some-plugin-${process.pid}.js`)
12
+ const file = join(os.tmpdir(), `${process.pid}-1.js`)
13
13
 
14
14
  await writeFile(file, `
15
15
  module.exports = async function (app, options) {
@@ -62,8 +62,8 @@ test('config reloads', async ({ teardown, equal, pass, same }) => {
62
62
  })
63
63
 
64
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`)
65
+ const config = join(os.tmpdir(), `${process.pid}-2.json`)
66
+ const file = join(os.tmpdir(), `${process.pid}-2.js`)
67
67
 
68
68
  await writeFile(config, JSON.stringify({
69
69
  server: {
@@ -116,3 +116,71 @@ test('config reloads from a written file', async ({ teardown, equal, pass, same
116
116
  same(await res.body.text(), 'ciao mondo', 'response')
117
117
  }
118
118
  })
119
+
120
+ test('config reloads from a written file from a route', async ({ teardown, equal, pass, same }) => {
121
+ const config = join(os.tmpdir(), `${process.pid}-3.json`)
122
+ const file = join(os.tmpdir(), `${process.pid}-3.js`)
123
+
124
+ await writeFile(config, JSON.stringify({
125
+ server: {
126
+ hostname: '127.0.0.1',
127
+ logger: { level: 'error' },
128
+ port: 0
129
+ },
130
+ plugin: {
131
+ path: file,
132
+ options: {
133
+ message: 'hello'
134
+ }
135
+ },
136
+ metrics: false
137
+ }))
138
+
139
+ await writeFile(file, `
140
+ module.exports = async function (app, options) {
141
+ app.get('/', () => options.message)
142
+
143
+ app.post('/restart', async (req, res) => {
144
+ await app.platformatic.configManager.update({
145
+ server: {
146
+ hostname: '127.0.0.1',
147
+ port: 0
148
+ },
149
+ plugin: {
150
+ path: '${file.replace(/\\/g, '\\\\')}',
151
+ options: {
152
+ message: 'ciao mondo'
153
+ }
154
+ },
155
+ metrics: false
156
+ })
157
+
158
+ await app.restart()
159
+
160
+ return true
161
+ })
162
+ }`)
163
+
164
+ const server = await buildServer(config)
165
+ teardown(server.stop)
166
+ await server.listen()
167
+
168
+ {
169
+ const res = await request(`${server.url}/`)
170
+ equal(res.statusCode, 200, 'add status code')
171
+ same(await res.body.text(), 'hello', 'response')
172
+ }
173
+
174
+ {
175
+ const res = await request(`${server.url}/restart`, {
176
+ method: 'POST'
177
+ })
178
+ equal(res.statusCode, 200, 'add status code')
179
+ }
180
+
181
+ {
182
+ const res = await request(`${server.url}/`)
183
+ equal(res.statusCode, 200, 'add status code')
184
+ same(await res.body.text(), 'ciao mondo', 'response')
185
+ }
186
+ })