@platformatic/service 0.45.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.
- package/index.js +2 -2
- package/package.json +6 -6
- package/fixtures/hello/no-server-logger.json +0 -13
- package/fixtures/hello/platformatic.service.json +0 -18
- package/fixtures/hello/plugin.js +0 -7
- package/fixtures/hello/warn-log.service.json +0 -18
- package/fixtures/hello-client/hello/hello.cjs +0 -21
- package/fixtures/hello-client/hello/hello.d.ts +0 -34
- package/fixtures/hello-client/hello/hello.openapi.json +0 -22
- package/fixtures/hello-client/hello/package.json +0 -5
- package/fixtures/hello-client/platformatic.service.json +0 -19
- package/fixtures/hello-client/plugin.js +0 -8
- package/fixtures/hello-client-ts/hello/hello.cjs +0 -21
- package/fixtures/hello-client-ts/hello/hello.d.ts +0 -34
- package/fixtures/hello-client-ts/hello/hello.openapi.json +0 -22
- package/fixtures/hello-client-ts/hello/package.json +0 -5
- package/fixtures/hello-client-ts/platformatic.service.json +0 -21
- package/fixtures/hello-client-ts/plugin.ts +0 -8
- package/fixtures/hello-client-ts/tsconfig.json +0 -23
- package/fixtures/hello-client-ts-without-deps/hello.d.ts +0 -34
- package/fixtures/hello-client-ts-without-deps/hello.openapi.json +0 -22
- package/fixtures/hello-client-ts-without-deps/platformatic.service.json +0 -23
- package/fixtures/hello-client-ts-without-deps/plugin.ts +0 -8
- package/fixtures/hello-client-ts-without-deps/tsconfig.json +0 -22
- package/fixtures/hello-client-without-deps/hello.d.ts +0 -34
- package/fixtures/hello-client-without-deps/hello.openapi.json +0 -22
- package/fixtures/hello-client-without-deps/platformatic.service.json +0 -21
- package/fixtures/hello-client-without-deps/plugin.js +0 -8
- package/fixtures/https/embedded-pem.json +0 -20
- package/fixtures/https/https.crt +0 -25
- package/fixtures/https/https.key +0 -27
- package/fixtures/https/pem-path.json +0 -20
- package/fixtures/https/plugin.js +0 -7
- package/fixtures/options/platformatic.service.yml +0 -9
- package/fixtures/options/plugin.js +0 -7
- package/test/autoload.test.js +0 -486
- package/test/cli/compile-1.test.mjs +0 -532
- package/test/cli/compile-2.test.mjs +0 -310
- package/test/cli/gen-schema.test.mjs +0 -44
- package/test/cli/gen-types.test.mjs +0 -30
- package/test/cli/helper.mjs +0 -67
- package/test/cli/start.test.mjs +0 -126
- package/test/cli/tap-parallel-not-ok +0 -0
- package/test/cli/validations.test.mjs +0 -33
- package/test/clients.test.js +0 -87
- package/test/config.test.js +0 -316
- package/test/cors.test.js +0 -291
- package/test/fixtures/bad-typescript-plugin/platformatic.service.json +0 -16
- package/test/fixtures/bad-typescript-plugin/plugin.ts +0 -5
- package/test/fixtures/bad-typescript-plugin/tsconfig.json +0 -22
- package/test/fixtures/custom-port-placeholder.json +0 -10
- package/test/fixtures/default-env-var-names.json +0 -7
- package/test/fixtures/directories/platformatic.service.json +0 -13
- package/test/fixtures/directories/plugins/decorator.js +0 -7
- package/test/fixtures/directories/routes/foo/bar.js +0 -11
- package/test/fixtures/directories/routes/foo/baz/index.js +0 -7
- package/test/fixtures/directories/routes/foo/baz/index2.js +0 -11
- package/test/fixtures/directories/routes/oof/auto.hooks.js +0 -5
- package/test/fixtures/directories/routes/oof/index.js +0 -7
- package/test/fixtures/directories/routes/root.js +0 -7
- package/test/fixtures/hello-ts-with-config/global.d.ts +0 -8
- package/test/fixtures/hello-ts-with-config/platformatic.service.json +0 -16
- package/test/fixtures/hello-ts-with-config/plugin.ts +0 -8
- package/test/fixtures/hello-ts-with-config/tsconfig.json +0 -23
- package/test/fixtures/hello-world-resolver.js +0 -16
- package/test/fixtures/missing-property.config.json +0 -1
- package/test/fixtures/nested-directories/modules/catalogue/index.js +0 -11
- package/test/fixtures/nested-directories/modules/catalogue/routes/products.js +0 -14
- package/test/fixtures/nested-directories/modules/inventory/index.js +0 -33
- package/test/fixtures/nested-directories/modules/inventory/routes/product.js +0 -15
- package/test/fixtures/nested-directories/package.json +0 -3
- package/test/fixtures/nested-directories/platformatic.service.json +0 -23
- package/test/fixtures/nested-directories/plugins/decorator.js +0 -3
- package/test/fixtures/nested-directories/plugins/handlers.js +0 -17
- package/test/fixtures/not-load.js +0 -8
- package/test/fixtures/not-load.service.json +0 -13
- package/test/fixtures/other-side.js +0 -9
- package/test/fixtures/request-id.js +0 -9
- package/test/fixtures/root-endpoint-plugin.js +0 -8
- package/test/fixtures/throw-resolver.js +0 -16
- package/test/fixtures/typescript-autoload/platformatic.service.json +0 -16
- package/test/fixtures/typescript-autoload/routes/plugin.ts +0 -5
- package/test/fixtures/typescript-autoload/tsconfig.json +0 -22
- package/test/fixtures/typescript-compiled/compiled/plugin.js +0 -6
- package/test/fixtures/typescript-compiled/platformatic.service.json +0 -18
- package/test/fixtures/typescript-plugin/platformatic.service.json +0 -16
- package/test/fixtures/typescript-plugin/plugin.ts +0 -5
- package/test/fixtures/typescript-plugin/tsconfig.json +0 -22
- package/test/fixtures/typescript-plugin-custom-flags/platformatic.service.json +0 -18
- package/test/fixtures/typescript-plugin-custom-flags/plugin.ts +0 -5
- package/test/fixtures/typescript-plugin-custom-flags/tsconfig.json +0 -22
- package/test/fixtures/typescript-plugin-custom-tsconfig/a-config-for-ts.json +0 -22
- package/test/fixtures/typescript-plugin-custom-tsconfig/platformatic.service.json +0 -18
- package/test/fixtures/typescript-plugin-custom-tsconfig/plugin.ts +0 -5
- package/test/fixtures/typescript-plugin-nocompile/platformatic.service.json +0 -16
- package/test/fixtures/typescript-plugin-nocompile/plugin.ts +0 -5
- package/test/fixtures/typescript-plugin-nocompile/tsconfig.json +0 -22
- package/test/fixtures/typescript-plugin-nocompile-enabled/platformatic.service.json +0 -18
- package/test/fixtures/typescript-plugin-nocompile-enabled/plugin.ts +0 -5
- package/test/fixtures/typescript-plugin-nocompile-enabled/tsconfig.json +0 -22
- package/test/fixtures/typescript-plugin-nocompile-string/platformatic.service.json +0 -16
- package/test/fixtures/typescript-plugin-nocompile-string/plugin.ts +0 -5
- package/test/fixtures/typescript-plugin-nocompile-string/tsconfig.json +0 -22
- package/test/fixtures/typescript-plugin-string/platformatic.service.json +0 -16
- package/test/fixtures/typescript-plugin-string/plugin.ts +0 -5
- package/test/fixtures/typescript-plugin-string/tsconfig.json +0 -22
- package/test/fixtures/undici-plugin.js +0 -15
- package/test/graphql.test.js +0 -219
- package/test/healthcheck.test.js +0 -92
- package/test/helper.js +0 -30
- package/test/https.test.js +0 -64
- package/test/lambda.test.js +0 -103
- package/test/load-and-reload-files.test.js +0 -180
- package/test/load-plugin.test.js +0 -67
- package/test/metrics.test.js +0 -220
- package/test/routes.test.js +0 -230
- package/test/schema.test.js +0 -12
- package/test/tap-parallel-ok +0 -0
- package/test/telemetry.test.js +0 -87
- package/test/utils.test.js +0 -37
package/test/clients.test.js
DELETED
|
@@ -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
|
-
})
|
package/test/config.test.js
DELETED
|
@@ -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
|
-
})
|
package/test/cors.test.js
DELETED
|
@@ -1,291 +0,0 @@
|
|
|
1
|
-
'use strict'
|
|
2
|
-
|
|
3
|
-
require('./helper')
|
|
4
|
-
const { test } = require('tap')
|
|
5
|
-
const { buildServer, platformaticService } = require('..')
|
|
6
|
-
const { request } = require('undici')
|
|
7
|
-
|
|
8
|
-
test('CORS is disabled by default', async ({ teardown, equal, pass, same }) => {
|
|
9
|
-
const app = await buildServer({
|
|
10
|
-
server: {
|
|
11
|
-
hostname: '127.0.0.1',
|
|
12
|
-
port: 0
|
|
13
|
-
},
|
|
14
|
-
metrics: false
|
|
15
|
-
}, async function (app, opts) {
|
|
16
|
-
app.register(platformaticService, opts)
|
|
17
|
-
app.post('/login', (req, reply) => {})
|
|
18
|
-
})
|
|
19
|
-
|
|
20
|
-
// handles login
|
|
21
|
-
teardown(async () => {
|
|
22
|
-
await app.close()
|
|
23
|
-
})
|
|
24
|
-
await app.start()
|
|
25
|
-
|
|
26
|
-
const res = await (request(`${app.url}/login`, {
|
|
27
|
-
method: 'OPTIONS',
|
|
28
|
-
headers: {
|
|
29
|
-
'Access-Control-Request-Method': 'POST',
|
|
30
|
-
Origin: 'https://foo.bar.org'
|
|
31
|
-
}
|
|
32
|
-
}))
|
|
33
|
-
equal(res.statusCode, 404)
|
|
34
|
-
})
|
|
35
|
-
|
|
36
|
-
test('CORS can be enabled', async ({ teardown, equal, pass, same }) => {
|
|
37
|
-
const app = await buildServer({
|
|
38
|
-
server: {
|
|
39
|
-
hostname: '127.0.0.1',
|
|
40
|
-
port: 0,
|
|
41
|
-
cors: {
|
|
42
|
-
origin: true,
|
|
43
|
-
methods: ['GET', 'POST']
|
|
44
|
-
}
|
|
45
|
-
},
|
|
46
|
-
metrics: false
|
|
47
|
-
}, async function (app, opts) {
|
|
48
|
-
app.register(platformaticService, opts)
|
|
49
|
-
app.post('/login', (req, reply) => {})
|
|
50
|
-
})
|
|
51
|
-
|
|
52
|
-
teardown(async () => {
|
|
53
|
-
await app.close()
|
|
54
|
-
})
|
|
55
|
-
await app.start()
|
|
56
|
-
|
|
57
|
-
{
|
|
58
|
-
const res = await (request(`${app.url}/_admin/login`, {
|
|
59
|
-
method: 'OPTIONS',
|
|
60
|
-
headers: {
|
|
61
|
-
'Access-Control-Request-Method': 'POST',
|
|
62
|
-
Origin: 'https://foo.bar.org'
|
|
63
|
-
}
|
|
64
|
-
}))
|
|
65
|
-
equal(res.statusCode, 204)
|
|
66
|
-
equal(res.headers['access-control-allow-origin'], 'https://foo.bar.org')
|
|
67
|
-
equal(res.headers['access-control-allow-methods'], 'GET, POST')
|
|
68
|
-
}
|
|
69
|
-
})
|
|
70
|
-
|
|
71
|
-
test('CORS with a regexp', async ({ teardown, equal, pass, same }) => {
|
|
72
|
-
const app = await buildServer({
|
|
73
|
-
server: {
|
|
74
|
-
hostname: '127.0.0.1',
|
|
75
|
-
port: 0,
|
|
76
|
-
cors: {
|
|
77
|
-
origin: {
|
|
78
|
-
regexp: 'https://[a-z-]*.deploy.space|https://platformatic.cloud'
|
|
79
|
-
},
|
|
80
|
-
methods: ['GET', 'POST']
|
|
81
|
-
}
|
|
82
|
-
},
|
|
83
|
-
metrics: false
|
|
84
|
-
}, async function (app, opts) {
|
|
85
|
-
app.register(platformaticService, opts)
|
|
86
|
-
app.post('/login', (req, reply) => {})
|
|
87
|
-
})
|
|
88
|
-
|
|
89
|
-
teardown(async () => {
|
|
90
|
-
await app.close()
|
|
91
|
-
})
|
|
92
|
-
await app.start()
|
|
93
|
-
|
|
94
|
-
{
|
|
95
|
-
const res = await (request(`${app.url}/_admin/login`, {
|
|
96
|
-
method: 'OPTIONS',
|
|
97
|
-
headers: {
|
|
98
|
-
'Access-Control-Request-Method': 'POST',
|
|
99
|
-
Origin: 'https://platformatic.cloud'
|
|
100
|
-
}
|
|
101
|
-
}))
|
|
102
|
-
equal(res.statusCode, 204)
|
|
103
|
-
equal(res.headers['access-control-allow-origin'], 'https://platformatic.cloud')
|
|
104
|
-
equal(res.headers['access-control-allow-methods'], 'GET, POST')
|
|
105
|
-
}
|
|
106
|
-
|
|
107
|
-
{
|
|
108
|
-
const res = await (request(`${app.url}/_admin/login`, {
|
|
109
|
-
method: 'OPTIONS',
|
|
110
|
-
headers: {
|
|
111
|
-
'Access-Control-Request-Method': 'POST',
|
|
112
|
-
Origin: 'https://foo.deploy.space'
|
|
113
|
-
}
|
|
114
|
-
}))
|
|
115
|
-
equal(res.statusCode, 204)
|
|
116
|
-
equal(res.headers['access-control-allow-origin'], 'https://foo.deploy.space')
|
|
117
|
-
equal(res.headers['access-control-allow-methods'], 'GET, POST')
|
|
118
|
-
}
|
|
119
|
-
|
|
120
|
-
{
|
|
121
|
-
const res = await (request(`${app.url}/_admin/login`, {
|
|
122
|
-
method: 'OPTIONS',
|
|
123
|
-
headers: {
|
|
124
|
-
'Access-Control-Request-Method': 'POST',
|
|
125
|
-
Origin: 'https://foo.space'
|
|
126
|
-
}
|
|
127
|
-
}))
|
|
128
|
-
equal(res.statusCode, 204)
|
|
129
|
-
equal(res.headers['access-control-allow-origin'], undefined)
|
|
130
|
-
equal(res.headers['access-control-allow-methods'], 'GET, POST')
|
|
131
|
-
}
|
|
132
|
-
})
|
|
133
|
-
|
|
134
|
-
test('CORS with an array of strings', async ({ teardown, equal, pass, same }) => {
|
|
135
|
-
const app = await buildServer({
|
|
136
|
-
server: {
|
|
137
|
-
hostname: '127.0.0.1',
|
|
138
|
-
port: 0,
|
|
139
|
-
cors: {
|
|
140
|
-
origin: ['https://foo.deploy.space', 'https://platformatic.cloud'],
|
|
141
|
-
methods: ['GET', 'POST']
|
|
142
|
-
}
|
|
143
|
-
},
|
|
144
|
-
metrics: false
|
|
145
|
-
}, async function (app, opts) {
|
|
146
|
-
app.register(platformaticService, opts)
|
|
147
|
-
app.post('/login', (req, reply) => {})
|
|
148
|
-
})
|
|
149
|
-
|
|
150
|
-
teardown(async () => {
|
|
151
|
-
await app.close()
|
|
152
|
-
})
|
|
153
|
-
await app.start()
|
|
154
|
-
|
|
155
|
-
{
|
|
156
|
-
const res = await (request(`${app.url}/_admin/login`, {
|
|
157
|
-
method: 'OPTIONS',
|
|
158
|
-
headers: {
|
|
159
|
-
'Access-Control-Request-Method': 'POST',
|
|
160
|
-
Origin: 'https://platformatic.cloud'
|
|
161
|
-
}
|
|
162
|
-
}))
|
|
163
|
-
equal(res.statusCode, 204)
|
|
164
|
-
equal(res.headers['access-control-allow-origin'], 'https://platformatic.cloud')
|
|
165
|
-
equal(res.headers['access-control-allow-methods'], 'GET, POST')
|
|
166
|
-
}
|
|
167
|
-
|
|
168
|
-
{
|
|
169
|
-
const res = await (request(`${app.url}/_admin/login`, {
|
|
170
|
-
method: 'OPTIONS',
|
|
171
|
-
headers: {
|
|
172
|
-
'Access-Control-Request-Method': 'POST',
|
|
173
|
-
Origin: 'https://foo.deploy.space'
|
|
174
|
-
}
|
|
175
|
-
}))
|
|
176
|
-
equal(res.statusCode, 204)
|
|
177
|
-
equal(res.headers['access-control-allow-origin'], 'https://foo.deploy.space')
|
|
178
|
-
equal(res.headers['access-control-allow-methods'], 'GET, POST')
|
|
179
|
-
}
|
|
180
|
-
|
|
181
|
-
{
|
|
182
|
-
const res = await (request(`${app.url}/_admin/login`, {
|
|
183
|
-
method: 'OPTIONS',
|
|
184
|
-
headers: {
|
|
185
|
-
'Access-Control-Request-Method': 'POST',
|
|
186
|
-
Origin: 'https://foo.cloud'
|
|
187
|
-
}
|
|
188
|
-
}))
|
|
189
|
-
equal(res.statusCode, 204)
|
|
190
|
-
equal(res.headers['access-control-allow-origin'], undefined)
|
|
191
|
-
equal(res.headers['access-control-allow-methods'], 'GET, POST')
|
|
192
|
-
}
|
|
193
|
-
})
|
|
194
|
-
|
|
195
|
-
test('CORS with an array and a regexp', async ({ teardown, equal, pass, same }) => {
|
|
196
|
-
const app = await buildServer({
|
|
197
|
-
server: {
|
|
198
|
-
hostname: '127.0.0.1',
|
|
199
|
-
port: 0,
|
|
200
|
-
cors: {
|
|
201
|
-
origin: [{
|
|
202
|
-
regexp: 'https://[a-z-]*.deploy.space'
|
|
203
|
-
}, 'https://platformatic.cloud'],
|
|
204
|
-
methods: ['GET', 'POST']
|
|
205
|
-
}
|
|
206
|
-
},
|
|
207
|
-
metrics: false
|
|
208
|
-
}, async function (app, opts) {
|
|
209
|
-
app.register(platformaticService, opts)
|
|
210
|
-
app.post('/login', (req, reply) => {})
|
|
211
|
-
})
|
|
212
|
-
|
|
213
|
-
teardown(async () => {
|
|
214
|
-
await app.close()
|
|
215
|
-
})
|
|
216
|
-
await app.start()
|
|
217
|
-
|
|
218
|
-
{
|
|
219
|
-
const res = await (request(`${app.url}/_admin/login`, {
|
|
220
|
-
method: 'OPTIONS',
|
|
221
|
-
headers: {
|
|
222
|
-
'Access-Control-Request-Method': 'POST',
|
|
223
|
-
Origin: 'https://platformatic.cloud'
|
|
224
|
-
}
|
|
225
|
-
}))
|
|
226
|
-
equal(res.statusCode, 204)
|
|
227
|
-
equal(res.headers['access-control-allow-origin'], 'https://platformatic.cloud')
|
|
228
|
-
equal(res.headers['access-control-allow-methods'], 'GET, POST')
|
|
229
|
-
}
|
|
230
|
-
|
|
231
|
-
{
|
|
232
|
-
const res = await (request(`${app.url}/_admin/login`, {
|
|
233
|
-
method: 'OPTIONS',
|
|
234
|
-
headers: {
|
|
235
|
-
'Access-Control-Request-Method': 'POST',
|
|
236
|
-
Origin: 'https://foo.deploy.space'
|
|
237
|
-
}
|
|
238
|
-
}))
|
|
239
|
-
equal(res.statusCode, 204)
|
|
240
|
-
equal(res.headers['access-control-allow-origin'], 'https://foo.deploy.space')
|
|
241
|
-
equal(res.headers['access-control-allow-methods'], 'GET, POST')
|
|
242
|
-
}
|
|
243
|
-
|
|
244
|
-
{
|
|
245
|
-
const res = await (request(`${app.url}/_admin/login`, {
|
|
246
|
-
method: 'OPTIONS',
|
|
247
|
-
headers: {
|
|
248
|
-
'Access-Control-Request-Method': 'POST',
|
|
249
|
-
Origin: 'https://foo.cloud'
|
|
250
|
-
}
|
|
251
|
-
}))
|
|
252
|
-
equal(res.statusCode, 204)
|
|
253
|
-
equal(res.headers['access-control-allow-origin'], undefined)
|
|
254
|
-
equal(res.headers['access-control-allow-methods'], 'GET, POST')
|
|
255
|
-
}
|
|
256
|
-
})
|
|
257
|
-
|
|
258
|
-
test('CORS with a string', async ({ teardown, equal, pass, same }) => {
|
|
259
|
-
const app = await buildServer({
|
|
260
|
-
server: {
|
|
261
|
-
hostname: '127.0.0.1',
|
|
262
|
-
port: 0,
|
|
263
|
-
cors: {
|
|
264
|
-
origin: 'https://platformatic.cloud',
|
|
265
|
-
methods: ['GET', 'POST']
|
|
266
|
-
}
|
|
267
|
-
},
|
|
268
|
-
metrics: false
|
|
269
|
-
}, async function (app, opts) {
|
|
270
|
-
app.register(platformaticService, opts)
|
|
271
|
-
app.post('/login', (req, reply) => {})
|
|
272
|
-
})
|
|
273
|
-
|
|
274
|
-
teardown(async () => {
|
|
275
|
-
await app.close()
|
|
276
|
-
})
|
|
277
|
-
await app.start()
|
|
278
|
-
|
|
279
|
-
{
|
|
280
|
-
const res = await (request(`${app.url}/_admin/login`, {
|
|
281
|
-
method: 'OPTIONS',
|
|
282
|
-
headers: {
|
|
283
|
-
'Access-Control-Request-Method': 'POST',
|
|
284
|
-
Origin: 'https://foo.cloud'
|
|
285
|
-
}
|
|
286
|
-
}))
|
|
287
|
-
equal(res.statusCode, 204)
|
|
288
|
-
equal(res.headers['access-control-allow-origin'], 'https://platformatic.cloud')
|
|
289
|
-
equal(res.headers['access-control-allow-methods'], 'GET, POST')
|
|
290
|
-
}
|
|
291
|
-
})
|