@platformatic/service 0.46.1 → 0.47.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/.c8rc +6 -0
- package/config.d.ts +0 -1
- package/index.d.ts +25 -0
- package/index.js +1 -0
- package/index.test-d.ts +24 -1
- package/lib/schema.js +0 -3
- package/package.json +9 -7
- 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 -352
- 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/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
|
-
})
|
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"compilerOptions": {
|
|
3
|
-
"module": "commonjs",
|
|
4
|
-
"esModuleInterop": true,
|
|
5
|
-
"target": "es2020",
|
|
6
|
-
"moduleResolution": "node",
|
|
7
|
-
"sourceMap": true,
|
|
8
|
-
"pretty": true,
|
|
9
|
-
"noEmitOnError": true,
|
|
10
|
-
"outDir": "dist"
|
|
11
|
-
},
|
|
12
|
-
"watchOptions": {
|
|
13
|
-
"watchFile": "fixedPollingInterval",
|
|
14
|
-
"watchDirectory": "fixedPollingInterval",
|
|
15
|
-
"fallbackPolling": "dynamicPriority",
|
|
16
|
-
"synchronousWatchDirectory": true,
|
|
17
|
-
"excludeDirectories": [
|
|
18
|
-
"**/node_modules",
|
|
19
|
-
"dist"
|
|
20
|
-
]
|
|
21
|
-
}
|
|
22
|
-
}
|
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
'use strict'
|
|
2
|
-
|
|
3
|
-
module.exports = async function (fastify, opts) {
|
|
4
|
-
fastify.get('/bar', async function (request, reply) {
|
|
5
|
-
return { hello: 'from bar' }
|
|
6
|
-
})
|
|
7
|
-
|
|
8
|
-
fastify.get('/with-decorator', async function (request, reply) {
|
|
9
|
-
return { hello: fastify.foo }
|
|
10
|
-
})
|
|
11
|
-
}
|
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
'use strict'
|
|
2
|
-
|
|
3
|
-
/*
|
|
4
|
-
* Used for providing an alternative `index.js` naming convention
|
|
5
|
-
* when specified from the autoload `indexPattern` property.
|
|
6
|
-
*/
|
|
7
|
-
module.exports = async function (fastify, opts) {
|
|
8
|
-
fastify.get('/index2', async function (request, reply) {
|
|
9
|
-
return { hello: 'from baz with index2.js' }
|
|
10
|
-
})
|
|
11
|
-
}
|
|
@@ -1,23 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"compilerOptions": {
|
|
3
|
-
"module": "commonjs",
|
|
4
|
-
"esModuleInterop": true,
|
|
5
|
-
"target": "es2020",
|
|
6
|
-
"moduleResolution": "node",
|
|
7
|
-
"sourceMap": false,
|
|
8
|
-
"incremental": true,
|
|
9
|
-
"pretty": true,
|
|
10
|
-
"noEmitOnError": true,
|
|
11
|
-
"outDir": "dist"
|
|
12
|
-
},
|
|
13
|
-
"watchOptions": {
|
|
14
|
-
"watchFile": "fixedPollingInterval",
|
|
15
|
-
"watchDirectory": "fixedPollingInterval",
|
|
16
|
-
"fallbackPolling": "dynamicPriority",
|
|
17
|
-
"synchronousWatchDirectory": true,
|
|
18
|
-
"excludeDirectories": [
|
|
19
|
-
"**/node_modules",
|
|
20
|
-
"dist"
|
|
21
|
-
]
|
|
22
|
-
}
|
|
23
|
-
}
|
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
'use strict'
|
|
2
|
-
|
|
3
|
-
module.exports = async function (app) {
|
|
4
|
-
app.graphql.extendSchema(`
|
|
5
|
-
extend type Query {
|
|
6
|
-
hello: String
|
|
7
|
-
}
|
|
8
|
-
`)
|
|
9
|
-
app.graphql.defineResolvers({
|
|
10
|
-
Query: {
|
|
11
|
-
hello: async function (root, args, context) {
|
|
12
|
-
return 'world'
|
|
13
|
-
}
|
|
14
|
-
}
|
|
15
|
-
})
|
|
16
|
-
}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{}
|
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
export default async function (fastify, opts) {
|
|
2
|
-
fastify.get('/products', async (request, reply) => {
|
|
3
|
-
const data = [{ sku: 42, name: 'foo' }, { sku: 43, name: 'bar' }]
|
|
4
|
-
// Currently slow and inefficient, but ok for the demo
|
|
5
|
-
for (const product of data) {
|
|
6
|
-
product.inStore = await fastify.inventory.howManyInStore(product.sku)
|
|
7
|
-
}
|
|
8
|
-
return data
|
|
9
|
-
})
|
|
10
|
-
|
|
11
|
-
fastify.get('/error', async (request, reply) => {
|
|
12
|
-
throw new Error('This is an error')
|
|
13
|
-
})
|
|
14
|
-
}
|
|
@@ -1,33 +0,0 @@
|
|
|
1
|
-
import fp from 'fastify-plugin'
|
|
2
|
-
import autoload from '@fastify/autoload'
|
|
3
|
-
import { join } from 'desm'
|
|
4
|
-
|
|
5
|
-
class Inventory {
|
|
6
|
-
async howManyInStore (sku) {
|
|
7
|
-
if (sku === 42) {
|
|
8
|
-
return 2
|
|
9
|
-
} else {
|
|
10
|
-
return 0
|
|
11
|
-
}
|
|
12
|
-
}
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
async function inventory (fastify, opts) {
|
|
16
|
-
// This will be published to the root fastify instance
|
|
17
|
-
// it could also be extracted to a separate plugin
|
|
18
|
-
fastify.decorate('inventory', new Inventory())
|
|
19
|
-
|
|
20
|
-
// These routes would be created in their own child instances
|
|
21
|
-
fastify.register(autoload, {
|
|
22
|
-
dir: join(import.meta.url, 'routes'),
|
|
23
|
-
options: {
|
|
24
|
-
prefix: opts.prefix
|
|
25
|
-
}
|
|
26
|
-
})
|
|
27
|
-
|
|
28
|
-
fastify.get('/foo', async function (req) {
|
|
29
|
-
return req.foo
|
|
30
|
-
})
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
export default fp(inventory)
|
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
export default async function (fastify, opts) {
|
|
2
|
-
fastify.get('/product/:sku', {
|
|
3
|
-
schema: {
|
|
4
|
-
params: {
|
|
5
|
-
type: 'object',
|
|
6
|
-
properties: {
|
|
7
|
-
sku: { type: 'number' }
|
|
8
|
-
}
|
|
9
|
-
}
|
|
10
|
-
}
|
|
11
|
-
}, async (request, reply) => {
|
|
12
|
-
const sku = request.params.sku
|
|
13
|
-
return { sku, inStore: await fastify.inventory.howManyInStore(sku) }
|
|
14
|
-
})
|
|
15
|
-
}
|
|
@@ -1,23 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"$schema": "https://platformatic.dev/schemas/v0.19.7/service",
|
|
3
|
-
"server": {
|
|
4
|
-
"hostname": "{PLT_SERVER_HOSTNAME}",
|
|
5
|
-
"port": "{PORT}",
|
|
6
|
-
"logger": {
|
|
7
|
-
"level": "{PLT_SERVER_LOGGER_LEVEL}"
|
|
8
|
-
}
|
|
9
|
-
},
|
|
10
|
-
"service": {
|
|
11
|
-
"openapi": true
|
|
12
|
-
},
|
|
13
|
-
"plugins": {
|
|
14
|
-
"paths": [{
|
|
15
|
-
"path": "plugins",
|
|
16
|
-
"encapsulate": false
|
|
17
|
-
}, {
|
|
18
|
-
"path": "modules",
|
|
19
|
-
"encapsulate": false,
|
|
20
|
-
"maxDepth": 1
|
|
21
|
-
}]
|
|
22
|
-
}
|
|
23
|
-
}
|
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
export default async function (app, opts) {
|
|
2
|
-
app.setErrorHandler(async (err, request, reply) => {
|
|
3
|
-
if (err.validation) {
|
|
4
|
-
reply.code(403)
|
|
5
|
-
return err.message
|
|
6
|
-
}
|
|
7
|
-
request.log.error({ err })
|
|
8
|
-
reply.code(err.statusCode || 500)
|
|
9
|
-
|
|
10
|
-
return "I'm sorry, there was an error processing your request."
|
|
11
|
-
})
|
|
12
|
-
|
|
13
|
-
app.setNotFoundHandler(async (request, reply) => {
|
|
14
|
-
reply.code(404)
|
|
15
|
-
return "I'm sorry, I couldn't find what you were looking for."
|
|
16
|
-
})
|
|
17
|
-
}
|