@cedarjs/api-server 9.0.0-canary.1784 → 9.0.0-canary.3124

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.
Files changed (127) hide show
  1. package/README.md +0 -1
  2. package/dist/apiCLIConfig.d.ts.map +1 -1
  3. package/dist/apiCLIConfig.js +1 -1
  4. package/dist/apiCLIConfigHandler.d.ts.map +1 -1
  5. package/dist/apiCLIConfigHandler.js +5 -0
  6. package/dist/bin.js +316 -98
  7. package/dist/bothCLIConfig.d.ts.map +1 -1
  8. package/dist/bothCLIConfig.js +2 -2
  9. package/dist/bothCLIConfigHandler.d.ts.map +1 -1
  10. package/dist/bothCLIConfigHandler.js +8 -2
  11. package/dist/cliHelpers.d.ts +22 -4
  12. package/dist/cliHelpers.d.ts.map +1 -1
  13. package/dist/cliHelpers.js +43 -11
  14. package/dist/createServer.d.ts +19 -3
  15. package/dist/createServer.d.ts.map +1 -1
  16. package/dist/createServer.js +18 -11
  17. package/dist/createServerHelpers.d.ts +15 -2
  18. package/dist/createServerHelpers.d.ts.map +1 -1
  19. package/dist/createServerHelpers.js +14 -4
  20. package/dist/fastify.d.ts.map +1 -1
  21. package/dist/fastify.js +5 -0
  22. package/dist/logFormatter/formatters.d.ts +1 -1
  23. package/dist/logFormatter/formatters.d.ts.map +1 -1
  24. package/dist/logFormatter/index.d.ts.map +1 -1
  25. package/dist/plugins/api.d.ts +4 -5
  26. package/dist/plugins/api.d.ts.map +1 -1
  27. package/dist/plugins/api.js +15 -15
  28. package/dist/plugins/graphql.d.ts +20 -3
  29. package/dist/plugins/graphql.d.ts.map +1 -1
  30. package/dist/plugins/graphql.js +69 -28
  31. package/dist/plugins/lambdaLoader.d.ts +16 -6
  32. package/dist/plugins/lambdaLoader.d.ts.map +1 -1
  33. package/dist/plugins/lambdaLoader.js +73 -10
  34. package/dist/requestHandlers/awsLambdaFastify.d.ts.map +1 -1
  35. package/dist/requestHandlers/awsLambdaFastify.js +16 -4
  36. package/dist/serverFile.d.ts +23 -0
  37. package/dist/serverFile.d.ts.map +1 -0
  38. package/dist/serverFile.js +35 -0
  39. package/dist/types.d.ts +4 -4
  40. package/dist/types.d.ts.map +1 -1
  41. package/dist/utils.d.ts +0 -3
  42. package/dist/utils.d.ts.map +1 -1
  43. package/dist/utils.js +0 -20
  44. package/package.json +56 -72
  45. package/LICENSE +0 -21
  46. package/dist/buildManager.d.ts +0 -15
  47. package/dist/buildManager.d.ts.map +0 -1
  48. package/dist/buildManager.js +0 -50
  49. package/dist/cjs/apiCLIConfig.d.ts +0 -6
  50. package/dist/cjs/apiCLIConfig.d.ts.map +0 -1
  51. package/dist/cjs/apiCLIConfig.js +0 -71
  52. package/dist/cjs/apiCLIConfigHandler.d.ts +0 -3
  53. package/dist/cjs/apiCLIConfigHandler.d.ts.map +0 -1
  54. package/dist/cjs/apiCLIConfigHandler.js +0 -67
  55. package/dist/cjs/bin.d.ts +0 -2
  56. package/dist/cjs/bin.d.ts.map +0 -1
  57. package/dist/cjs/bin.js +0 -896
  58. package/dist/cjs/bothCLIConfig.d.ts +0 -6
  59. package/dist/cjs/bothCLIConfig.d.ts.map +0 -1
  60. package/dist/cjs/bothCLIConfig.js +0 -76
  61. package/dist/cjs/bothCLIConfigHandler.d.ts +0 -3
  62. package/dist/cjs/bothCLIConfigHandler.d.ts.map +0 -1
  63. package/dist/cjs/bothCLIConfigHandler.js +0 -107
  64. package/dist/cjs/buildManager.d.ts +0 -15
  65. package/dist/cjs/buildManager.d.ts.map +0 -1
  66. package/dist/cjs/buildManager.js +0 -74
  67. package/dist/cjs/cliHelpers.d.ts +0 -5
  68. package/dist/cjs/cliHelpers.d.ts.map +0 -1
  69. package/dist/cjs/cliHelpers.js +0 -52
  70. package/dist/cjs/createServer.d.ts +0 -30
  71. package/dist/cjs/createServer.d.ts.map +0 -1
  72. package/dist/cjs/createServer.js +0 -144
  73. package/dist/cjs/createServerHelpers.d.ts +0 -38
  74. package/dist/cjs/createServerHelpers.d.ts.map +0 -1
  75. package/dist/cjs/createServerHelpers.js +0 -112
  76. package/dist/cjs/fastify.d.ts +0 -13
  77. package/dist/cjs/fastify.d.ts.map +0 -1
  78. package/dist/cjs/fastify.js +0 -91
  79. package/dist/cjs/logFormatter/ambient.d.js +0 -1
  80. package/dist/cjs/logFormatter/bin.d.ts +0 -2
  81. package/dist/cjs/logFormatter/bin.d.ts.map +0 -1
  82. package/dist/cjs/logFormatter/bin.js +0 -369
  83. package/dist/cjs/logFormatter/formatters.d.ts +0 -30
  84. package/dist/cjs/logFormatter/formatters.d.ts.map +0 -1
  85. package/dist/cjs/logFormatter/formatters.js +0 -275
  86. package/dist/cjs/logFormatter/index.d.ts +0 -2
  87. package/dist/cjs/logFormatter/index.d.ts.map +0 -1
  88. package/dist/cjs/logFormatter/index.js +0 -184
  89. package/dist/cjs/package.json +0 -1
  90. package/dist/cjs/plugins/api.d.ts +0 -14
  91. package/dist/cjs/plugins/api.d.ts.map +0 -1
  92. package/dist/cjs/plugins/api.js +0 -78
  93. package/dist/cjs/plugins/graphql.d.ts +0 -10
  94. package/dist/cjs/plugins/graphql.d.ts.map +0 -1
  95. package/dist/cjs/plugins/graphql.js +0 -109
  96. package/dist/cjs/plugins/lambdaLoader.d.ts +0 -24
  97. package/dist/cjs/plugins/lambdaLoader.d.ts.map +0 -1
  98. package/dist/cjs/plugins/lambdaLoader.js +0 -134
  99. package/dist/cjs/requestHandlers/awsLambdaFastify.d.ts +0 -5
  100. package/dist/cjs/requestHandlers/awsLambdaFastify.d.ts.map +0 -1
  101. package/dist/cjs/requestHandlers/awsLambdaFastify.js +0 -103
  102. package/dist/cjs/requestHandlers/utils.d.ts +0 -26
  103. package/dist/cjs/requestHandlers/utils.d.ts.map +0 -1
  104. package/dist/cjs/requestHandlers/utils.js +0 -55
  105. package/dist/cjs/serverManager.d.ts +0 -8
  106. package/dist/cjs/serverManager.d.ts.map +0 -1
  107. package/dist/cjs/serverManager.js +0 -137
  108. package/dist/cjs/types.d.ts +0 -19
  109. package/dist/cjs/types.d.ts.map +0 -1
  110. package/dist/cjs/utils.d.ts +0 -6
  111. package/dist/cjs/utils.d.ts.map +0 -1
  112. package/dist/cjs/utils.js +0 -58
  113. package/dist/cjs/watch.d.ts +0 -10
  114. package/dist/cjs/watch.d.ts.map +0 -1
  115. package/dist/cjs/watch.js +0 -394
  116. package/dist/cjs/watchPaths.d.ts +0 -3
  117. package/dist/cjs/watchPaths.d.ts.map +0 -1
  118. package/dist/cjs/watchPaths.js +0 -140
  119. package/dist/serverManager.d.ts +0 -8
  120. package/dist/serverManager.d.ts.map +0 -1
  121. package/dist/serverManager.js +0 -102
  122. package/dist/watch.d.ts +0 -10
  123. package/dist/watch.d.ts.map +0 -1
  124. package/dist/watch.js +0 -370
  125. package/dist/watchPaths.d.ts +0 -3
  126. package/dist/watchPaths.d.ts.map +0 -1
  127. package/dist/watchPaths.js +0 -109
@@ -1,6 +0,0 @@
1
- import type { Argv } from 'yargs';
2
- import type { BothParsedOptions } from './types.js';
3
- export declare const description = "Start a server for serving the api and web sides";
4
- export declare function builder(yargs: Argv<BothParsedOptions>): void;
5
- export declare function handler(options: BothParsedOptions): Promise<void>;
6
- //# sourceMappingURL=bothCLIConfig.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"bothCLIConfig.d.ts","sourceRoot":"","sources":["../../src/bothCLIConfig.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,OAAO,CAAA;AAEjC,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,YAAY,CAAA;AAEnD,eAAO,MAAM,WAAW,qDAAqD,CAAA;AAE7E,wBAAgB,OAAO,CAAC,KAAK,EAAE,IAAI,CAAC,iBAAiB,CAAC,QA+BrD;AAED,wBAAsB,OAAO,CAAC,OAAO,EAAE,iBAAiB,iBAGvD"}
@@ -1,76 +0,0 @@
1
- "use strict";
2
- var __create = Object.create;
3
- var __defProp = Object.defineProperty;
4
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
- var __getOwnPropNames = Object.getOwnPropertyNames;
6
- var __getProtoOf = Object.getPrototypeOf;
7
- var __hasOwnProp = Object.prototype.hasOwnProperty;
8
- var __export = (target, all) => {
9
- for (var name in all)
10
- __defProp(target, name, { get: all[name], enumerable: true });
11
- };
12
- var __copyProps = (to, from, except, desc) => {
13
- if (from && typeof from === "object" || typeof from === "function") {
14
- for (let key of __getOwnPropNames(from))
15
- if (!__hasOwnProp.call(to, key) && key !== except)
16
- __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
17
- }
18
- return to;
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
- ));
28
- var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
29
- var bothCLIConfig_exports = {};
30
- __export(bothCLIConfig_exports, {
31
- builder: () => builder,
32
- description: () => description,
33
- handler: () => handler
34
- });
35
- module.exports = __toCommonJS(bothCLIConfig_exports);
36
- const description = "Start a server for serving the api and web sides";
37
- function builder(yargs) {
38
- yargs.options({
39
- webPort: {
40
- description: "The port for the web server to listen on",
41
- type: "number",
42
- alias: ["web-port"]
43
- },
44
- webHost: {
45
- description: "The host for the web server to listen on. Note that you most likely want this to be '0.0.0.0' in production",
46
- type: "string",
47
- alias: ["web-host"]
48
- },
49
- apiPort: {
50
- description: "The port for the api server to listen on",
51
- type: "number",
52
- alias: ["api-port"]
53
- },
54
- apiHost: {
55
- description: "The host for the api server to listen on. Note that you most likely want this to be '0.0.0.0' in production",
56
- type: "string",
57
- alias: ["api-host"]
58
- },
59
- apiRootPath: {
60
- description: "Root path where your api functions are served",
61
- type: "string",
62
- alias: ["api-root-path", "rootPath", "root-path"],
63
- default: "/"
64
- }
65
- });
66
- }
67
- async function handler(options) {
68
- const { handler: handler2 } = await import("./bothCLIConfigHandler.js");
69
- await handler2(options);
70
- }
71
- // Annotate the CommonJS export names for ESM import in node:
72
- 0 && (module.exports = {
73
- builder,
74
- description,
75
- handler
76
- });
@@ -1,3 +0,0 @@
1
- import type { BothParsedOptions } from './types.js';
2
- export declare function handler(options: BothParsedOptions): Promise<void>;
3
- //# sourceMappingURL=bothCLIConfigHandler.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"bothCLIConfigHandler.d.ts","sourceRoot":"","sources":["../../src/bothCLIConfigHandler.ts"],"names":[],"mappings":"AAUA,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,YAAY,CAAA;AAEnD,wBAAsB,OAAO,CAAC,OAAO,EAAE,iBAAiB,iBAmEvD"}
@@ -1,107 +0,0 @@
1
- "use strict";
2
- var __create = Object.create;
3
- var __defProp = Object.defineProperty;
4
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
- var __getOwnPropNames = Object.getOwnPropertyNames;
6
- var __getProtoOf = Object.getPrototypeOf;
7
- var __hasOwnProp = Object.prototype.hasOwnProperty;
8
- var __export = (target, all) => {
9
- for (var name in all)
10
- __defProp(target, name, { get: all[name], enumerable: true });
11
- };
12
- var __copyProps = (to, from, except, desc) => {
13
- if (from && typeof from === "object" || typeof from === "function") {
14
- for (let key of __getOwnPropNames(from))
15
- if (!__hasOwnProp.call(to, key) && key !== except)
16
- __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
17
- }
18
- return to;
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
- ));
28
- var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
29
- var bothCLIConfigHandler_exports = {};
30
- __export(bothCLIConfigHandler_exports, {
31
- handler: () => handler
32
- });
33
- module.exports = __toCommonJS(bothCLIConfigHandler_exports);
34
- var import_ansis = __toESM(require("ansis"), 1);
35
- var import_fastify_web = require("@cedarjs/fastify-web");
36
- var import_cliHelpers = require("./cliHelpers.js");
37
- var import_createServer = require("./createServer.js");
38
- var import_fastify = require("./fastify.js");
39
- async function handler(options) {
40
- const timeStart = Date.now();
41
- console.log(import_ansis.default.dim.italic("Starting API and Web Servers..."));
42
- options.webHost ??= (0, import_cliHelpers.getWebHost)();
43
- options.webPort ??= (0, import_cliHelpers.getWebPort)();
44
- options.apiHost ??= (0, import_cliHelpers.getAPIHost)();
45
- options.apiPort ??= (0, import_cliHelpers.getAPIPort)();
46
- options.apiRootPath = (0, import_fastify_web.coerceRootPath)(options.apiRootPath ?? "/");
47
- const apiProxyTarget = [
48
- "http://",
49
- options.apiHost.includes(":") ? `[${options.apiHost}]` : options.apiHost,
50
- ":",
51
- options.apiPort,
52
- options.apiRootPath
53
- ].join("");
54
- const webFastify = await (0, import_fastify.createFastifyInstance)();
55
- webFastify.register(import_fastify_web.redwoodFastifyWeb, {
56
- redwood: {
57
- apiProxyTarget
58
- }
59
- });
60
- const apiFastify = await (0, import_createServer.createServer)({
61
- apiRootPath: options.apiRootPath
62
- });
63
- await webFastify.listen({
64
- port: options.webPort,
65
- host: options.webHost,
66
- listenTextResolver: getListenTextResolver("Web")
67
- });
68
- webFastify.log.trace(
69
- { custom: { ...webFastify.initialConfig } },
70
- "Fastify server configuration"
71
- );
72
- webFastify.log.trace(`Registered plugins
73
- ${webFastify.printPlugins()}`);
74
- await apiFastify.listen({
75
- port: options.apiPort,
76
- host: options.apiHost,
77
- listenTextResolver: getListenTextResolver("API")
78
- });
79
- apiFastify.log.trace(
80
- { custom: { ...apiFastify.initialConfig } },
81
- "Fastify server configuration"
82
- );
83
- apiFastify.log.trace(`Registered plugins
84
- ${apiFastify.printPlugins()}`);
85
- console.log(import_ansis.default.dim.italic("Took " + (Date.now() - timeStart) + " ms"));
86
- const webServer = import_ansis.default.green(webFastify.listeningOrigin);
87
- const apiServer = import_ansis.default.magenta(
88
- `${apiFastify.listeningOrigin}${options.apiRootPath}`
89
- );
90
- const graphqlEndpoint = import_ansis.default.magenta(`${apiServer}graphql`);
91
- console.log(`Web server listening at ${webServer}`);
92
- console.log(`API server listening at ${apiServer}`);
93
- console.log(`GraphQL endpoint at ${graphqlEndpoint}`);
94
- process?.send?.("ready");
95
- }
96
- function getListenTextResolver(side) {
97
- return (address) => {
98
- if (process.env.NODE_ENV !== "production") {
99
- address = address.replace(/http:\/\/\[::\]/, "http://localhost");
100
- }
101
- return `${side} server listening at ${address}`;
102
- };
103
- }
104
- // Annotate the CommonJS export names for ESM import in node:
105
- 0 && (module.exports = {
106
- handler
107
- });
@@ -1,15 +0,0 @@
1
- export type BuildAndRestartOptions = {
2
- rebuild?: boolean;
3
- clean?: boolean;
4
- };
5
- declare class BuildManager {
6
- private shouldRebuild;
7
- private shouldClean;
8
- private debouncedBuild;
9
- private buildFn;
10
- constructor(buildFn: (options: BuildAndRestartOptions) => Promise<void>);
11
- run(options: BuildAndRestartOptions): Promise<void>;
12
- cancelScheduledBuild(): void;
13
- }
14
- export { BuildManager };
15
- //# sourceMappingURL=buildManager.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"buildManager.d.ts","sourceRoot":"","sources":["../../src/buildManager.ts"],"names":[],"mappings":"AAEA,MAAM,MAAM,sBAAsB,GAAG;IACnC,OAAO,CAAC,EAAE,OAAO,CAAA;IACjB,KAAK,CAAC,EAAE,OAAO,CAAA;CAChB,CAAA;AAED,cAAM,YAAY;IAChB,OAAO,CAAC,aAAa,CAAS;IAC9B,OAAO,CAAC,WAAW,CAAS;IAC5B,OAAO,CAAC,cAAc,CAA6B;IACnD,OAAO,CAAC,OAAO,CAAoD;gBAEvD,OAAO,EAAE,CAAC,OAAO,EAAE,sBAAsB,KAAK,OAAO,CAAC,IAAI,CAAC;IAgCjE,GAAG,CAAC,OAAO,EAAE,sBAAsB;IAWzC,oBAAoB;CAGrB;AAED,OAAO,EAAE,YAAY,EAAE,CAAA"}
@@ -1,74 +0,0 @@
1
- "use strict";
2
- var __defProp = Object.defineProperty;
3
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
- var __getOwnPropNames = Object.getOwnPropertyNames;
5
- var __hasOwnProp = Object.prototype.hasOwnProperty;
6
- var __export = (target, all) => {
7
- for (var name in all)
8
- __defProp(target, name, { get: all[name], enumerable: true });
9
- };
10
- var __copyProps = (to, from, except, desc) => {
11
- if (from && typeof from === "object" || typeof from === "function") {
12
- for (let key of __getOwnPropNames(from))
13
- if (!__hasOwnProp.call(to, key) && key !== except)
14
- __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
- }
16
- return to;
17
- };
18
- var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
- var buildManager_exports = {};
20
- __export(buildManager_exports, {
21
- BuildManager: () => BuildManager
22
- });
23
- module.exports = __toCommonJS(buildManager_exports);
24
- var import_utils = require("./utils.js");
25
- class BuildManager {
26
- shouldRebuild;
27
- shouldClean;
28
- debouncedBuild;
29
- buildFn;
30
- constructor(buildFn) {
31
- this.shouldRebuild = true;
32
- this.shouldClean = false;
33
- this.buildFn = buildFn;
34
- const delay = process.env.CEDAR_DELAY_API_RESTART || process.env.RWJS_DELAY_RESTART;
35
- this.debouncedBuild = (0, import_utils.debounce)(
36
- async (options) => {
37
- try {
38
- await this.buildFn({
39
- ...options,
40
- rebuild: this.shouldRebuild,
41
- clean: this.shouldClean
42
- });
43
- } finally {
44
- this.shouldRebuild = true;
45
- this.shouldClean = false;
46
- }
47
- },
48
- // We want to delay execution when multiple files are modified on the
49
- // filesystem. This usually happens when running Cedar generator commands.
50
- // Local writes are very fast, but writes in e2e environments are not, so
51
- // allow the default to be adjusted with an env-var.
52
- delay ? parseInt(delay, 10) : 500
53
- );
54
- }
55
- // Wrapper method to handle options and set precedence flags.
56
- // If we ever see a `rebuild: false` option while debouncing, we never want to rebuild.
57
- // If we ever see a `clean: true` option, we always want to clean.
58
- async run(options) {
59
- if (options.rebuild === false) {
60
- this.shouldRebuild = false;
61
- }
62
- if (options.clean) {
63
- this.shouldClean = true;
64
- }
65
- await this.debouncedBuild(options);
66
- }
67
- cancelScheduledBuild() {
68
- this.debouncedBuild.cancel();
69
- }
70
- }
71
- // Annotate the CommonJS export names for ESM import in node:
72
- 0 && (module.exports = {
73
- BuildManager
74
- });
@@ -1,5 +0,0 @@
1
- export declare function getAPIHost(): string;
2
- export declare function getAPIPort(): number;
3
- export declare function getWebHost(): string;
4
- export declare function getWebPort(): number;
5
- //# sourceMappingURL=cliHelpers.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"cliHelpers.d.ts","sourceRoot":"","sources":["../../src/cliHelpers.ts"],"names":[],"mappings":"AAEA,wBAAgB,UAAU,WAKzB;AAED,wBAAgB,UAAU,WAIzB;AAED,wBAAgB,UAAU,WAKzB;AAED,wBAAgB,UAAU,WAIzB"}
@@ -1,52 +0,0 @@
1
- "use strict";
2
- var __defProp = Object.defineProperty;
3
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
- var __getOwnPropNames = Object.getOwnPropertyNames;
5
- var __hasOwnProp = Object.prototype.hasOwnProperty;
6
- var __export = (target, all) => {
7
- for (var name in all)
8
- __defProp(target, name, { get: all[name], enumerable: true });
9
- };
10
- var __copyProps = (to, from, except, desc) => {
11
- if (from && typeof from === "object" || typeof from === "function") {
12
- for (let key of __getOwnPropNames(from))
13
- if (!__hasOwnProp.call(to, key) && key !== except)
14
- __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
- }
16
- return to;
17
- };
18
- var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
- var cliHelpers_exports = {};
20
- __export(cliHelpers_exports, {
21
- getAPIHost: () => getAPIHost,
22
- getAPIPort: () => getAPIPort,
23
- getWebHost: () => getWebHost,
24
- getWebPort: () => getWebPort
25
- });
26
- module.exports = __toCommonJS(cliHelpers_exports);
27
- var import_project_config = require("@cedarjs/project-config");
28
- function getAPIHost() {
29
- let host = process.env.REDWOOD_API_HOST;
30
- host ??= (0, import_project_config.getConfig)().api.host;
31
- host ??= process.env.NODE_ENV === "production" ? "0.0.0.0" : "::";
32
- return host;
33
- }
34
- function getAPIPort() {
35
- return process.env.REDWOOD_API_PORT ? parseInt(process.env.REDWOOD_API_PORT) : (0, import_project_config.getConfig)().api.port;
36
- }
37
- function getWebHost() {
38
- let host = process.env.REDWOOD_WEB_HOST;
39
- host ??= (0, import_project_config.getConfig)().web.host;
40
- host ??= process.env.NODE_ENV === "production" ? "0.0.0.0" : "::";
41
- return host;
42
- }
43
- function getWebPort() {
44
- return process.env.REDWOOD_WEB_PORT ? parseInt(process.env.REDWOOD_WEB_PORT) : (0, import_project_config.getConfig)().web.port;
45
- }
46
- // Annotate the CommonJS export names for ESM import in node:
47
- 0 && (module.exports = {
48
- getAPIHost,
49
- getAPIPort,
50
- getWebHost,
51
- getWebPort
52
- });
@@ -1,30 +0,0 @@
1
- import type { CreateServerOptions, Server } from './createServerHelpers.js';
2
- /**
3
- * Creates a server for api functions:
4
- *
5
- * ```js
6
- * import { createServer } from '@cedarjs/api-server'
7
- *
8
- * import { logger } from 'src/lib/logger'
9
- *
10
- async function main() {
11
- * const server = await createServer({
12
- * logger,
13
- * apiRootPath: 'api'
14
- * configureApiServer: (server) => {
15
- * // Configure the API server fastify instance, e.g. add content type parsers
16
- * },
17
- * })
18
- *
19
- * // Configure the returned fastify instance:
20
- * server.register(myPlugin)
21
- *
22
- * // When ready, start the server:
23
- * await server.start()
24
- * }
25
- *
26
- * main()
27
- * ```
28
- */
29
- export declare function createServer(options?: CreateServerOptions): Promise<Server>;
30
- //# sourceMappingURL=createServer.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"createServer.d.ts","sourceRoot":"","sources":["../../src/createServer.ts"],"names":[],"mappings":"AAgBA,OAAO,KAAK,EACV,mBAAmB,EACnB,MAAM,EAEP,MAAM,0BAA0B,CAAA;AAqBjC;;;;;;;;;;;;;;;;;;;;;;;;;;GA0BG;AACH,wBAAsB,YAAY,CAAC,OAAO,GAAE,mBAAwB,mBAoHnE"}
@@ -1,144 +0,0 @@
1
- "use strict";
2
- var __create = Object.create;
3
- var __defProp = Object.defineProperty;
4
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
- var __getOwnPropNames = Object.getOwnPropertyNames;
6
- var __getProtoOf = Object.getPrototypeOf;
7
- var __hasOwnProp = Object.prototype.hasOwnProperty;
8
- var __export = (target, all) => {
9
- for (var name in all)
10
- __defProp(target, name, { get: all[name], enumerable: true });
11
- };
12
- var __copyProps = (to, from, except, desc) => {
13
- if (from && typeof from === "object" || typeof from === "function") {
14
- for (let key of __getOwnPropNames(from))
15
- if (!__hasOwnProp.call(to, key) && key !== except)
16
- __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
17
- }
18
- return to;
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
- ));
28
- var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
29
- var createServer_exports = {};
30
- __export(createServer_exports, {
31
- createServer: () => createServer
32
- });
33
- module.exports = __toCommonJS(createServer_exports);
34
- var import_node_fs = __toESM(require("node:fs"), 1);
35
- var import_path = __toESM(require("path"), 1);
36
- var import_ansis = __toESM(require("ansis"), 1);
37
- var import_dotenv_defaults = require("dotenv-defaults");
38
- var import_fast_glob = __toESM(require("fast-glob"), 1);
39
- var import_fastify = __toESM(require("fastify"), 1);
40
- var import_store = require("@cedarjs/context/dist/store");
41
- var import_project_config = require("@cedarjs/project-config");
42
- var import_createServerHelpers = require("./createServerHelpers.js");
43
- var import_api = require("./plugins/api.js");
44
- if (!process.env.REDWOOD_ENV_FILES_LOADED) {
45
- (0, import_dotenv_defaults.config)({
46
- path: import_path.default.join((0, import_project_config.getPaths)().base, ".env"),
47
- defaults: import_path.default.join((0, import_project_config.getPaths)().base, ".env.defaults"),
48
- multiline: true
49
- });
50
- process.env.REDWOOD_ENV_FILES_LOADED = "true";
51
- }
52
- async function createServer(options = {}) {
53
- const {
54
- apiRootPath,
55
- fastifyServerOptions,
56
- discoverFunctionsGlob,
57
- configureApiServer,
58
- apiPort,
59
- apiHost
60
- } = (0, import_createServerHelpers.resolveOptions)(options);
61
- const serverConfigPath = import_path.default.join(
62
- (0, import_project_config.getPaths)().base,
63
- (0, import_project_config.getConfig)().api.serverConfig
64
- );
65
- if (import_node_fs.default.existsSync(serverConfigPath)) {
66
- console.warn(
67
- import_ansis.default.yellow(
68
- [
69
- "",
70
- `Ignoring \`config\` and \`configureServer\` in api/server.config.js.`,
71
- `Migrate them to api/src/server.{ts,js}:`,
72
- "",
73
- `\`\`\`js title="api/src/server.{ts,js}"`,
74
- "// Pass your config to `createServer`",
75
- "const server = createServer({",
76
- " fastifyServerOptions: myFastifyConfig",
77
- "})",
78
- "",
79
- "// Then inline your `configureFastify` logic:",
80
- "server.register(myFastifyPlugin)",
81
- "```",
82
- ""
83
- ].join("\n")
84
- )
85
- );
86
- }
87
- const server = Object.assign((0, import_fastify.default)(fastifyServerOptions), {
88
- // `start` will get replaced further down in this file
89
- start: async () => {
90
- throw new Error("Not implemented yet");
91
- }
92
- });
93
- server.addHook("onRequest", (_req, _reply, done) => {
94
- (0, import_store.getAsyncStoreInstance)().run(/* @__PURE__ */ new Map(), done);
95
- });
96
- await server.register(import_api.redwoodFastifyAPI, {
97
- redwood: {
98
- apiRootPath,
99
- fastGlobOptions: {
100
- ignore: ["**/dist/functions/graphql.js"]
101
- },
102
- discoverFunctionsGlob,
103
- configureServer: configureApiServer
104
- }
105
- });
106
- const [graphqlFunctionPath] = await (0, import_fast_glob.default)("dist/functions/graphql.{ts,js}", {
107
- cwd: (0, import_project_config.getPaths)().api.base,
108
- absolute: true
109
- });
110
- if (graphqlFunctionPath) {
111
- const { redwoodFastifyGraphQLServer } = await import("./plugins/graphql.js");
112
- const { __rw_graphqlOptions } = await import(`file://${graphqlFunctionPath}`);
113
- await server.register(redwoodFastifyGraphQLServer, {
114
- redwood: {
115
- apiRootPath,
116
- graphql: __rw_graphqlOptions
117
- }
118
- });
119
- }
120
- server.addHook("onReady", (done) => {
121
- process.send?.("ready");
122
- done();
123
- });
124
- server.addHook("onListen", (done) => {
125
- console.log(
126
- `Server listening at ${import_ansis.default.magenta(
127
- `${server.listeningOrigin}${apiRootPath}`
128
- )}`
129
- );
130
- done();
131
- });
132
- server.start = (options2 = {}) => {
133
- return server.listen({
134
- ...options2,
135
- port: apiPort,
136
- host: apiHost
137
- });
138
- };
139
- return server;
140
- }
141
- // Annotate the CommonJS export names for ESM import in node:
142
- 0 && (module.exports = {
143
- createServer
144
- });
@@ -1,38 +0,0 @@
1
- import type { FastifyListenOptions, FastifyServerOptions, FastifyInstance } from 'fastify';
2
- export type StartOptions = Omit<FastifyListenOptions, 'port' | 'host'>;
3
- export interface Server extends FastifyInstance {
4
- start: (options?: StartOptions) => Promise<string>;
5
- }
6
- export interface CreateServerOptions {
7
- /** The prefix for all routes. Defaults to `/` */
8
- apiRootPath?: string;
9
- /** Logger instance or options */
10
- logger?: FastifyServerOptions['logger'] | FastifyServerOptions['loggerInstance'];
11
- /**
12
- * Options for the fastify server instance.
13
- * Omitting logger here because we move it up.
14
- */
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[];
21
- /** Customise the API server fastify plugin before it is registered */
22
- configureApiServer?: (server: Server) => void | Promise<void>;
23
- /** Whether to parse args or not. Defaults to `true` */
24
- parseArgs?: boolean;
25
- /** The port to listen on. Defaults to what's configured in cedar.toml */
26
- apiPort?: number;
27
- /** The host to bind to. Defaults to what's configured in cedar.toml */
28
- apiHost?: string;
29
- }
30
- type DefaultCreateServerOptions = Required<Omit<CreateServerOptions, 'fastifyServerOptions'> & {
31
- fastifyServerOptions: FastifyServerOptions;
32
- }>;
33
- export declare const getDefaultCreateServerOptions: () => DefaultCreateServerOptions;
34
- export declare function resolveOptions(options?: CreateServerOptions, args?: string[]): Required<Omit<CreateServerOptions, "logger" | "fastifyServerOptions" | "parseArgs"> & {
35
- fastifyServerOptions: FastifyServerOptions;
36
- }>;
37
- export {};
38
- //# sourceMappingURL=createServerHelpers.d.ts.map
@@ -1 +0,0 @@
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,yEAAyE;IACzE,OAAO,CAAC,EAAE,MAAM,CAAA;IAEhB,uEAAuE;IACvE,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"}