@cedarjs/api-server 2.8.1-next.116 → 2.8.1-rc.3
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/dist/bin.js +17 -25
- package/dist/cjs/bin.js +18 -26
- package/dist/cjs/createServer.js +1 -1
- package/dist/cjs/plugins/api.d.ts +2 -2
- package/dist/cjs/plugins/api.d.ts.map +1 -1
- package/dist/cjs/plugins/api.js +16 -16
- package/dist/cjs/requestHandlers/awsLambdaFastify.d.ts.map +1 -1
- package/dist/cjs/requestHandlers/awsLambdaFastify.js +12 -10
- package/dist/cjs/types.d.ts +4 -4
- package/dist/cjs/types.d.ts.map +1 -1
- package/dist/createServer.js +2 -2
- package/dist/plugins/api.d.ts +2 -2
- package/dist/plugins/api.d.ts.map +1 -1
- package/dist/plugins/api.js +15 -15
- package/dist/requestHandlers/awsLambdaFastify.d.ts.map +1 -1
- package/dist/requestHandlers/awsLambdaFastify.js +2 -10
- package/dist/types.d.ts +4 -4
- package/dist/types.d.ts.map +1 -1
- package/package.json +14 -13
package/dist/bin.js
CHANGED
|
@@ -219,26 +219,18 @@ var init_utils = __esm({
|
|
|
219
219
|
});
|
|
220
220
|
|
|
221
221
|
// src/requestHandlers/awsLambdaFastify.ts
|
|
222
|
-
import
|
|
222
|
+
import qs from "qs";
|
|
223
223
|
var lambdaEventForFastifyRequest, fastifyResponseForLambdaResult, fastifyResponseForLambdaError, requestHandler;
|
|
224
224
|
var init_awsLambdaFastify = __esm({
|
|
225
225
|
"src/requestHandlers/awsLambdaFastify.ts"() {
|
|
226
226
|
"use strict";
|
|
227
227
|
init_utils();
|
|
228
228
|
lambdaEventForFastifyRequest = (request) => {
|
|
229
|
-
const qsParams = parse(
|
|
230
|
-
request.url.split(/\?(.+)/)[1],
|
|
231
|
-
{
|
|
232
|
-
nestingSyntax: "index",
|
|
233
|
-
arrayRepeat: true,
|
|
234
|
-
arrayRepeatSyntax: "bracket"
|
|
235
|
-
}
|
|
236
|
-
);
|
|
237
229
|
return {
|
|
238
230
|
httpMethod: request.method,
|
|
239
231
|
headers: request.headers,
|
|
240
232
|
path: request.urlData("path"),
|
|
241
|
-
queryStringParameters:
|
|
233
|
+
queryStringParameters: qs.parse(request.url.split(/\?(.+)/)[1]),
|
|
242
234
|
requestContext: {
|
|
243
235
|
requestId: request.id,
|
|
244
236
|
identity: {
|
|
@@ -419,12 +411,12 @@ import fastifyUrlData from "@fastify/url-data";
|
|
|
419
411
|
import fastifyRawBody from "fastify-raw-body";
|
|
420
412
|
import { getAsyncStoreInstance as getAsyncStoreInstance2 } from "@cedarjs/context/dist/store";
|
|
421
413
|
import { coerceRootPath as coerceRootPath2 } from "@cedarjs/fastify-web/dist/helpers.js";
|
|
422
|
-
async function
|
|
423
|
-
const
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
414
|
+
async function redwoodFastifyAPI(fastify2, opts) {
|
|
415
|
+
const redwoodOptions = opts.redwood ?? {};
|
|
416
|
+
redwoodOptions.apiRootPath ??= "/";
|
|
417
|
+
redwoodOptions.apiRootPath = coerceRootPath2(redwoodOptions.apiRootPath);
|
|
418
|
+
redwoodOptions.fastGlobOptions ??= {};
|
|
419
|
+
redwoodOptions.loadUserConfig ??= false;
|
|
428
420
|
fastify2.register(fastifyUrlData);
|
|
429
421
|
await fastify2.register(fastifyRawBody);
|
|
430
422
|
fastify2.addHook("onRequest", (_req, _reply, done) => {
|
|
@@ -435,23 +427,23 @@ async function cedarFastifyAPI(fastify2, opts) {
|
|
|
435
427
|
{ parseAs: "string" },
|
|
436
428
|
fastify2.defaultTextParser
|
|
437
429
|
);
|
|
438
|
-
if (
|
|
430
|
+
if (redwoodOptions.loadUserConfig) {
|
|
439
431
|
const { configureFastify } = await loadFastifyConfig();
|
|
440
432
|
if (configureFastify) {
|
|
441
433
|
await configureFastify(fastify2, {
|
|
442
434
|
side: "api",
|
|
443
|
-
apiRootPath:
|
|
435
|
+
apiRootPath: redwoodOptions.apiRootPath
|
|
444
436
|
});
|
|
445
437
|
}
|
|
446
438
|
}
|
|
447
|
-
if (
|
|
448
|
-
await
|
|
439
|
+
if (redwoodOptions.configureServer) {
|
|
440
|
+
await redwoodOptions.configureServer(fastify2);
|
|
449
441
|
}
|
|
450
|
-
fastify2.all(`${
|
|
451
|
-
fastify2.all(`${
|
|
442
|
+
fastify2.all(`${redwoodOptions.apiRootPath}:routeName`, lambdaRequestHandler);
|
|
443
|
+
fastify2.all(`${redwoodOptions.apiRootPath}:routeName/*`, lambdaRequestHandler);
|
|
452
444
|
await loadFunctionsFromDist({
|
|
453
|
-
fastGlobOptions:
|
|
454
|
-
discoverFunctionsGlob:
|
|
445
|
+
fastGlobOptions: redwoodOptions.fastGlobOptions,
|
|
446
|
+
discoverFunctionsGlob: redwoodOptions.discoverFunctionsGlob
|
|
455
447
|
});
|
|
456
448
|
}
|
|
457
449
|
var init_api = __esm({
|
|
@@ -604,7 +596,7 @@ async function createServer(options = {}) {
|
|
|
604
596
|
server.addHook("onRequest", (_req, _reply, done) => {
|
|
605
597
|
getAsyncStoreInstance4().run(/* @__PURE__ */ new Map(), done);
|
|
606
598
|
});
|
|
607
|
-
await server.register(
|
|
599
|
+
await server.register(redwoodFastifyAPI, {
|
|
608
600
|
redwood: {
|
|
609
601
|
apiRootPath,
|
|
610
602
|
fastGlobOptions: {
|
package/dist/cjs/bin.js
CHANGED
|
@@ -241,26 +241,18 @@ var init_utils = __esm({
|
|
|
241
241
|
});
|
|
242
242
|
|
|
243
243
|
// src/requestHandlers/awsLambdaFastify.ts
|
|
244
|
-
var
|
|
244
|
+
var import_qs, lambdaEventForFastifyRequest, fastifyResponseForLambdaResult, fastifyResponseForLambdaError, requestHandler;
|
|
245
245
|
var init_awsLambdaFastify = __esm({
|
|
246
246
|
"src/requestHandlers/awsLambdaFastify.ts"() {
|
|
247
247
|
"use strict";
|
|
248
|
-
|
|
248
|
+
import_qs = __toESM(require("qs"), 1);
|
|
249
249
|
init_utils();
|
|
250
250
|
lambdaEventForFastifyRequest = (request) => {
|
|
251
|
-
const qsParams = (0, import_picoquery.parse)(
|
|
252
|
-
request.url.split(/\?(.+)/)[1],
|
|
253
|
-
{
|
|
254
|
-
nestingSyntax: "index",
|
|
255
|
-
arrayRepeat: true,
|
|
256
|
-
arrayRepeatSyntax: "bracket"
|
|
257
|
-
}
|
|
258
|
-
);
|
|
259
251
|
return {
|
|
260
252
|
httpMethod: request.method,
|
|
261
253
|
headers: request.headers,
|
|
262
254
|
path: request.urlData("path"),
|
|
263
|
-
queryStringParameters:
|
|
255
|
+
queryStringParameters: import_qs.default.parse(request.url.split(/\?(.+)/)[1]),
|
|
264
256
|
requestContext: {
|
|
265
257
|
requestId: request.id,
|
|
266
258
|
identity: {
|
|
@@ -437,12 +429,12 @@ var init_lambdaLoader = __esm({
|
|
|
437
429
|
});
|
|
438
430
|
|
|
439
431
|
// src/plugins/api.ts
|
|
440
|
-
async function
|
|
441
|
-
const
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
432
|
+
async function redwoodFastifyAPI(fastify2, opts) {
|
|
433
|
+
const redwoodOptions = opts.redwood ?? {};
|
|
434
|
+
redwoodOptions.apiRootPath ??= "/";
|
|
435
|
+
redwoodOptions.apiRootPath = (0, import_helpers2.coerceRootPath)(redwoodOptions.apiRootPath);
|
|
436
|
+
redwoodOptions.fastGlobOptions ??= {};
|
|
437
|
+
redwoodOptions.loadUserConfig ??= false;
|
|
446
438
|
fastify2.register(import_url_data.default);
|
|
447
439
|
await fastify2.register(import_fastify_raw_body.default);
|
|
448
440
|
fastify2.addHook("onRequest", (_req, _reply, done) => {
|
|
@@ -453,23 +445,23 @@ async function cedarFastifyAPI(fastify2, opts) {
|
|
|
453
445
|
{ parseAs: "string" },
|
|
454
446
|
fastify2.defaultTextParser
|
|
455
447
|
);
|
|
456
|
-
if (
|
|
448
|
+
if (redwoodOptions.loadUserConfig) {
|
|
457
449
|
const { configureFastify } = await loadFastifyConfig();
|
|
458
450
|
if (configureFastify) {
|
|
459
451
|
await configureFastify(fastify2, {
|
|
460
452
|
side: "api",
|
|
461
|
-
apiRootPath:
|
|
453
|
+
apiRootPath: redwoodOptions.apiRootPath
|
|
462
454
|
});
|
|
463
455
|
}
|
|
464
456
|
}
|
|
465
|
-
if (
|
|
466
|
-
await
|
|
457
|
+
if (redwoodOptions.configureServer) {
|
|
458
|
+
await redwoodOptions.configureServer(fastify2);
|
|
467
459
|
}
|
|
468
|
-
fastify2.all(`${
|
|
469
|
-
fastify2.all(`${
|
|
460
|
+
fastify2.all(`${redwoodOptions.apiRootPath}:routeName`, lambdaRequestHandler);
|
|
461
|
+
fastify2.all(`${redwoodOptions.apiRootPath}:routeName/*`, lambdaRequestHandler);
|
|
470
462
|
await loadFunctionsFromDist({
|
|
471
|
-
fastGlobOptions:
|
|
472
|
-
discoverFunctionsGlob:
|
|
463
|
+
fastGlobOptions: redwoodOptions.fastGlobOptions,
|
|
464
|
+
discoverFunctionsGlob: redwoodOptions.discoverFunctionsGlob
|
|
473
465
|
});
|
|
474
466
|
}
|
|
475
467
|
var import_url_data, import_fastify_raw_body, import_store2, import_helpers2;
|
|
@@ -620,7 +612,7 @@ async function createServer(options = {}) {
|
|
|
620
612
|
server.addHook("onRequest", (_req, _reply, done) => {
|
|
621
613
|
(0, import_store4.getAsyncStoreInstance)().run(/* @__PURE__ */ new Map(), done);
|
|
622
614
|
});
|
|
623
|
-
await server.register(
|
|
615
|
+
await server.register(redwoodFastifyAPI, {
|
|
624
616
|
redwood: {
|
|
625
617
|
apiRootPath,
|
|
626
618
|
fastGlobOptions: {
|
package/dist/cjs/createServer.js
CHANGED
|
@@ -93,7 +93,7 @@ async function createServer(options = {}) {
|
|
|
93
93
|
server.addHook("onRequest", (_req, _reply, done) => {
|
|
94
94
|
(0, import_store.getAsyncStoreInstance)().run(/* @__PURE__ */ new Map(), done);
|
|
95
95
|
});
|
|
96
|
-
await server.register(import_api.
|
|
96
|
+
await server.register(import_api.redwoodFastifyAPI, {
|
|
97
97
|
redwood: {
|
|
98
98
|
apiRootPath,
|
|
99
99
|
fastGlobOptions: {
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import type { Options as FastGlobOptions } from 'fast-glob';
|
|
2
2
|
import type { FastifyInstance } from 'fastify';
|
|
3
3
|
import type { Server } from '../createServerHelpers.js';
|
|
4
|
-
export interface
|
|
4
|
+
export interface RedwoodFastifyAPIOptions {
|
|
5
5
|
redwood: {
|
|
6
6
|
apiRootPath?: string;
|
|
7
7
|
fastGlobOptions?: FastGlobOptions;
|
|
@@ -10,5 +10,5 @@ export interface CedarFastifyAPIOptions {
|
|
|
10
10
|
configureServer?: (server: Server) => void | Promise<void>;
|
|
11
11
|
};
|
|
12
12
|
}
|
|
13
|
-
export declare function
|
|
13
|
+
export declare function redwoodFastifyAPI(fastify: FastifyInstance, opts: RedwoodFastifyAPIOptions): Promise<void>;
|
|
14
14
|
//# sourceMappingURL=api.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"api.d.ts","sourceRoot":"","sources":["../../../src/plugins/api.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,OAAO,IAAI,eAAe,EAAE,MAAM,WAAW,CAAA;AAC3D,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,SAAS,CAAA;AAO9C,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,2BAA2B,CAAA;AAKvD,MAAM,WAAW,
|
|
1
|
+
{"version":3,"file":"api.d.ts","sourceRoot":"","sources":["../../../src/plugins/api.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,OAAO,IAAI,eAAe,EAAE,MAAM,WAAW,CAAA;AAC3D,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,SAAS,CAAA;AAO9C,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,2BAA2B,CAAA;AAKvD,MAAM,WAAW,wBAAwB;IACvC,OAAO,EAAE;QACP,WAAW,CAAC,EAAE,MAAM,CAAA;QACpB,eAAe,CAAC,EAAE,eAAe,CAAA;QACjC,qBAAqB,CAAC,EAAE,MAAM,GAAG,MAAM,EAAE,CAAA;QACzC,cAAc,CAAC,EAAE,OAAO,CAAA;QACxB,eAAe,CAAC,EAAE,CAAC,MAAM,EAAE,MAAM,KAAK,IAAI,GAAG,OAAO,CAAC,IAAI,CAAC,CAAA;KAC3D,CAAA;CACF;AAED,wBAAsB,iBAAiB,CACrC,OAAO,EAAE,eAAe,EACxB,IAAI,EAAE,wBAAwB,iBA4C/B"}
|
package/dist/cjs/plugins/api.js
CHANGED
|
@@ -28,7 +28,7 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
|
|
|
28
28
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
29
29
|
var api_exports = {};
|
|
30
30
|
__export(api_exports, {
|
|
31
|
-
|
|
31
|
+
redwoodFastifyAPI: () => redwoodFastifyAPI
|
|
32
32
|
});
|
|
33
33
|
module.exports = __toCommonJS(api_exports);
|
|
34
34
|
var import_url_data = __toESM(require("@fastify/url-data"), 1);
|
|
@@ -37,12 +37,12 @@ var import_store = require("@cedarjs/context/dist/store");
|
|
|
37
37
|
var import_helpers = require("@cedarjs/fastify-web/dist/helpers.js");
|
|
38
38
|
var import_fastify = require("../fastify.js");
|
|
39
39
|
var import_lambdaLoader = require("./lambdaLoader.js");
|
|
40
|
-
async function
|
|
41
|
-
const
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
40
|
+
async function redwoodFastifyAPI(fastify, opts) {
|
|
41
|
+
const redwoodOptions = opts.redwood ?? {};
|
|
42
|
+
redwoodOptions.apiRootPath ??= "/";
|
|
43
|
+
redwoodOptions.apiRootPath = (0, import_helpers.coerceRootPath)(redwoodOptions.apiRootPath);
|
|
44
|
+
redwoodOptions.fastGlobOptions ??= {};
|
|
45
|
+
redwoodOptions.loadUserConfig ??= false;
|
|
46
46
|
fastify.register(import_url_data.default);
|
|
47
47
|
await fastify.register(import_fastify_raw_body.default);
|
|
48
48
|
fastify.addHook("onRequest", (_req, _reply, done) => {
|
|
@@ -53,26 +53,26 @@ async function cedarFastifyAPI(fastify, opts) {
|
|
|
53
53
|
{ parseAs: "string" },
|
|
54
54
|
fastify.defaultTextParser
|
|
55
55
|
);
|
|
56
|
-
if (
|
|
56
|
+
if (redwoodOptions.loadUserConfig) {
|
|
57
57
|
const { configureFastify } = await (0, import_fastify.loadFastifyConfig)();
|
|
58
58
|
if (configureFastify) {
|
|
59
59
|
await configureFastify(fastify, {
|
|
60
60
|
side: "api",
|
|
61
|
-
apiRootPath:
|
|
61
|
+
apiRootPath: redwoodOptions.apiRootPath
|
|
62
62
|
});
|
|
63
63
|
}
|
|
64
64
|
}
|
|
65
|
-
if (
|
|
66
|
-
await
|
|
65
|
+
if (redwoodOptions.configureServer) {
|
|
66
|
+
await redwoodOptions.configureServer(fastify);
|
|
67
67
|
}
|
|
68
|
-
fastify.all(`${
|
|
69
|
-
fastify.all(`${
|
|
68
|
+
fastify.all(`${redwoodOptions.apiRootPath}:routeName`, import_lambdaLoader.lambdaRequestHandler);
|
|
69
|
+
fastify.all(`${redwoodOptions.apiRootPath}:routeName/*`, import_lambdaLoader.lambdaRequestHandler);
|
|
70
70
|
await (0, import_lambdaLoader.loadFunctionsFromDist)({
|
|
71
|
-
fastGlobOptions:
|
|
72
|
-
discoverFunctionsGlob:
|
|
71
|
+
fastGlobOptions: redwoodOptions.fastGlobOptions,
|
|
72
|
+
discoverFunctionsGlob: redwoodOptions.discoverFunctionsGlob
|
|
73
73
|
});
|
|
74
74
|
}
|
|
75
75
|
// Annotate the CommonJS export names for ESM import in node:
|
|
76
76
|
0 && (module.exports = {
|
|
77
|
-
|
|
77
|
+
redwoodFastifyAPI
|
|
78
78
|
});
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"awsLambdaFastify.d.ts","sourceRoot":"","sources":["../../../src/requestHandlers/awsLambdaFastify.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAEV,oBAAoB,EACpB,OAAO,
|
|
1
|
+
{"version":3,"file":"awsLambdaFastify.d.ts","sourceRoot":"","sources":["../../../src/requestHandlers/awsLambdaFastify.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAEV,oBAAoB,EACpB,OAAO,EACR,MAAM,YAAY,CAAA;AACnB,OAAO,KAAK,EAAE,cAAc,EAAE,YAAY,EAAE,MAAM,SAAS,CAAA;AAK3D,eAAO,MAAM,4BAA4B,GACvC,SAAS,cAAc,KACtB,oBAcF,CAAA;AAoCD,eAAO,MAAM,cAAc,GACzB,KAAK,cAAc,EACnB,OAAO,YAAY,EACnB,SAAS,OAAO,kBAmCjB,CAAA"}
|
|
@@ -1,7 +1,9 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
var __create = Object.create;
|
|
2
3
|
var __defProp = Object.defineProperty;
|
|
3
4
|
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
5
|
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
5
7
|
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
8
|
var __export = (target, all) => {
|
|
7
9
|
for (var name in all)
|
|
@@ -15,6 +17,14 @@ var __copyProps = (to, from, except, desc) => {
|
|
|
15
17
|
}
|
|
16
18
|
return to;
|
|
17
19
|
};
|
|
20
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
21
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
22
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
23
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
24
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
25
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
26
|
+
mod
|
|
27
|
+
));
|
|
18
28
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
29
|
var awsLambdaFastify_exports = {};
|
|
20
30
|
__export(awsLambdaFastify_exports, {
|
|
@@ -22,22 +32,14 @@ __export(awsLambdaFastify_exports, {
|
|
|
22
32
|
requestHandler: () => requestHandler
|
|
23
33
|
});
|
|
24
34
|
module.exports = __toCommonJS(awsLambdaFastify_exports);
|
|
25
|
-
var
|
|
35
|
+
var import_qs = __toESM(require("qs"), 1);
|
|
26
36
|
var import_utils = require("./utils.js");
|
|
27
37
|
const lambdaEventForFastifyRequest = (request) => {
|
|
28
|
-
const qsParams = (0, import_picoquery.parse)(
|
|
29
|
-
request.url.split(/\?(.+)/)[1],
|
|
30
|
-
{
|
|
31
|
-
nestingSyntax: "index",
|
|
32
|
-
arrayRepeat: true,
|
|
33
|
-
arrayRepeatSyntax: "bracket"
|
|
34
|
-
}
|
|
35
|
-
);
|
|
36
38
|
return {
|
|
37
39
|
httpMethod: request.method,
|
|
38
40
|
headers: request.headers,
|
|
39
41
|
path: request.urlData("path"),
|
|
40
|
-
queryStringParameters:
|
|
42
|
+
queryStringParameters: import_qs.default.parse(request.url.split(/\?(.+)/)[1]),
|
|
41
43
|
requestContext: {
|
|
42
44
|
requestId: request.id,
|
|
43
45
|
identity: {
|
package/dist/cjs/types.d.ts
CHANGED
|
@@ -1,19 +1,19 @@
|
|
|
1
1
|
import type { FastifyInstance } from 'fastify';
|
|
2
|
-
import type {
|
|
2
|
+
import type { RedwoodFastifyAPIOptions } from './plugins/api.js';
|
|
3
3
|
export type FastifySideConfigFnOptions = {
|
|
4
4
|
side: 'api' | 'web';
|
|
5
5
|
};
|
|
6
|
-
export type FastifySideConfigFn = (fastify: FastifyInstance, options?: FastifySideConfigFnOptions & Pick<
|
|
6
|
+
export type FastifySideConfigFn = (fastify: FastifyInstance, options?: FastifySideConfigFnOptions & Pick<RedwoodFastifyAPIOptions['redwood'], 'apiRootPath'>) => Promise<FastifyInstance> | void;
|
|
7
7
|
export type APIParsedOptions = {
|
|
8
8
|
port?: number;
|
|
9
9
|
host?: string;
|
|
10
10
|
loadEnvFiles?: boolean;
|
|
11
|
-
} & Omit<
|
|
11
|
+
} & Omit<RedwoodFastifyAPIOptions['redwood'], 'fastGlobOptions'>;
|
|
12
12
|
export type BothParsedOptions = {
|
|
13
13
|
webPort?: number;
|
|
14
14
|
webHost?: string;
|
|
15
15
|
apiPort?: number;
|
|
16
16
|
apiHost?: string;
|
|
17
17
|
apiRootPath?: string;
|
|
18
|
-
} & Omit<
|
|
18
|
+
} & Omit<RedwoodFastifyAPIOptions['redwood'], 'fastGlobOptions'>;
|
|
19
19
|
//# sourceMappingURL=types.d.ts.map
|
package/dist/cjs/types.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,SAAS,CAAA;AAE9C,OAAO,KAAK,EAAE,
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,SAAS,CAAA;AAE9C,OAAO,KAAK,EAAE,wBAAwB,EAAE,MAAM,kBAAkB,CAAA;AAGhE,MAAM,MAAM,0BAA0B,GAAG;IACvC,IAAI,EAAE,KAAK,GAAG,KAAK,CAAA;CACpB,CAAA;AAED,MAAM,MAAM,mBAAmB,GAAG,CAChC,OAAO,EAAE,eAAe,EACxB,OAAO,CAAC,EAAE,0BAA0B,GAClC,IAAI,CAAC,wBAAwB,CAAC,SAAS,CAAC,EAAE,aAAa,CAAC,KACvD,OAAO,CAAC,eAAe,CAAC,GAAG,IAAI,CAAA;AAEpC,MAAM,MAAM,gBAAgB,GAAG;IAC7B,IAAI,CAAC,EAAE,MAAM,CAAA;IACb,IAAI,CAAC,EAAE,MAAM,CAAA;IACb,YAAY,CAAC,EAAE,OAAO,CAAA;CACvB,GAAG,IAAI,CAAC,wBAAwB,CAAC,SAAS,CAAC,EAAE,iBAAiB,CAAC,CAAA;AAEhE,MAAM,MAAM,iBAAiB,GAAG;IAC9B,OAAO,CAAC,EAAE,MAAM,CAAA;IAChB,OAAO,CAAC,EAAE,MAAM,CAAA;IAChB,OAAO,CAAC,EAAE,MAAM,CAAA;IAChB,OAAO,CAAC,EAAE,MAAM,CAAA;IAChB,WAAW,CAAC,EAAE,MAAM,CAAA;CACrB,GAAG,IAAI,CAAC,wBAAwB,CAAC,SAAS,CAAC,EAAE,iBAAiB,CAAC,CAAA"}
|
package/dist/createServer.js
CHANGED
|
@@ -7,7 +7,7 @@ import fastify from "fastify";
|
|
|
7
7
|
import { getAsyncStoreInstance } from "@cedarjs/context/dist/store";
|
|
8
8
|
import { getConfig, getPaths } from "@cedarjs/project-config";
|
|
9
9
|
import { resolveOptions } from "./createServerHelpers.js";
|
|
10
|
-
import {
|
|
10
|
+
import { redwoodFastifyAPI } from "./plugins/api.js";
|
|
11
11
|
if (!process.env.REDWOOD_ENV_FILES_LOADED) {
|
|
12
12
|
config({
|
|
13
13
|
path: path.join(getPaths().base, ".env"),
|
|
@@ -60,7 +60,7 @@ async function createServer(options = {}) {
|
|
|
60
60
|
server.addHook("onRequest", (_req, _reply, done) => {
|
|
61
61
|
getAsyncStoreInstance().run(/* @__PURE__ */ new Map(), done);
|
|
62
62
|
});
|
|
63
|
-
await server.register(
|
|
63
|
+
await server.register(redwoodFastifyAPI, {
|
|
64
64
|
redwood: {
|
|
65
65
|
apiRootPath,
|
|
66
66
|
fastGlobOptions: {
|
package/dist/plugins/api.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import type { Options as FastGlobOptions } from 'fast-glob';
|
|
2
2
|
import type { FastifyInstance } from 'fastify';
|
|
3
3
|
import type { Server } from '../createServerHelpers.js';
|
|
4
|
-
export interface
|
|
4
|
+
export interface RedwoodFastifyAPIOptions {
|
|
5
5
|
redwood: {
|
|
6
6
|
apiRootPath?: string;
|
|
7
7
|
fastGlobOptions?: FastGlobOptions;
|
|
@@ -10,5 +10,5 @@ export interface CedarFastifyAPIOptions {
|
|
|
10
10
|
configureServer?: (server: Server) => void | Promise<void>;
|
|
11
11
|
};
|
|
12
12
|
}
|
|
13
|
-
export declare function
|
|
13
|
+
export declare function redwoodFastifyAPI(fastify: FastifyInstance, opts: RedwoodFastifyAPIOptions): Promise<void>;
|
|
14
14
|
//# sourceMappingURL=api.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"api.d.ts","sourceRoot":"","sources":["../../src/plugins/api.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,OAAO,IAAI,eAAe,EAAE,MAAM,WAAW,CAAA;AAC3D,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,SAAS,CAAA;AAO9C,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,2BAA2B,CAAA;AAKvD,MAAM,WAAW,
|
|
1
|
+
{"version":3,"file":"api.d.ts","sourceRoot":"","sources":["../../src/plugins/api.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,OAAO,IAAI,eAAe,EAAE,MAAM,WAAW,CAAA;AAC3D,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,SAAS,CAAA;AAO9C,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,2BAA2B,CAAA;AAKvD,MAAM,WAAW,wBAAwB;IACvC,OAAO,EAAE;QACP,WAAW,CAAC,EAAE,MAAM,CAAA;QACpB,eAAe,CAAC,EAAE,eAAe,CAAA;QACjC,qBAAqB,CAAC,EAAE,MAAM,GAAG,MAAM,EAAE,CAAA;QACzC,cAAc,CAAC,EAAE,OAAO,CAAA;QACxB,eAAe,CAAC,EAAE,CAAC,MAAM,EAAE,MAAM,KAAK,IAAI,GAAG,OAAO,CAAC,IAAI,CAAC,CAAA;KAC3D,CAAA;CACF;AAED,wBAAsB,iBAAiB,CACrC,OAAO,EAAE,eAAe,EACxB,IAAI,EAAE,wBAAwB,iBA4C/B"}
|
package/dist/plugins/api.js
CHANGED
|
@@ -4,12 +4,12 @@ import { getAsyncStoreInstance } from "@cedarjs/context/dist/store";
|
|
|
4
4
|
import { coerceRootPath } from "@cedarjs/fastify-web/dist/helpers.js";
|
|
5
5
|
import { loadFastifyConfig } from "../fastify.js";
|
|
6
6
|
import { lambdaRequestHandler, loadFunctionsFromDist } from "./lambdaLoader.js";
|
|
7
|
-
async function
|
|
8
|
-
const
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
7
|
+
async function redwoodFastifyAPI(fastify, opts) {
|
|
8
|
+
const redwoodOptions = opts.redwood ?? {};
|
|
9
|
+
redwoodOptions.apiRootPath ??= "/";
|
|
10
|
+
redwoodOptions.apiRootPath = coerceRootPath(redwoodOptions.apiRootPath);
|
|
11
|
+
redwoodOptions.fastGlobOptions ??= {};
|
|
12
|
+
redwoodOptions.loadUserConfig ??= false;
|
|
13
13
|
fastify.register(fastifyUrlData);
|
|
14
14
|
await fastify.register(fastifyRawBody);
|
|
15
15
|
fastify.addHook("onRequest", (_req, _reply, done) => {
|
|
@@ -20,25 +20,25 @@ async function cedarFastifyAPI(fastify, opts) {
|
|
|
20
20
|
{ parseAs: "string" },
|
|
21
21
|
fastify.defaultTextParser
|
|
22
22
|
);
|
|
23
|
-
if (
|
|
23
|
+
if (redwoodOptions.loadUserConfig) {
|
|
24
24
|
const { configureFastify } = await loadFastifyConfig();
|
|
25
25
|
if (configureFastify) {
|
|
26
26
|
await configureFastify(fastify, {
|
|
27
27
|
side: "api",
|
|
28
|
-
apiRootPath:
|
|
28
|
+
apiRootPath: redwoodOptions.apiRootPath
|
|
29
29
|
});
|
|
30
30
|
}
|
|
31
31
|
}
|
|
32
|
-
if (
|
|
33
|
-
await
|
|
32
|
+
if (redwoodOptions.configureServer) {
|
|
33
|
+
await redwoodOptions.configureServer(fastify);
|
|
34
34
|
}
|
|
35
|
-
fastify.all(`${
|
|
36
|
-
fastify.all(`${
|
|
35
|
+
fastify.all(`${redwoodOptions.apiRootPath}:routeName`, lambdaRequestHandler);
|
|
36
|
+
fastify.all(`${redwoodOptions.apiRootPath}:routeName/*`, lambdaRequestHandler);
|
|
37
37
|
await loadFunctionsFromDist({
|
|
38
|
-
fastGlobOptions:
|
|
39
|
-
discoverFunctionsGlob:
|
|
38
|
+
fastGlobOptions: redwoodOptions.fastGlobOptions,
|
|
39
|
+
discoverFunctionsGlob: redwoodOptions.discoverFunctionsGlob
|
|
40
40
|
});
|
|
41
41
|
}
|
|
42
42
|
export {
|
|
43
|
-
|
|
43
|
+
redwoodFastifyAPI
|
|
44
44
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"awsLambdaFastify.d.ts","sourceRoot":"","sources":["../../src/requestHandlers/awsLambdaFastify.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAEV,oBAAoB,EACpB,OAAO,
|
|
1
|
+
{"version":3,"file":"awsLambdaFastify.d.ts","sourceRoot":"","sources":["../../src/requestHandlers/awsLambdaFastify.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAEV,oBAAoB,EACpB,OAAO,EACR,MAAM,YAAY,CAAA;AACnB,OAAO,KAAK,EAAE,cAAc,EAAE,YAAY,EAAE,MAAM,SAAS,CAAA;AAK3D,eAAO,MAAM,4BAA4B,GACvC,SAAS,cAAc,KACtB,oBAcF,CAAA;AAoCD,eAAO,MAAM,cAAc,GACzB,KAAK,cAAc,EACnB,OAAO,YAAY,EACnB,SAAS,OAAO,kBAmCjB,CAAA"}
|
|
@@ -1,19 +1,11 @@
|
|
|
1
|
-
import
|
|
1
|
+
import qs from "qs";
|
|
2
2
|
import { mergeMultiValueHeaders, parseBody } from "./utils.js";
|
|
3
3
|
const lambdaEventForFastifyRequest = (request) => {
|
|
4
|
-
const qsParams = parse(
|
|
5
|
-
request.url.split(/\?(.+)/)[1],
|
|
6
|
-
{
|
|
7
|
-
nestingSyntax: "index",
|
|
8
|
-
arrayRepeat: true,
|
|
9
|
-
arrayRepeatSyntax: "bracket"
|
|
10
|
-
}
|
|
11
|
-
);
|
|
12
4
|
return {
|
|
13
5
|
httpMethod: request.method,
|
|
14
6
|
headers: request.headers,
|
|
15
7
|
path: request.urlData("path"),
|
|
16
|
-
queryStringParameters:
|
|
8
|
+
queryStringParameters: qs.parse(request.url.split(/\?(.+)/)[1]),
|
|
17
9
|
requestContext: {
|
|
18
10
|
requestId: request.id,
|
|
19
11
|
identity: {
|
package/dist/types.d.ts
CHANGED
|
@@ -1,19 +1,19 @@
|
|
|
1
1
|
import type { FastifyInstance } from 'fastify';
|
|
2
|
-
import type {
|
|
2
|
+
import type { RedwoodFastifyAPIOptions } from './plugins/api.js';
|
|
3
3
|
export type FastifySideConfigFnOptions = {
|
|
4
4
|
side: 'api' | 'web';
|
|
5
5
|
};
|
|
6
|
-
export type FastifySideConfigFn = (fastify: FastifyInstance, options?: FastifySideConfigFnOptions & Pick<
|
|
6
|
+
export type FastifySideConfigFn = (fastify: FastifyInstance, options?: FastifySideConfigFnOptions & Pick<RedwoodFastifyAPIOptions['redwood'], 'apiRootPath'>) => Promise<FastifyInstance> | void;
|
|
7
7
|
export type APIParsedOptions = {
|
|
8
8
|
port?: number;
|
|
9
9
|
host?: string;
|
|
10
10
|
loadEnvFiles?: boolean;
|
|
11
|
-
} & Omit<
|
|
11
|
+
} & Omit<RedwoodFastifyAPIOptions['redwood'], 'fastGlobOptions'>;
|
|
12
12
|
export type BothParsedOptions = {
|
|
13
13
|
webPort?: number;
|
|
14
14
|
webHost?: string;
|
|
15
15
|
apiPort?: number;
|
|
16
16
|
apiHost?: string;
|
|
17
17
|
apiRootPath?: string;
|
|
18
|
-
} & Omit<
|
|
18
|
+
} & Omit<RedwoodFastifyAPIOptions['redwood'], 'fastGlobOptions'>;
|
|
19
19
|
//# sourceMappingURL=types.d.ts.map
|
package/dist/types.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,SAAS,CAAA;AAE9C,OAAO,KAAK,EAAE,
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,SAAS,CAAA;AAE9C,OAAO,KAAK,EAAE,wBAAwB,EAAE,MAAM,kBAAkB,CAAA;AAGhE,MAAM,MAAM,0BAA0B,GAAG;IACvC,IAAI,EAAE,KAAK,GAAG,KAAK,CAAA;CACpB,CAAA;AAED,MAAM,MAAM,mBAAmB,GAAG,CAChC,OAAO,EAAE,eAAe,EACxB,OAAO,CAAC,EAAE,0BAA0B,GAClC,IAAI,CAAC,wBAAwB,CAAC,SAAS,CAAC,EAAE,aAAa,CAAC,KACvD,OAAO,CAAC,eAAe,CAAC,GAAG,IAAI,CAAA;AAEpC,MAAM,MAAM,gBAAgB,GAAG;IAC7B,IAAI,CAAC,EAAE,MAAM,CAAA;IACb,IAAI,CAAC,EAAE,MAAM,CAAA;IACb,YAAY,CAAC,EAAE,OAAO,CAAA;CACvB,GAAG,IAAI,CAAC,wBAAwB,CAAC,SAAS,CAAC,EAAE,iBAAiB,CAAC,CAAA;AAEhE,MAAM,MAAM,iBAAiB,GAAG;IAC9B,OAAO,CAAC,EAAE,MAAM,CAAA;IAChB,OAAO,CAAC,EAAE,MAAM,CAAA;IAChB,OAAO,CAAC,EAAE,MAAM,CAAA;IAChB,OAAO,CAAC,EAAE,MAAM,CAAA;IAChB,WAAW,CAAC,EAAE,MAAM,CAAA;CACrB,GAAG,IAAI,CAAC,wBAAwB,CAAC,SAAS,CAAC,EAAE,iBAAiB,CAAC,CAAA"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@cedarjs/api-server",
|
|
3
|
-
"version": "2.8.1-
|
|
3
|
+
"version": "2.8.1-rc.3",
|
|
4
4
|
"description": "CedarJS's HTTP server for Serverless Functions",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
@@ -111,11 +111,11 @@
|
|
|
111
111
|
"test:watch": "vitest watch"
|
|
112
112
|
},
|
|
113
113
|
"dependencies": {
|
|
114
|
-
"@cedarjs/context": "2.8.1-
|
|
115
|
-
"@cedarjs/fastify-web": "2.8.1-
|
|
116
|
-
"@cedarjs/internal": "2.8.1-
|
|
117
|
-
"@cedarjs/project-config": "2.8.1-
|
|
118
|
-
"@cedarjs/web-server": "2.8.1-
|
|
114
|
+
"@cedarjs/context": "2.8.1-rc.3",
|
|
115
|
+
"@cedarjs/fastify-web": "2.8.1-rc.3",
|
|
116
|
+
"@cedarjs/internal": "2.8.1-rc.3",
|
|
117
|
+
"@cedarjs/project-config": "2.8.1-rc.3",
|
|
118
|
+
"@cedarjs/web-server": "2.8.1-rc.3",
|
|
119
119
|
"@fastify/multipart": "9.4.0",
|
|
120
120
|
"@fastify/url-data": "6.0.3",
|
|
121
121
|
"ansis": "4.2.0",
|
|
@@ -123,29 +123,30 @@
|
|
|
123
123
|
"dotenv-defaults": "5.0.2",
|
|
124
124
|
"fast-glob": "3.3.3",
|
|
125
125
|
"fast-json-parse": "1.0.3",
|
|
126
|
-
"fastify": "5.
|
|
126
|
+
"fastify": "5.7.4",
|
|
127
127
|
"fastify-raw-body": "5.0.0",
|
|
128
|
-
"picoquery": "2.5.0",
|
|
129
128
|
"pretty-bytes": "5.6.0",
|
|
130
129
|
"pretty-ms": "7.0.1",
|
|
130
|
+
"qs": "6.15.0",
|
|
131
131
|
"split2": "4.2.0",
|
|
132
132
|
"yargs": "17.7.2"
|
|
133
133
|
},
|
|
134
134
|
"devDependencies": {
|
|
135
|
-
"@cedarjs/framework-tools": "2.8.1-
|
|
135
|
+
"@cedarjs/framework-tools": "2.8.1-rc.3",
|
|
136
136
|
"@types/aws-lambda": "8.10.161",
|
|
137
137
|
"@types/dotenv-defaults": "^5.0.0",
|
|
138
|
+
"@types/qs": "6.14.0",
|
|
138
139
|
"@types/split2": "4.2.3",
|
|
139
140
|
"@types/yargs": "17.0.35",
|
|
140
|
-
"graphql-yoga": "5.18.
|
|
141
|
-
"memfs": "4.56.
|
|
141
|
+
"graphql-yoga": "5.18.0",
|
|
142
|
+
"memfs": "4.56.10",
|
|
142
143
|
"pino-abstract-transport": "1.2.0",
|
|
143
144
|
"tsx": "4.21.0",
|
|
144
145
|
"typescript": "5.9.3",
|
|
145
146
|
"vitest": "3.2.4"
|
|
146
147
|
},
|
|
147
148
|
"peerDependencies": {
|
|
148
|
-
"@cedarjs/graphql-server": "2.8.
|
|
149
|
+
"@cedarjs/graphql-server": "2.8.1-rc.3"
|
|
149
150
|
},
|
|
150
151
|
"peerDependenciesMeta": {
|
|
151
152
|
"@cedarjs/graphql-server": {
|
|
@@ -155,5 +156,5 @@
|
|
|
155
156
|
"publishConfig": {
|
|
156
157
|
"access": "public"
|
|
157
158
|
},
|
|
158
|
-
"gitHead": "
|
|
159
|
+
"gitHead": "f778a5b70b97c0b129246e918083f42c63a6dc0a"
|
|
159
160
|
}
|