@cedarjs/api-server 1.0.0-canary.12388 → 1.0.0-canary.12391
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 +39 -16
- package/dist/createServer.d.ts.map +1 -1
- package/dist/createServer.js +2 -0
- package/dist/createServerHelpers.d.ts +5 -0
- package/dist/createServerHelpers.d.ts.map +1 -1
- package/dist/createServerHelpers.js +2 -0
- package/dist/plugins/api.d.ts +1 -0
- package/dist/plugins/api.d.ts.map +1 -1
- package/dist/plugins/api.js +2 -1
- package/dist/plugins/lambdaLoader.d.ts +1 -0
- package/dist/plugins/lambdaLoader.d.ts.map +1 -1
- package/dist/plugins/lambdaLoader.js +27 -9
- package/package.json +9 -9
package/dist/bin.js
CHANGED
|
@@ -71,6 +71,7 @@ function resolveOptions(options = {}, args) {
|
|
|
71
71
|
requestTimeout: defaults.fastifyServerOptions.requestTimeout,
|
|
72
72
|
bodyLimit: defaults.fastifyServerOptions.bodyLimit
|
|
73
73
|
},
|
|
74
|
+
discoverFunctionsGlob: options.discoverFunctionsGlob ?? defaults.discoverFunctionsGlob,
|
|
74
75
|
configureApiServer: options.configureApiServer ?? defaults.configureApiServer,
|
|
75
76
|
apiHost: options.apiHost ?? defaults.apiHost,
|
|
76
77
|
apiPort: options.apiPort ?? defaults.apiPort
|
|
@@ -137,6 +138,7 @@ var init_createServerHelpers = __esm({
|
|
|
137
138
|
bodyLimit: 1024 * 1024 * 100
|
|
138
139
|
// 100MB
|
|
139
140
|
},
|
|
141
|
+
discoverFunctionsGlob: "dist/functions/**/*.{ts,js}",
|
|
140
142
|
configureApiServer: () => {
|
|
141
143
|
},
|
|
142
144
|
parseArgs: true,
|
|
@@ -312,16 +314,7 @@ var init_awsLambdaFastify = __esm({
|
|
|
312
314
|
});
|
|
313
315
|
|
|
314
316
|
// src/plugins/lambdaLoader.ts
|
|
315
|
-
|
|
316
|
-
return import_fast_glob.default.sync("dist/functions/**/*.{ts,js}", {
|
|
317
|
-
cwd,
|
|
318
|
-
deep: 2,
|
|
319
|
-
// We don't support deeply nested api functions, to maximise compatibility with deployment providers
|
|
320
|
-
absolute: true,
|
|
321
|
-
...options
|
|
322
|
-
});
|
|
323
|
-
}
|
|
324
|
-
var import_path2, import_chalk, import_fast_glob, import_lodash, import_project_config3, LAMBDA_FUNCTIONS, setLambdaFunctions, loadFunctionsFromDist, lambdaRequestHandler;
|
|
317
|
+
var import_path2, import_chalk, import_fast_glob, import_lodash, import_project_config3, LAMBDA_FUNCTIONS, setLambdaFunctions, loadFunctionsFromDist, findApiDistFunctions, lambdaRequestHandler;
|
|
325
318
|
var init_lambdaLoader = __esm({
|
|
326
319
|
"src/plugins/lambdaLoader.ts"() {
|
|
327
320
|
"use strict";
|
|
@@ -338,7 +331,18 @@ var init_lambdaLoader = __esm({
|
|
|
338
331
|
const imports = foundFunctions.map(async (fnPath) => {
|
|
339
332
|
const ts = Date.now();
|
|
340
333
|
const routeName = import_path2.default.basename(fnPath).replace(".js", "");
|
|
341
|
-
const
|
|
334
|
+
const fnImport = await import(`file://${fnPath}`);
|
|
335
|
+
const handler3 = (() => {
|
|
336
|
+
if ("handler" in fnImport) {
|
|
337
|
+
return fnImport.handler;
|
|
338
|
+
}
|
|
339
|
+
if ("default" in fnImport) {
|
|
340
|
+
if ("handler" in fnImport.default) {
|
|
341
|
+
return fnImport.default.handler;
|
|
342
|
+
}
|
|
343
|
+
}
|
|
344
|
+
return void 0;
|
|
345
|
+
})();
|
|
342
346
|
LAMBDA_FUNCTIONS[routeName] = handler3;
|
|
343
347
|
if (!handler3) {
|
|
344
348
|
console.warn(
|
|
@@ -359,10 +363,11 @@ var init_lambdaLoader = __esm({
|
|
|
359
363
|
);
|
|
360
364
|
};
|
|
361
365
|
loadFunctionsFromDist = async (options = {}) => {
|
|
362
|
-
const serverFunctions = findApiDistFunctions(
|
|
363
|
-
(0, import_project_config3.getPaths)().api.base,
|
|
364
|
-
options?.fastGlobOptions
|
|
365
|
-
|
|
366
|
+
const serverFunctions = findApiDistFunctions({
|
|
367
|
+
cwd: (0, import_project_config3.getPaths)().api.base,
|
|
368
|
+
options: options?.fastGlobOptions,
|
|
369
|
+
discoverFunctionsGlob: options?.discoverFunctionsGlob
|
|
370
|
+
});
|
|
366
371
|
const i = serverFunctions.findIndex((x) => import_path2.default.basename(x) === "graphql.js");
|
|
367
372
|
if (i >= 0) {
|
|
368
373
|
const graphQLFn = serverFunctions.splice(i, 1)[0];
|
|
@@ -370,6 +375,21 @@ var init_lambdaLoader = __esm({
|
|
|
370
375
|
}
|
|
371
376
|
await setLambdaFunctions(serverFunctions);
|
|
372
377
|
};
|
|
378
|
+
findApiDistFunctions = (params) => {
|
|
379
|
+
const {
|
|
380
|
+
cwd = (0, import_project_config3.getPaths)().api.base,
|
|
381
|
+
options = {},
|
|
382
|
+
discoverFunctionsGlob = "dist/functions/**/*.{ts,js}"
|
|
383
|
+
} = params;
|
|
384
|
+
return import_fast_glob.default.sync(discoverFunctionsGlob, {
|
|
385
|
+
cwd,
|
|
386
|
+
// We don't support deeply nested api functions, to maximise compatibility
|
|
387
|
+
// with deployment providers
|
|
388
|
+
deep: 2,
|
|
389
|
+
absolute: true,
|
|
390
|
+
...options
|
|
391
|
+
});
|
|
392
|
+
};
|
|
373
393
|
lambdaRequestHandler = async (req, reply) => {
|
|
374
394
|
const { routeName } = req.params;
|
|
375
395
|
if (!LAMBDA_FUNCTIONS[routeName]) {
|
|
@@ -424,7 +444,8 @@ async function redwoodFastifyAPI(fastify2, opts) {
|
|
|
424
444
|
fastify2.all(`${redwoodOptions.apiRootPath}:routeName`, lambdaRequestHandler);
|
|
425
445
|
fastify2.all(`${redwoodOptions.apiRootPath}:routeName/*`, lambdaRequestHandler);
|
|
426
446
|
await loadFunctionsFromDist({
|
|
427
|
-
fastGlobOptions: redwoodOptions.fastGlobOptions
|
|
447
|
+
fastGlobOptions: redwoodOptions.fastGlobOptions,
|
|
448
|
+
discoverFunctionsGlob: redwoodOptions.discoverFunctionsGlob
|
|
428
449
|
});
|
|
429
450
|
}
|
|
430
451
|
var import_url_data, import_fastify_raw_body, import_store2, import_helpers2;
|
|
@@ -539,6 +560,7 @@ async function createServer(options = {}) {
|
|
|
539
560
|
const {
|
|
540
561
|
apiRootPath,
|
|
541
562
|
fastifyServerOptions,
|
|
563
|
+
discoverFunctionsGlob,
|
|
542
564
|
configureApiServer,
|
|
543
565
|
apiPort,
|
|
544
566
|
apiHost
|
|
@@ -584,6 +606,7 @@ async function createServer(options = {}) {
|
|
|
584
606
|
fastGlobOptions: {
|
|
585
607
|
ignore: ["**/dist/functions/graphql.js"]
|
|
586
608
|
},
|
|
609
|
+
discoverFunctionsGlob,
|
|
587
610
|
configureServer: configureApiServer
|
|
588
611
|
}
|
|
589
612
|
});
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"createServer.d.ts","sourceRoot":"","sources":["../src/createServer.ts"],"names":[],"mappings":"AAaA,OAAO,KAAK,EACV,mBAAmB,EACnB,MAAM,EAEP,MAAM,uBAAuB,CAAA;AAqB9B;;;;;;;;;;;;;;;;;;;;;;;;;;GA0BG;AACH,wBAAsB,YAAY,CAAC,OAAO,GAAE,mBAAwB,
|
|
1
|
+
{"version":3,"file":"createServer.d.ts","sourceRoot":"","sources":["../src/createServer.ts"],"names":[],"mappings":"AAaA,OAAO,KAAK,EACV,mBAAmB,EACnB,MAAM,EAEP,MAAM,uBAAuB,CAAA;AAqB9B;;;;;;;;;;;;;;;;;;;;;;;;;;GA0BG;AACH,wBAAsB,YAAY,CAAC,OAAO,GAAE,mBAAwB,mBAoHnE"}
|
package/dist/createServer.js
CHANGED
|
@@ -53,6 +53,7 @@ async function createServer(options = {}) {
|
|
|
53
53
|
const {
|
|
54
54
|
apiRootPath,
|
|
55
55
|
fastifyServerOptions,
|
|
56
|
+
discoverFunctionsGlob,
|
|
56
57
|
configureApiServer,
|
|
57
58
|
apiPort,
|
|
58
59
|
apiHost
|
|
@@ -98,6 +99,7 @@ async function createServer(options = {}) {
|
|
|
98
99
|
fastGlobOptions: {
|
|
99
100
|
ignore: ["**/dist/functions/graphql.js"]
|
|
100
101
|
},
|
|
102
|
+
discoverFunctionsGlob,
|
|
101
103
|
configureServer: configureApiServer
|
|
102
104
|
}
|
|
103
105
|
});
|
|
@@ -13,6 +13,11 @@ export interface CreateServerOptions {
|
|
|
13
13
|
* Omitting logger here because we move it up.
|
|
14
14
|
*/
|
|
15
15
|
fastifyServerOptions?: Omit<FastifyServerOptions, 'logger'>;
|
|
16
|
+
/**
|
|
17
|
+
* Override the glob used to discover functions.
|
|
18
|
+
* Defaults to: "dist/functions/**\/*.{ts,js}"
|
|
19
|
+
*/
|
|
20
|
+
discoverFunctionsGlob?: string | string[];
|
|
16
21
|
/** Customise the API server fastify plugin before it is registered */
|
|
17
22
|
configureApiServer?: (server: Server) => void | Promise<void>;
|
|
18
23
|
/** Whether to parse args or not. Defaults to `true` */
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"createServerHelpers.d.ts","sourceRoot":"","sources":["../src/createServerHelpers.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EACV,oBAAoB,EACpB,oBAAoB,EACpB,eAAe,EAChB,MAAM,SAAS,CAAA;AAMhB,MAAM,MAAM,YAAY,GAAG,IAAI,CAAC,oBAAoB,EAAE,MAAM,GAAG,MAAM,CAAC,CAAA;AAEtE,MAAM,WAAW,MAAO,SAAQ,eAAe;IAC7C,KAAK,EAAE,CAAC,OAAO,CAAC,EAAE,YAAY,KAAK,OAAO,CAAC,MAAM,CAAC,CAAA;CACnD;AAED,MAAM,WAAW,mBAAmB;IAClC,iDAAiD;IACjD,WAAW,CAAC,EAAE,MAAM,CAAA;IAGpB,iCAAiC;IACjC,MAAM,CAAC,EACH,oBAAoB,CAAC,QAAQ,CAAC,GAC9B,oBAAoB,CAAC,gBAAgB,CAAC,CAAA;IAE1C;;;OAGG;IACH,oBAAoB,CAAC,EAAE,IAAI,CAAC,oBAAoB,EAAE,QAAQ,CAAC,CAAA;IAE3D,sEAAsE;IACtE,kBAAkB,CAAC,EAAE,CAAC,MAAM,EAAE,MAAM,KAAK,IAAI,GAAG,OAAO,CAAC,IAAI,CAAC,CAAA;IAE7D,uDAAuD;IACvD,SAAS,CAAC,EAAE,OAAO,CAAA;IAEnB,2EAA2E;IAC3E,OAAO,CAAC,EAAE,MAAM,CAAA;IAEhB,yEAAyE;IACzE,OAAO,CAAC,EAAE,MAAM,CAAA;CACjB;AAED,KAAK,0BAA0B,GAAG,QAAQ,CACxC,IAAI,CAAC,mBAAmB,EAAE,sBAAsB,CAAC,GAAG;IAClD,oBAAoB,EAAE,oBAAoB,CAAA;CAC3C,CACF,CAAA;AAID,eAAO,MAAM,6BAA6B,EAAE,MAAM,
|
|
1
|
+
{"version":3,"file":"createServerHelpers.d.ts","sourceRoot":"","sources":["../src/createServerHelpers.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EACV,oBAAoB,EACpB,oBAAoB,EACpB,eAAe,EAChB,MAAM,SAAS,CAAA;AAMhB,MAAM,MAAM,YAAY,GAAG,IAAI,CAAC,oBAAoB,EAAE,MAAM,GAAG,MAAM,CAAC,CAAA;AAEtE,MAAM,WAAW,MAAO,SAAQ,eAAe;IAC7C,KAAK,EAAE,CAAC,OAAO,CAAC,EAAE,YAAY,KAAK,OAAO,CAAC,MAAM,CAAC,CAAA;CACnD;AAED,MAAM,WAAW,mBAAmB;IAClC,iDAAiD;IACjD,WAAW,CAAC,EAAE,MAAM,CAAA;IAGpB,iCAAiC;IACjC,MAAM,CAAC,EACH,oBAAoB,CAAC,QAAQ,CAAC,GAC9B,oBAAoB,CAAC,gBAAgB,CAAC,CAAA;IAE1C;;;OAGG;IACH,oBAAoB,CAAC,EAAE,IAAI,CAAC,oBAAoB,EAAE,QAAQ,CAAC,CAAA;IAE3D;;;OAGG;IACH,qBAAqB,CAAC,EAAE,MAAM,GAAG,MAAM,EAAE,CAAA;IAEzC,sEAAsE;IACtE,kBAAkB,CAAC,EAAE,CAAC,MAAM,EAAE,MAAM,KAAK,IAAI,GAAG,OAAO,CAAC,IAAI,CAAC,CAAA;IAE7D,uDAAuD;IACvD,SAAS,CAAC,EAAE,OAAO,CAAA;IAEnB,2EAA2E;IAC3E,OAAO,CAAC,EAAE,MAAM,CAAA;IAEhB,yEAAyE;IACzE,OAAO,CAAC,EAAE,MAAM,CAAA;CACjB;AAED,KAAK,0BAA0B,GAAG,QAAQ,CACxC,IAAI,CAAC,mBAAmB,EAAE,sBAAsB,CAAC,GAAG;IAClD,oBAAoB,EAAE,oBAAoB,CAAA;CAC3C,CACF,CAAA;AAID,eAAO,MAAM,6BAA6B,EAAE,MAAM,0BAiB9C,CAAA;AAgBJ,wBAAgB,cAAc,CAC5B,OAAO,GAAE,mBAAwB,EACjC,IAAI,CAAC,EAAE,MAAM,EAAE;0BAdS,oBAAoB;GA4F7C"}
|
|
@@ -35,6 +35,7 @@ const getDefaultCreateServerOptions = () => ({
|
|
|
35
35
|
bodyLimit: 1024 * 1024 * 100
|
|
36
36
|
// 100MB
|
|
37
37
|
},
|
|
38
|
+
discoverFunctionsGlob: "dist/functions/**/*.{ts,js}",
|
|
38
39
|
configureApiServer: () => {
|
|
39
40
|
},
|
|
40
41
|
parseArgs: true,
|
|
@@ -54,6 +55,7 @@ function resolveOptions(options = {}, args) {
|
|
|
54
55
|
requestTimeout: defaults.fastifyServerOptions.requestTimeout,
|
|
55
56
|
bodyLimit: defaults.fastifyServerOptions.bodyLimit
|
|
56
57
|
},
|
|
58
|
+
discoverFunctionsGlob: options.discoverFunctionsGlob ?? defaults.discoverFunctionsGlob,
|
|
57
59
|
configureApiServer: options.configureApiServer ?? defaults.configureApiServer,
|
|
58
60
|
apiHost: options.apiHost ?? defaults.apiHost,
|
|
59
61
|
apiPort: options.apiPort ?? defaults.apiPort
|
package/dist/plugins/api.d.ts
CHANGED
|
@@ -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,wBAAwB,CAAA;AAKpD,MAAM,WAAW,wBAAwB;IACvC,OAAO,EAAE;QACP,WAAW,CAAC,EAAE,MAAM,CAAA;QACpB,eAAe,CAAC,EAAE,eAAe,CAAA;QACjC,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,
|
|
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,wBAAwB,CAAA;AAKpD,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
|
@@ -68,7 +68,8 @@ async function redwoodFastifyAPI(fastify, opts) {
|
|
|
68
68
|
fastify.all(`${redwoodOptions.apiRootPath}:routeName`, import_lambdaLoader.lambdaRequestHandler);
|
|
69
69
|
fastify.all(`${redwoodOptions.apiRootPath}:routeName/*`, import_lambdaLoader.lambdaRequestHandler);
|
|
70
70
|
await (0, import_lambdaLoader.loadFunctionsFromDist)({
|
|
71
|
-
fastGlobOptions: redwoodOptions.fastGlobOptions
|
|
71
|
+
fastGlobOptions: redwoodOptions.fastGlobOptions,
|
|
72
|
+
discoverFunctionsGlob: redwoodOptions.discoverFunctionsGlob
|
|
72
73
|
});
|
|
73
74
|
}
|
|
74
75
|
// Annotate the CommonJS export names for ESM import in node:
|
|
@@ -6,6 +6,7 @@ export declare const LAMBDA_FUNCTIONS: Lambdas;
|
|
|
6
6
|
export declare const setLambdaFunctions: (foundFunctions: string[]) => Promise<void>;
|
|
7
7
|
type LoadFunctionsFromDistOptions = {
|
|
8
8
|
fastGlobOptions?: FastGlobOptions;
|
|
9
|
+
discoverFunctionsGlob?: string | string[];
|
|
9
10
|
};
|
|
10
11
|
export declare const loadFunctionsFromDist: (options?: LoadFunctionsFromDistOptions) => Promise<void>;
|
|
11
12
|
interface LambdaHandlerRequest extends RequestGenericInterface {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"lambdaLoader.d.ts","sourceRoot":"","sources":["../../src/plugins/lambdaLoader.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,YAAY,CAAA;AAGzC,OAAO,KAAK,EAAE,OAAO,IAAI,eAAe,EAAE,MAAM,WAAW,CAAA;AAC3D,OAAO,KAAK,EACV,YAAY,EACZ,cAAc,EACd,uBAAuB,EACxB,MAAM,SAAS,CAAA;AAOhB,MAAM,MAAM,OAAO,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAA;AAC7C,eAAO,MAAM,gBAAgB,EAAE,OAAY,CAAA;AAI3C,eAAO,MAAM,kBAAkB,mBAA0B,MAAM,EAAE,
|
|
1
|
+
{"version":3,"file":"lambdaLoader.d.ts","sourceRoot":"","sources":["../../src/plugins/lambdaLoader.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,YAAY,CAAA;AAGzC,OAAO,KAAK,EAAE,OAAO,IAAI,eAAe,EAAE,MAAM,WAAW,CAAA;AAC3D,OAAO,KAAK,EACV,YAAY,EACZ,cAAc,EACd,uBAAuB,EACxB,MAAM,SAAS,CAAA;AAOhB,MAAM,MAAM,OAAO,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAA;AAC7C,eAAO,MAAM,gBAAgB,EAAE,OAAY,CAAA;AAI3C,eAAO,MAAM,kBAAkB,mBAA0B,MAAM,EAAE,kBAsDhE,CAAA;AAED,KAAK,4BAA4B,GAAG;IAClC,eAAe,CAAC,EAAE,eAAe,CAAA;IACjC,qBAAqB,CAAC,EAAE,MAAM,GAAG,MAAM,EAAE,CAAA;CAC1C,CAAA;AAGD,eAAO,MAAM,qBAAqB,aACvB,4BAA4B,kBAetC,CAAA;AA0BD,UAAU,oBAAqB,SAAQ,uBAAuB;IAC5D,MAAM,EAAE;QACN,SAAS,EAAE,MAAM,CAAA;KAClB,CAAA;CACF;AAED;;;;IAII;AACJ,eAAO,MAAM,oBAAoB,QAC1B,cAAc,CAAC,oBAAoB,CAAC,SAClC,YAAY,kBAsBpB,CAAA"}
|
|
@@ -47,7 +47,18 @@ const setLambdaFunctions = async (foundFunctions) => {
|
|
|
47
47
|
const imports = foundFunctions.map(async (fnPath) => {
|
|
48
48
|
const ts = Date.now();
|
|
49
49
|
const routeName = import_path.default.basename(fnPath).replace(".js", "");
|
|
50
|
-
const
|
|
50
|
+
const fnImport = await import(`file://${fnPath}`);
|
|
51
|
+
const handler = (() => {
|
|
52
|
+
if ("handler" in fnImport) {
|
|
53
|
+
return fnImport.handler;
|
|
54
|
+
}
|
|
55
|
+
if ("default" in fnImport) {
|
|
56
|
+
if ("handler" in fnImport.default) {
|
|
57
|
+
return fnImport.default.handler;
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
return void 0;
|
|
61
|
+
})();
|
|
51
62
|
LAMBDA_FUNCTIONS[routeName] = handler;
|
|
52
63
|
if (!handler) {
|
|
53
64
|
console.warn(
|
|
@@ -68,10 +79,11 @@ const setLambdaFunctions = async (foundFunctions) => {
|
|
|
68
79
|
);
|
|
69
80
|
};
|
|
70
81
|
const loadFunctionsFromDist = async (options = {}) => {
|
|
71
|
-
const serverFunctions = findApiDistFunctions(
|
|
72
|
-
(0, import_project_config.getPaths)().api.base,
|
|
73
|
-
options?.fastGlobOptions
|
|
74
|
-
|
|
82
|
+
const serverFunctions = findApiDistFunctions({
|
|
83
|
+
cwd: (0, import_project_config.getPaths)().api.base,
|
|
84
|
+
options: options?.fastGlobOptions,
|
|
85
|
+
discoverFunctionsGlob: options?.discoverFunctionsGlob
|
|
86
|
+
});
|
|
75
87
|
const i = serverFunctions.findIndex((x) => import_path.default.basename(x) === "graphql.js");
|
|
76
88
|
if (i >= 0) {
|
|
77
89
|
const graphQLFn = serverFunctions.splice(i, 1)[0];
|
|
@@ -79,15 +91,21 @@ const loadFunctionsFromDist = async (options = {}) => {
|
|
|
79
91
|
}
|
|
80
92
|
await setLambdaFunctions(serverFunctions);
|
|
81
93
|
};
|
|
82
|
-
|
|
83
|
-
|
|
94
|
+
const findApiDistFunctions = (params) => {
|
|
95
|
+
const {
|
|
96
|
+
cwd = (0, import_project_config.getPaths)().api.base,
|
|
97
|
+
options = {},
|
|
98
|
+
discoverFunctionsGlob = "dist/functions/**/*.{ts,js}"
|
|
99
|
+
} = params;
|
|
100
|
+
return import_fast_glob.default.sync(discoverFunctionsGlob, {
|
|
84
101
|
cwd,
|
|
102
|
+
// We don't support deeply nested api functions, to maximise compatibility
|
|
103
|
+
// with deployment providers
|
|
85
104
|
deep: 2,
|
|
86
|
-
// We don't support deeply nested api functions, to maximise compatibility with deployment providers
|
|
87
105
|
absolute: true,
|
|
88
106
|
...options
|
|
89
107
|
});
|
|
90
|
-
}
|
|
108
|
+
};
|
|
91
109
|
const lambdaRequestHandler = async (req, reply) => {
|
|
92
110
|
const { routeName } = req.params;
|
|
93
111
|
if (!LAMBDA_FUNCTIONS[routeName]) {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@cedarjs/api-server",
|
|
3
|
-
"version": "1.0.0-canary.
|
|
3
|
+
"version": "1.0.0-canary.12391+a353ecd1b",
|
|
4
4
|
"description": "CedarJS's HTTP server for Serverless Functions",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
@@ -29,11 +29,11 @@
|
|
|
29
29
|
"test:watch": "vitest watch"
|
|
30
30
|
},
|
|
31
31
|
"dependencies": {
|
|
32
|
-
"@cedarjs/context": "1.0.0-canary.
|
|
33
|
-
"@cedarjs/fastify-web": "1.0.0-canary.
|
|
34
|
-
"@cedarjs/internal": "1.0.0-canary.
|
|
35
|
-
"@cedarjs/project-config": "1.0.0-canary.
|
|
36
|
-
"@cedarjs/web-server": "1.0.0-canary.
|
|
32
|
+
"@cedarjs/context": "1.0.0-canary.12391",
|
|
33
|
+
"@cedarjs/fastify-web": "1.0.0-canary.12391",
|
|
34
|
+
"@cedarjs/internal": "1.0.0-canary.12391",
|
|
35
|
+
"@cedarjs/project-config": "1.0.0-canary.12391",
|
|
36
|
+
"@cedarjs/web-server": "1.0.0-canary.12391",
|
|
37
37
|
"@fastify/multipart": "9.0.3",
|
|
38
38
|
"@fastify/url-data": "6.0.3",
|
|
39
39
|
"chalk": "4.1.2",
|
|
@@ -51,7 +51,7 @@
|
|
|
51
51
|
"yargs": "17.7.2"
|
|
52
52
|
},
|
|
53
53
|
"devDependencies": {
|
|
54
|
-
"@cedarjs/framework-tools": "1.0.0-canary.
|
|
54
|
+
"@cedarjs/framework-tools": "1.0.0-canary.12391",
|
|
55
55
|
"@types/aws-lambda": "8.10.145",
|
|
56
56
|
"@types/lodash": "4.17.15",
|
|
57
57
|
"@types/qs": "6.9.16",
|
|
@@ -64,12 +64,12 @@
|
|
|
64
64
|
"vitest": "3.2.4"
|
|
65
65
|
},
|
|
66
66
|
"peerDependencies": {
|
|
67
|
-
"@cedarjs/graphql-server": "1.0.0-canary.
|
|
67
|
+
"@cedarjs/graphql-server": "1.0.0-canary.12391"
|
|
68
68
|
},
|
|
69
69
|
"peerDependenciesMeta": {
|
|
70
70
|
"@cedarjs/graphql-server": {
|
|
71
71
|
"optional": true
|
|
72
72
|
}
|
|
73
73
|
},
|
|
74
|
-
"gitHead": "
|
|
74
|
+
"gitHead": "a353ecd1b514fbf35b6acb47af46d3631929f18c"
|
|
75
75
|
}
|