@cedarjs/api-server 5.0.7-next.336 → 5.0.7-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.
Files changed (118) hide show
  1. package/README.md +1 -0
  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 +0 -5
  6. package/dist/bin.js +45 -160
  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 +2 -8
  11. package/dist/buildManager.d.ts +15 -0
  12. package/dist/buildManager.d.ts.map +1 -0
  13. package/dist/buildManager.js +55 -0
  14. package/dist/cjs/apiCLIConfig.d.ts +6 -0
  15. package/dist/cjs/apiCLIConfig.d.ts.map +1 -0
  16. package/dist/cjs/apiCLIConfig.js +71 -0
  17. package/dist/cjs/apiCLIConfigHandler.d.ts +3 -0
  18. package/dist/cjs/apiCLIConfigHandler.d.ts.map +1 -0
  19. package/dist/cjs/apiCLIConfigHandler.js +67 -0
  20. package/dist/cjs/bin.d.ts +2 -0
  21. package/dist/cjs/bin.d.ts.map +1 -0
  22. package/dist/cjs/bin.js +1002 -0
  23. package/dist/cjs/bothCLIConfig.d.ts +6 -0
  24. package/dist/cjs/bothCLIConfig.d.ts.map +1 -0
  25. package/dist/cjs/bothCLIConfig.js +76 -0
  26. package/dist/cjs/bothCLIConfigHandler.d.ts +3 -0
  27. package/dist/cjs/bothCLIConfigHandler.d.ts.map +1 -0
  28. package/dist/cjs/bothCLIConfigHandler.js +107 -0
  29. package/dist/cjs/buildManager.d.ts +15 -0
  30. package/dist/cjs/buildManager.d.ts.map +1 -0
  31. package/dist/cjs/buildManager.js +79 -0
  32. package/dist/cjs/cliHelpers.d.ts +6 -0
  33. package/dist/cjs/cliHelpers.d.ts.map +1 -0
  34. package/dist/cjs/cliHelpers.js +57 -0
  35. package/dist/cjs/createServer.d.ts +30 -0
  36. package/dist/cjs/createServer.d.ts.map +1 -0
  37. package/dist/cjs/createServer.js +145 -0
  38. package/dist/cjs/createServerHelpers.d.ts +38 -0
  39. package/dist/cjs/createServerHelpers.d.ts.map +1 -0
  40. package/dist/cjs/createServerHelpers.js +112 -0
  41. package/dist/cjs/fastify.d.ts +13 -0
  42. package/dist/cjs/fastify.d.ts.map +1 -0
  43. package/dist/cjs/fastify.js +96 -0
  44. package/dist/cjs/logFormatter/ambient.d.js +1 -0
  45. package/dist/cjs/logFormatter/bin.d.ts +2 -0
  46. package/dist/cjs/logFormatter/bin.d.ts.map +1 -0
  47. package/dist/cjs/logFormatter/bin.js +369 -0
  48. package/dist/cjs/logFormatter/formatters.d.ts +30 -0
  49. package/dist/cjs/logFormatter/formatters.d.ts.map +1 -0
  50. package/dist/cjs/logFormatter/formatters.js +275 -0
  51. package/dist/cjs/logFormatter/index.d.ts +2 -0
  52. package/dist/cjs/logFormatter/index.d.ts.map +1 -0
  53. package/dist/cjs/logFormatter/index.js +184 -0
  54. package/dist/cjs/package.json +1 -0
  55. package/dist/cjs/plugins/api.d.ts +14 -0
  56. package/dist/cjs/plugins/api.d.ts.map +1 -0
  57. package/dist/cjs/plugins/api.js +78 -0
  58. package/dist/cjs/plugins/graphql.d.ts +10 -0
  59. package/dist/cjs/plugins/graphql.d.ts.map +1 -0
  60. package/dist/cjs/plugins/graphql.js +135 -0
  61. package/dist/cjs/plugins/lambdaLoader.d.ts +34 -0
  62. package/dist/cjs/plugins/lambdaLoader.d.ts.map +1 -0
  63. package/dist/cjs/plugins/lambdaLoader.js +199 -0
  64. package/dist/cjs/requestHandlers/awsLambdaFastify.d.ts +5 -0
  65. package/dist/cjs/requestHandlers/awsLambdaFastify.d.ts.map +1 -0
  66. package/dist/cjs/requestHandlers/awsLambdaFastify.js +105 -0
  67. package/dist/cjs/requestHandlers/utils.d.ts +26 -0
  68. package/dist/cjs/requestHandlers/utils.d.ts.map +1 -0
  69. package/dist/cjs/requestHandlers/utils.js +55 -0
  70. package/dist/cjs/serverManager.d.ts +8 -0
  71. package/dist/cjs/serverManager.d.ts.map +1 -0
  72. package/dist/cjs/serverManager.js +137 -0
  73. package/dist/cjs/types.d.ts +19 -0
  74. package/dist/cjs/types.d.ts.map +1 -0
  75. package/dist/cjs/utils.d.ts +6 -0
  76. package/dist/cjs/utils.d.ts.map +1 -0
  77. package/dist/cjs/utils.js +58 -0
  78. package/dist/cjs/watch.d.ts +10 -0
  79. package/dist/cjs/watch.d.ts.map +1 -0
  80. package/dist/cjs/watch.js +399 -0
  81. package/dist/cjs/watchPaths.d.ts +3 -0
  82. package/dist/cjs/watchPaths.d.ts.map +1 -0
  83. package/dist/cjs/watchPaths.js +140 -0
  84. package/dist/cliHelpers.d.ts +4 -21
  85. package/dist/cliHelpers.d.ts.map +1 -1
  86. package/dist/cliHelpers.js +11 -39
  87. package/dist/createServer.d.ts +3 -19
  88. package/dist/createServer.d.ts.map +1 -1
  89. package/dist/createServer.js +5 -11
  90. package/dist/createServerHelpers.d.ts +2 -15
  91. package/dist/createServerHelpers.d.ts.map +1 -1
  92. package/dist/createServerHelpers.js +2 -12
  93. package/dist/logFormatter/formatters.d.ts.map +1 -1
  94. package/dist/plugins/api.d.ts +3 -2
  95. package/dist/plugins/api.d.ts.map +1 -1
  96. package/dist/plugins/api.js +1 -1
  97. package/dist/plugins/graphql.d.ts +3 -20
  98. package/dist/plugins/graphql.d.ts.map +1 -1
  99. package/dist/plugins/graphql.js +13 -31
  100. package/dist/plugins/lambdaLoader.d.ts.map +1 -1
  101. package/dist/serverManager.d.ts +8 -0
  102. package/dist/serverManager.d.ts.map +1 -0
  103. package/dist/serverManager.js +102 -0
  104. package/dist/types.d.ts +3 -3
  105. package/dist/types.d.ts.map +1 -1
  106. package/dist/utils.d.ts +3 -0
  107. package/dist/utils.d.ts.map +1 -1
  108. package/dist/utils.js +20 -0
  109. package/dist/watch.d.ts +10 -0
  110. package/dist/watch.d.ts.map +1 -0
  111. package/dist/watch.js +375 -0
  112. package/dist/watchPaths.d.ts +3 -0
  113. package/dist/watchPaths.d.ts.map +1 -0
  114. package/dist/watchPaths.js +109 -0
  115. package/package.json +79 -39
  116. package/dist/serverFile.d.ts +0 -23
  117. package/dist/serverFile.d.ts.map +0 -1
  118. package/dist/serverFile.js +0 -35
@@ -0,0 +1,1002 @@
1
+ #!/usr/bin/env node
2
+ "use strict";
3
+ var __create = Object.create;
4
+ var __defProp = Object.defineProperty;
5
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
6
+ var __getOwnPropNames = Object.getOwnPropertyNames;
7
+ var __getProtoOf = Object.getPrototypeOf;
8
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
9
+ var __esm = (fn, res) => function __init() {
10
+ return fn && (res = (0, fn[__getOwnPropNames(fn)[0]])(fn = 0)), res;
11
+ };
12
+ var __export = (target, all) => {
13
+ for (var name in all)
14
+ __defProp(target, name, { get: all[name], enumerable: true });
15
+ };
16
+ var __copyProps = (to, from, except, desc) => {
17
+ if (from && typeof from === "object" || typeof from === "function") {
18
+ for (let key of __getOwnPropNames(from))
19
+ if (!__hasOwnProp.call(to, key) && key !== except)
20
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
21
+ }
22
+ return to;
23
+ };
24
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
25
+ // If the importer is in node compatibility mode or this is not an ESM
26
+ // file that has been converted to a CommonJS file using a Babel-
27
+ // compatible transform (i.e. "__esModule" has not been set), then set
28
+ // "default" to the CommonJS "module.exports" for node compatibility.
29
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
30
+ mod
31
+ ));
32
+
33
+ // src/cliHelpers.ts
34
+ function getAPIHost() {
35
+ let host = process.env.REDWOOD_API_HOST;
36
+ host ??= (0, import_project_config.getConfig)().api.host;
37
+ host ??= process.env.NODE_ENV === "production" ? "0.0.0.0" : "::";
38
+ return host;
39
+ }
40
+ function getAPIPort() {
41
+ return process.env.REDWOOD_API_PORT ? parseInt(process.env.REDWOOD_API_PORT) : (0, import_project_config.getConfig)().api.port;
42
+ }
43
+ function getAPIRootPath() {
44
+ return process.env.CEDAR_API_ROOT_PATH ?? "/";
45
+ }
46
+ function getWebHost() {
47
+ let host = process.env.REDWOOD_WEB_HOST;
48
+ host ??= (0, import_project_config.getConfig)().web.host;
49
+ host ??= process.env.NODE_ENV === "production" ? "0.0.0.0" : "::";
50
+ return host;
51
+ }
52
+ function getWebPort() {
53
+ return process.env.REDWOOD_WEB_PORT ? parseInt(process.env.REDWOOD_WEB_PORT) : (0, import_project_config.getConfig)().web.port;
54
+ }
55
+ var import_project_config;
56
+ var init_cliHelpers = __esm({
57
+ "src/cliHelpers.ts"() {
58
+ "use strict";
59
+ import_project_config = require("@cedarjs/project-config");
60
+ }
61
+ });
62
+
63
+ // src/createServerHelpers.ts
64
+ function isCustomLoggerInstance(logger) {
65
+ return !!logger && typeof logger === "object" && "info" in logger;
66
+ }
67
+ function resolveOptions(options = {}, args) {
68
+ options.parseArgs ??= true;
69
+ const defaults = getDefaultCreateServerOptions();
70
+ const logger = options.logger ?? defaults.logger;
71
+ const resolvedOptions = {
72
+ apiRootPath: options.apiRootPath ?? defaults.apiRootPath,
73
+ fastifyServerOptions: options.fastifyServerOptions ?? {
74
+ requestTimeout: defaults.fastifyServerOptions.requestTimeout,
75
+ bodyLimit: defaults.fastifyServerOptions.bodyLimit
76
+ },
77
+ discoverFunctionsGlob: options.discoverFunctionsGlob ?? defaults.discoverFunctionsGlob,
78
+ configureApiServer: options.configureApiServer ?? defaults.configureApiServer,
79
+ apiHost: options.apiHost ?? defaults.apiHost,
80
+ apiPort: options.apiPort ?? defaults.apiPort
81
+ };
82
+ resolvedOptions.fastifyServerOptions.requestTimeout ??= defaults.fastifyServerOptions.requestTimeout;
83
+ if (isCustomLoggerInstance(logger)) {
84
+ resolvedOptions.fastifyServerOptions.loggerInstance = logger;
85
+ } else {
86
+ resolvedOptions.fastifyServerOptions.logger = logger;
87
+ }
88
+ if (options.parseArgs) {
89
+ const { values } = (0, import_util.parseArgs)({
90
+ options: {
91
+ apiHost: {
92
+ type: "string"
93
+ },
94
+ apiPort: {
95
+ type: "string",
96
+ short: "p"
97
+ },
98
+ apiRootPath: {
99
+ type: "string"
100
+ }
101
+ },
102
+ strict: false,
103
+ ...args && { args }
104
+ });
105
+ if (values.apiHost && typeof values.apiHost !== "string") {
106
+ throw new Error("`apiHost` must be a string");
107
+ }
108
+ if (values.apiHost) {
109
+ resolvedOptions.apiHost = values.apiHost;
110
+ }
111
+ if (values.apiPort) {
112
+ resolvedOptions.apiPort = +values.apiPort;
113
+ if (isNaN(resolvedOptions.apiPort)) {
114
+ throw new Error("`apiPort` must be an integer");
115
+ }
116
+ }
117
+ if (values.apiRootPath && typeof values.apiRootPath !== "string") {
118
+ throw new Error("`apiRootPath` must be a string");
119
+ }
120
+ if (values.apiRootPath) {
121
+ resolvedOptions.apiRootPath = values.apiRootPath;
122
+ }
123
+ }
124
+ resolvedOptions.apiRootPath = (0, import_helpers.coerceRootPath)(resolvedOptions.apiRootPath);
125
+ return resolvedOptions;
126
+ }
127
+ var import_util, import_helpers, getDefaultCreateServerOptions;
128
+ var init_createServerHelpers = __esm({
129
+ "src/createServerHelpers.ts"() {
130
+ "use strict";
131
+ import_util = require("util");
132
+ import_helpers = require("@cedarjs/fastify-web/dist/helpers.js");
133
+ init_cliHelpers();
134
+ getDefaultCreateServerOptions = () => ({
135
+ apiRootPath: getAPIRootPath(),
136
+ logger: {
137
+ level: process.env.LOG_LEVEL ?? (process.env.NODE_ENV === "development" ? "debug" : "warn")
138
+ },
139
+ fastifyServerOptions: {
140
+ requestTimeout: 15e3,
141
+ bodyLimit: 1024 * 1024 * 100
142
+ // 100MB
143
+ },
144
+ discoverFunctionsGlob: "dist/functions/**/*.{ts,js}",
145
+ configureApiServer: () => {
146
+ },
147
+ parseArgs: true,
148
+ apiHost: getAPIHost(),
149
+ apiPort: getAPIPort()
150
+ });
151
+ }
152
+ });
153
+
154
+ // src/fastify.ts
155
+ async function loadFastifyConfig() {
156
+ const serverConfigPath = import_path.default.join(
157
+ (0, import_project_config2.getPaths)().base,
158
+ (0, import_project_config2.getConfig)().api.serverConfig
159
+ );
160
+ if (!import_node_fs.default.existsSync(serverConfigPath)) {
161
+ return serverConfigFile;
162
+ }
163
+ if (loadedServerConfigPath !== serverConfigPath) {
164
+ isServerConfigLoaded = false;
165
+ }
166
+ if (!isServerConfigLoaded) {
167
+ console.log(`Loading server config from ${serverConfigPath}`);
168
+ console.log(`Loading server config from URL file://${serverConfigPath}`);
169
+ console.log(
170
+ `Loading server config from URL ${(0, import_url.pathToFileURL)(serverConfigPath).href}`
171
+ );
172
+ const config3 = await import((0, import_url.pathToFileURL)(serverConfigPath).href);
173
+ serverConfigFile = { ...config3.default };
174
+ loadedServerConfigPath = serverConfigPath;
175
+ isServerConfigLoaded = true;
176
+ }
177
+ return serverConfigFile;
178
+ }
179
+ var import_node_fs, import_path, import_url, import_fastify, import_store, import_project_config2, DEFAULT_OPTIONS, isServerConfigLoaded, loadedServerConfigPath, serverConfigFile, createFastifyInstance;
180
+ var init_fastify = __esm({
181
+ "src/fastify.ts"() {
182
+ "use strict";
183
+ import_node_fs = __toESM(require("node:fs"), 1);
184
+ import_path = __toESM(require("path"), 1);
185
+ import_url = require("url");
186
+ import_fastify = __toESM(require("fastify"), 1);
187
+ import_store = require("@cedarjs/context/dist/store");
188
+ import_project_config2 = require("@cedarjs/project-config");
189
+ DEFAULT_OPTIONS = {
190
+ logger: {
191
+ level: process.env.NODE_ENV === "development" ? "debug" : "info"
192
+ }
193
+ };
194
+ isServerConfigLoaded = false;
195
+ serverConfigFile = {
196
+ config: DEFAULT_OPTIONS,
197
+ configureFastify: async (fastify2, options) => {
198
+ fastify2.log.trace(
199
+ options,
200
+ `In configureFastify hook for side: ${options?.side}`
201
+ );
202
+ return fastify2;
203
+ }
204
+ };
205
+ createFastifyInstance = async (options) => {
206
+ const { config: config3 } = await loadFastifyConfig();
207
+ const fastify2 = (0, import_fastify.default)(options || config3 || DEFAULT_OPTIONS);
208
+ fastify2.addHook("onRequest", (_req, _reply, done) => {
209
+ (0, import_store.getAsyncStoreInstance)().run(/* @__PURE__ */ new Map(), done);
210
+ });
211
+ return fastify2;
212
+ };
213
+ }
214
+ });
215
+
216
+ // src/requestHandlers/utils.ts
217
+ var parseBody, mergeMultiValueHeaders;
218
+ var init_utils = __esm({
219
+ "src/requestHandlers/utils.ts"() {
220
+ "use strict";
221
+ parseBody = (rawBody) => {
222
+ if (typeof rawBody === "string") {
223
+ return { body: rawBody, isBase64Encoded: false };
224
+ }
225
+ if (rawBody instanceof Buffer) {
226
+ return { body: rawBody.toString("base64"), isBase64Encoded: true };
227
+ }
228
+ return { body: "", isBase64Encoded: false };
229
+ };
230
+ mergeMultiValueHeaders = (headers, multiValueHeaders) => {
231
+ const mergedHeaders = Object.entries(
232
+ headers || {}
233
+ ).reduce((acc, [name, value]) => {
234
+ acc[name.toLowerCase()] = [value];
235
+ return acc;
236
+ }, {});
237
+ Object.entries(multiValueHeaders || {}).forEach(([headerName, values]) => {
238
+ const name = headerName.toLowerCase();
239
+ if (name.toLowerCase() === "set-cookie") {
240
+ mergedHeaders["set-cookie"] = values;
241
+ } else {
242
+ mergedHeaders[name] = [values.join("; ")];
243
+ }
244
+ });
245
+ return mergedHeaders;
246
+ };
247
+ }
248
+ });
249
+
250
+ // src/requestHandlers/awsLambdaFastify.ts
251
+ var import_picoquery, lambdaEventForFastifyRequest, fastifyResponseForLambdaResult, fastifyResponseForLambdaError, requestHandler;
252
+ var init_awsLambdaFastify = __esm({
253
+ "src/requestHandlers/awsLambdaFastify.ts"() {
254
+ "use strict";
255
+ import_picoquery = require("picoquery");
256
+ init_utils();
257
+ lambdaEventForFastifyRequest = (request) => {
258
+ const qsParams = (0, import_picoquery.parse)(
259
+ request.url.split(/\?(.+)/)[1],
260
+ {
261
+ nestingSyntax: "index",
262
+ arrayRepeat: true,
263
+ arrayRepeatSyntax: "bracket"
264
+ }
265
+ );
266
+ return {
267
+ httpMethod: request.method,
268
+ headers: {
269
+ "x-forwarded-proto": request.protocol,
270
+ ...request.headers
271
+ },
272
+ path: request.urlData("path"),
273
+ queryStringParameters: qsParams,
274
+ requestContext: {
275
+ requestId: request.id,
276
+ identity: {
277
+ sourceIp: request.ip
278
+ },
279
+ domainName: request.hostname
280
+ },
281
+ ...parseBody(request.rawBody || "")
282
+ // adds `body` and `isBase64Encoded`
283
+ };
284
+ };
285
+ fastifyResponseForLambdaResult = (reply, lambdaResult) => {
286
+ const {
287
+ statusCode = 200,
288
+ headers,
289
+ body = "",
290
+ multiValueHeaders
291
+ } = lambdaResult;
292
+ const mergedHeaders = mergeMultiValueHeaders(headers, multiValueHeaders);
293
+ Object.entries(mergedHeaders).forEach(
294
+ ([name, values]) => values.forEach((value) => reply.header(name, value))
295
+ );
296
+ reply.status(statusCode);
297
+ if (lambdaResult.isBase64Encoded) {
298
+ return reply.send(Buffer.from(body, "base64"));
299
+ } else {
300
+ return reply.send(body);
301
+ }
302
+ };
303
+ fastifyResponseForLambdaError = (req, reply, error) => {
304
+ req.log.error(error);
305
+ reply.status(500).send();
306
+ };
307
+ requestHandler = async (req, reply, handler3) => {
308
+ const event = lambdaEventForFastifyRequest(req);
309
+ const handlerCallback = (reply2) => (error, lambdaResult) => {
310
+ if (error) {
311
+ fastifyResponseForLambdaError(req, reply2, error);
312
+ return;
313
+ }
314
+ fastifyResponseForLambdaResult(reply2, lambdaResult);
315
+ };
316
+ const handlerPromise = handler3(
317
+ event,
318
+ // @ts-expect-error - Add support for context: https://github.com/DefinitelyTyped/DefinitelyTyped/blob/0bb210867d16170c4a08d9ce5d132817651a0f80/types/aws-lambda/index.d.ts#L443-L467
319
+ {},
320
+ handlerCallback(reply)
321
+ );
322
+ if (handlerPromise && typeof handlerPromise.then === "function") {
323
+ try {
324
+ const lambdaResponse = await handlerPromise;
325
+ return fastifyResponseForLambdaResult(reply, lambdaResponse);
326
+ } catch (error) {
327
+ return fastifyResponseForLambdaError(req, reply, error);
328
+ }
329
+ }
330
+ };
331
+ }
332
+ });
333
+
334
+ // src/utils.ts
335
+ function escape(string) {
336
+ const htmlEscapes = {
337
+ "&": "&",
338
+ "<": "&lt;",
339
+ ">": "&gt;",
340
+ '"': "&quot;",
341
+ "'": "&#39;"
342
+ };
343
+ return string.replace(/[&<>"']/g, (char) => htmlEscapes[char]);
344
+ }
345
+ var init_utils2 = __esm({
346
+ "src/utils.ts"() {
347
+ "use strict";
348
+ }
349
+ });
350
+
351
+ // src/plugins/lambdaLoader.ts
352
+ var import_node_path, import_node_url, import_ansis, import_fast_glob, import_termi_link, import_runtime, import_project_config3, LAMBDA_FUNCTIONS, CEDAR_HANDLERS, cedarRouteManifest, setLambdaFunctions, loadFunctionsFromDist, findApiDistFunctions, lambdaRequestHandler;
353
+ var init_lambdaLoader = __esm({
354
+ "src/plugins/lambdaLoader.ts"() {
355
+ "use strict";
356
+ import_node_path = __toESM(require("node:path"), 1);
357
+ import_node_url = require("node:url");
358
+ import_ansis = __toESM(require("ansis"), 1);
359
+ import_fast_glob = __toESM(require("fast-glob"), 1);
360
+ import_termi_link = require("termi-link");
361
+ import_runtime = require("@cedarjs/api/runtime");
362
+ import_project_config3 = require("@cedarjs/project-config");
363
+ init_awsLambdaFastify();
364
+ init_utils2();
365
+ LAMBDA_FUNCTIONS = /* @__PURE__ */ new Map();
366
+ CEDAR_HANDLERS = /* @__PURE__ */ new Map();
367
+ cedarRouteManifest = [];
368
+ setLambdaFunctions = async (foundFunctions) => {
369
+ const tsImport = Date.now();
370
+ console.log(import_ansis.default.dim.italic("Importing Server Functions... "));
371
+ cedarRouteManifest.length = 0;
372
+ LAMBDA_FUNCTIONS.clear();
373
+ CEDAR_HANDLERS.clear();
374
+ const imports = foundFunctions.map(async (fnPath) => {
375
+ const ts = Date.now();
376
+ const routeName = import_node_path.default.basename(fnPath).replace(".js", "");
377
+ const routePath = `/${routeName}`;
378
+ const fnImport = await import((0, import_node_url.pathToFileURL)(fnPath).href);
379
+ const handler3 = (() => {
380
+ if ("handler" in fnImport) {
381
+ return fnImport.handler;
382
+ }
383
+ if ("default" in fnImport) {
384
+ if ("handler" in fnImport.default) {
385
+ return fnImport.default.handler;
386
+ }
387
+ }
388
+ return void 0;
389
+ })();
390
+ const cedarHandler = (() => {
391
+ if ("handleRequest" in fnImport && typeof fnImport.handleRequest === "function") {
392
+ return fnImport.handleRequest;
393
+ }
394
+ if ("default" in fnImport && fnImport.default && "handleRequest" in fnImport.default && typeof fnImport.default.handleRequest === "function") {
395
+ return fnImport.default.handleRequest;
396
+ }
397
+ return void 0;
398
+ })();
399
+ if (handler3) {
400
+ LAMBDA_FUNCTIONS.set(routeName, handler3);
401
+ }
402
+ if (cedarHandler) {
403
+ CEDAR_HANDLERS.set(routeName, cedarHandler);
404
+ } else if (handler3) {
405
+ CEDAR_HANDLERS.set(routeName, (0, import_runtime.wrapLegacyHandler)(handler3));
406
+ }
407
+ if (!handler3 && !cedarHandler) {
408
+ console.warn(
409
+ routeName,
410
+ "at",
411
+ fnPath,
412
+ "does not have a function called handler or handleRequest defined."
413
+ );
414
+ }
415
+ cedarRouteManifest.push({
416
+ id: routePath,
417
+ path: routePath,
418
+ methods: routeName === "graphql" ? ["GET", "POST", "OPTIONS"] : [],
419
+ type: routeName === "graphql" ? "graphql" : routeName === "health" ? "health" : routeName.toLowerCase().includes("auth") ? "auth" : "function",
420
+ entry: fnPath
421
+ });
422
+ console.log(
423
+ (0, import_termi_link.terminalLink)(import_ansis.default.magenta("/" + routeName), (0, import_node_url.pathToFileURL)(fnPath).href),
424
+ import_ansis.default.dim.italic(Date.now() - ts + " ms")
425
+ );
426
+ });
427
+ await Promise.all(imports);
428
+ console.log(
429
+ import_ansis.default.dim.italic("...Done importing in " + (Date.now() - tsImport) + " ms")
430
+ );
431
+ };
432
+ loadFunctionsFromDist = async (options = {}) => {
433
+ const serverFunctions = findApiDistFunctions({
434
+ cwd: (0, import_project_config3.getPaths)().api.base,
435
+ options: options?.fastGlobOptions,
436
+ discoverFunctionsGlob: options?.discoverFunctionsGlob
437
+ });
438
+ const i = serverFunctions.findIndex((x) => import_node_path.default.basename(x) === "graphql.js");
439
+ if (i >= 0) {
440
+ const graphQLFn = serverFunctions.splice(i, 1)[0];
441
+ serverFunctions.unshift(graphQLFn);
442
+ }
443
+ await setLambdaFunctions(serverFunctions);
444
+ };
445
+ findApiDistFunctions = (params) => {
446
+ const {
447
+ cwd = (0, import_project_config3.getPaths)().api.base,
448
+ options = {},
449
+ discoverFunctionsGlob = "dist/functions/**/*.{ts,js}"
450
+ } = params;
451
+ return import_fast_glob.default.sync(discoverFunctionsGlob, {
452
+ cwd,
453
+ // We don't support deeply nested api functions, to maximise compatibility
454
+ // with deployment providers
455
+ deep: 2,
456
+ absolute: true,
457
+ ...options
458
+ });
459
+ };
460
+ lambdaRequestHandler = async (req, reply) => {
461
+ const { routeName } = req.params;
462
+ const cedarHandlerCandidate = CEDAR_HANDLERS.get(routeName);
463
+ const cedarHandler = typeof cedarHandlerCandidate === "function" ? cedarHandlerCandidate : void 0;
464
+ if (cedarHandler) {
465
+ const requestBody = req.method === "GET" || req.method === "HEAD" ? void 0 : typeof req.rawBody === "string" ? req.rawBody : req.rawBody ? Buffer.from(req.rawBody).toString() : void 0;
466
+ const href = `${req.protocol}://${req.hostname}${req.raw.url ?? "/"}`;
467
+ const request = new Request(href, {
468
+ method: req.method,
469
+ headers: req.headers,
470
+ body: requestBody
471
+ });
472
+ const ctx = await (0, import_runtime.buildCedarContext)(request, {
473
+ params: {
474
+ routeName
475
+ }
476
+ });
477
+ const response = await cedarHandler(request, ctx);
478
+ reply.status(response.status);
479
+ response.headers.forEach((value, name) => {
480
+ reply.header(name, value);
481
+ });
482
+ const body = await response.arrayBuffer();
483
+ reply.send(Buffer.from(body));
484
+ return;
485
+ }
486
+ const handler3 = LAMBDA_FUNCTIONS.get(routeName);
487
+ if (handler3) {
488
+ return requestHandler(req, reply, handler3);
489
+ } else {
490
+ const errorMessage = `Function "${routeName}" was not found.`;
491
+ req.log.error(errorMessage);
492
+ reply.status(404);
493
+ if (process.env.NODE_ENV === "development") {
494
+ const devError = {
495
+ error: errorMessage,
496
+ availableFunctions: [
497
+ .../* @__PURE__ */ new Set([...LAMBDA_FUNCTIONS.keys(), ...CEDAR_HANDLERS.keys()])
498
+ ]
499
+ };
500
+ reply.send(devError);
501
+ } else {
502
+ reply.send(escape(errorMessage));
503
+ }
504
+ return;
505
+ }
506
+ };
507
+ }
508
+ });
509
+
510
+ // src/plugins/api.ts
511
+ async function cedarFastifyAPI(fastify2, opts) {
512
+ const cedarOptions = opts.redwood ?? {};
513
+ cedarOptions.apiRootPath ??= "/";
514
+ cedarOptions.apiRootPath = (0, import_helpers2.coerceRootPath)(cedarOptions.apiRootPath);
515
+ cedarOptions.fastGlobOptions ??= {};
516
+ cedarOptions.loadUserConfig ??= false;
517
+ fastify2.register(import_url_data.default);
518
+ await fastify2.register(import_fastify_raw_body.default);
519
+ fastify2.addHook("onRequest", (_req, _reply, done) => {
520
+ (0, import_store2.getAsyncStoreInstance)().run(/* @__PURE__ */ new Map(), done);
521
+ });
522
+ fastify2.addContentTypeParser(
523
+ ["application/x-www-form-urlencoded", "multipart/form-data"],
524
+ { parseAs: "string" },
525
+ fastify2.defaultTextParser
526
+ );
527
+ if (cedarOptions.loadUserConfig) {
528
+ const { configureFastify } = await loadFastifyConfig();
529
+ if (configureFastify) {
530
+ await configureFastify(fastify2, {
531
+ side: "api",
532
+ apiRootPath: cedarOptions.apiRootPath
533
+ });
534
+ }
535
+ }
536
+ if (cedarOptions.configureServer) {
537
+ await cedarOptions.configureServer(fastify2);
538
+ }
539
+ fastify2.all(`${cedarOptions.apiRootPath}:routeName`, lambdaRequestHandler);
540
+ fastify2.all(`${cedarOptions.apiRootPath}:routeName/*`, lambdaRequestHandler);
541
+ await loadFunctionsFromDist({
542
+ fastGlobOptions: cedarOptions.fastGlobOptions,
543
+ discoverFunctionsGlob: cedarOptions.discoverFunctionsGlob
544
+ });
545
+ }
546
+ var import_url_data, import_fastify_raw_body, import_store2, import_helpers2;
547
+ var init_api = __esm({
548
+ "src/plugins/api.ts"() {
549
+ "use strict";
550
+ import_url_data = __toESM(require("@fastify/url-data"), 1);
551
+ import_fastify_raw_body = __toESM(require("fastify-raw-body"), 1);
552
+ import_store2 = require("@cedarjs/context/dist/store");
553
+ import_helpers2 = require("@cedarjs/fastify-web/dist/helpers.js");
554
+ init_fastify();
555
+ init_lambdaLoader();
556
+ }
557
+ });
558
+
559
+ // src/plugins/graphql.ts
560
+ var graphql_exports = {};
561
+ __export(graphql_exports, {
562
+ redwoodFastifyGraphQLServer: () => redwoodFastifyGraphQLServer
563
+ });
564
+ async function redwoodFastifyGraphQLServer(fastify2, options) {
565
+ const redwoodOptions = options.redwood ?? {};
566
+ redwoodOptions.apiRootPath ??= "/";
567
+ redwoodOptions.apiRootPath = (0, import_helpers3.coerceRootPath)(redwoodOptions.apiRootPath);
568
+ fastify2.register(import_url_data2.default);
569
+ fastify2.register(import_multipart.default);
570
+ const method = ["GET", "POST", "OPTIONS"];
571
+ fastify2.addHook("onRequest", (_req, _reply, done) => {
572
+ (0, import_store3.getAsyncStoreInstance)().run(/* @__PURE__ */ new Map(), done);
573
+ });
574
+ try {
575
+ if (!redwoodOptions.graphql) {
576
+ const [graphqlFunctionPath] = await (0, import_fast_glob2.default)("dist/functions/graphql.{ts,js}", {
577
+ cwd: (0, import_project_config4.getPaths)().api.base,
578
+ absolute: true
579
+ });
580
+ const filePath = (0, import_node_url2.pathToFileURL)(graphqlFunctionPath).href;
581
+ const { __cedar_graphqlOptions } = await import(filePath);
582
+ if (!__cedar_graphqlOptions) {
583
+ return;
584
+ }
585
+ redwoodOptions.graphql = __cedar_graphqlOptions;
586
+ }
587
+ const graphqlOptions = redwoodOptions.graphql;
588
+ if (graphqlOptions?.realtime?.subscriptions) {
589
+ method.push("PUT");
590
+ }
591
+ const { yoga } = await (0, import_graphql_server.createGraphQLYoga)(graphqlOptions);
592
+ const graphqlEndpoint = trimSlashes(yoga.graphqlEndpoint);
593
+ const routePaths = ["", "/health", "/readiness", "/stream"];
594
+ for (const routePath of routePaths) {
595
+ fastify2.route({
596
+ url: `${redwoodOptions.apiRootPath}${graphqlEndpoint}${routePath}`,
597
+ method,
598
+ handler: async (req, reply) => {
599
+ const request = createFetchRequest(req, reply);
600
+ const cedarContext = await (0, import_runtime2.buildCedarContext)(request, {
601
+ authDecoder: graphqlOptions.authDecoder ?? import_runtime2.noopAuthDecoder
602
+ });
603
+ try {
604
+ return await yoga.handle(request, {
605
+ request,
606
+ cedarContext,
607
+ event: lambdaEventForFastifyRequest(req),
608
+ requestContext: void 0
609
+ });
610
+ } catch (e) {
611
+ if (!!e && typeof e === "object" && "code" in e && e.code === "ERR_STREAM_PREMATURE_CLOSE") {
612
+ return new Response(null, { status: 499 });
613
+ }
614
+ throw e;
615
+ }
616
+ }
617
+ });
618
+ }
619
+ fastify2.addHook("onReady", (done) => {
620
+ console.info(`GraphQL Yoga Server endpoint at ${graphqlEndpoint}`);
621
+ console.info(
622
+ `GraphQL Yoga Server Health Check endpoint at ${graphqlEndpoint}/health`
623
+ );
624
+ console.info(
625
+ `GraphQL Yoga Server Readiness endpoint at ${graphqlEndpoint}/readiness`
626
+ );
627
+ done();
628
+ });
629
+ } catch (e) {
630
+ console.log(e);
631
+ }
632
+ }
633
+ function trimSlashes(path5) {
634
+ return path5.replace(/^\/|\/$/g, "");
635
+ }
636
+ function createFetchRequest(req, reply) {
637
+ const controller = new AbortController();
638
+ reply.raw.on("close", () => {
639
+ if (!reply.raw.writableFinished) {
640
+ controller.abort();
641
+ }
642
+ });
643
+ const requestBody = req.method === "GET" || req.method === "HEAD" ? void 0 : typeof req.body === "string" ? req.body : req.body ? JSON.stringify(req.body) : void 0;
644
+ const href = `${req.protocol}://${req.hostname}${req.raw.url ?? "/"}`;
645
+ return new Request(href, {
646
+ method: req.method,
647
+ headers: req.headers,
648
+ body: requestBody,
649
+ signal: controller.signal
650
+ });
651
+ }
652
+ var import_node_url2, import_multipart, import_url_data2, import_fast_glob2, import_runtime2, import_store3, import_helpers3, import_graphql_server, import_project_config4;
653
+ var init_graphql = __esm({
654
+ "src/plugins/graphql.ts"() {
655
+ "use strict";
656
+ import_node_url2 = require("node:url");
657
+ import_multipart = __toESM(require("@fastify/multipart"), 1);
658
+ import_url_data2 = __toESM(require("@fastify/url-data"), 1);
659
+ import_fast_glob2 = __toESM(require("fast-glob"), 1);
660
+ import_runtime2 = require("@cedarjs/api/runtime");
661
+ import_store3 = require("@cedarjs/context/dist/store");
662
+ import_helpers3 = require("@cedarjs/fastify-web/dist/helpers.js");
663
+ import_graphql_server = require("@cedarjs/graphql-server");
664
+ import_project_config4 = require("@cedarjs/project-config");
665
+ init_awsLambdaFastify();
666
+ }
667
+ });
668
+
669
+ // src/createServer.ts
670
+ async function createServer(options = {}) {
671
+ const {
672
+ apiRootPath,
673
+ fastifyServerOptions,
674
+ discoverFunctionsGlob,
675
+ configureApiServer,
676
+ apiPort,
677
+ apiHost
678
+ } = resolveOptions(options);
679
+ const serverConfigPath = import_node_path2.default.join(
680
+ (0, import_project_config5.getPaths)().base,
681
+ (0, import_project_config5.getConfig)().api.serverConfig
682
+ );
683
+ if (import_node_fs2.default.existsSync(serverConfigPath)) {
684
+ console.warn(
685
+ import_ansis2.default.yellow(
686
+ [
687
+ "",
688
+ `Ignoring \`config\` and \`configureServer\` in api/server.config.js.`,
689
+ `Migrate them to api/src/server.{ts,js}:`,
690
+ "",
691
+ `\`\`\`js title="api/src/server.{ts,js}"`,
692
+ "// Pass your config to `createServer`",
693
+ "const server = createServer({",
694
+ " fastifyServerOptions: myFastifyConfig",
695
+ "})",
696
+ "",
697
+ "// Then inline your `configureFastify` logic:",
698
+ "server.register(myFastifyPlugin)",
699
+ "```",
700
+ ""
701
+ ].join("\n")
702
+ )
703
+ );
704
+ }
705
+ const server = Object.assign((0, import_fastify3.default)(fastifyServerOptions), {
706
+ // `start` will get replaced further down in this file
707
+ start: async () => {
708
+ throw new Error("Not implemented yet");
709
+ }
710
+ });
711
+ server.addHook("onRequest", (_req, _reply, done) => {
712
+ (0, import_store4.getAsyncStoreInstance)().run(/* @__PURE__ */ new Map(), done);
713
+ });
714
+ await server.register(cedarFastifyAPI, {
715
+ redwood: {
716
+ apiRootPath,
717
+ fastGlobOptions: {
718
+ ignore: ["**/dist/functions/graphql.js"]
719
+ },
720
+ discoverFunctionsGlob,
721
+ configureServer: configureApiServer
722
+ }
723
+ });
724
+ const [graphqlFunctionPath] = await (0, import_fast_glob3.default)("dist/functions/graphql.{ts,js}", {
725
+ cwd: (0, import_project_config5.getPaths)().api.base,
726
+ absolute: true
727
+ });
728
+ if (graphqlFunctionPath) {
729
+ const { redwoodFastifyGraphQLServer: redwoodFastifyGraphQLServer2 } = await Promise.resolve().then(() => (init_graphql(), graphql_exports));
730
+ const { __cedar_graphqlOptions } = await import((0, import_node_url3.pathToFileURL)(graphqlFunctionPath).href);
731
+ await server.register(redwoodFastifyGraphQLServer2, {
732
+ redwood: {
733
+ apiRootPath,
734
+ graphql: __cedar_graphqlOptions
735
+ }
736
+ });
737
+ }
738
+ server.addHook("onReady", (done) => {
739
+ process.send?.("ready");
740
+ done();
741
+ });
742
+ server.addHook("onListen", (done) => {
743
+ console.log(
744
+ `Server listening at ${import_ansis2.default.magenta(
745
+ `${server.listeningOrigin}${apiRootPath}`
746
+ )}`
747
+ );
748
+ done();
749
+ });
750
+ server.start = (options2 = {}) => {
751
+ return server.listen({
752
+ ...options2,
753
+ port: apiPort,
754
+ host: apiHost
755
+ });
756
+ };
757
+ return server;
758
+ }
759
+ var import_node_fs2, import_node_path2, import_node_url3, import_ansis2, import_dotenv_defaults, import_fast_glob3, import_fastify3, import_store4, import_project_config5;
760
+ var init_createServer = __esm({
761
+ "src/createServer.ts"() {
762
+ "use strict";
763
+ import_node_fs2 = __toESM(require("node:fs"), 1);
764
+ import_node_path2 = __toESM(require("node:path"), 1);
765
+ import_node_url3 = require("node:url");
766
+ import_ansis2 = __toESM(require("ansis"), 1);
767
+ import_dotenv_defaults = require("dotenv-defaults");
768
+ import_fast_glob3 = __toESM(require("fast-glob"), 1);
769
+ import_fastify3 = __toESM(require("fastify"), 1);
770
+ import_store4 = require("@cedarjs/context/dist/store");
771
+ import_project_config5 = require("@cedarjs/project-config");
772
+ init_createServerHelpers();
773
+ init_api();
774
+ if (!process.env.CEDAR_ENV_FILES_LOADED) {
775
+ (0, import_dotenv_defaults.config)({
776
+ path: import_node_path2.default.join((0, import_project_config5.getPaths)().base, ".env"),
777
+ defaults: import_node_path2.default.join((0, import_project_config5.getPaths)().base, ".env.defaults"),
778
+ multiline: true
779
+ });
780
+ process.env.CEDAR_ENV_FILES_LOADED = "true";
781
+ }
782
+ }
783
+ });
784
+
785
+ // src/apiCLIConfigHandler.ts
786
+ async function handler(options = {}) {
787
+ const timeStart = Date.now();
788
+ console.log(import_ansis3.default.dim.italic("Starting API Server..."));
789
+ options.apiRootPath = (0, import_fastify_web.coerceRootPath)(options.apiRootPath ?? "/");
790
+ const fastify2 = await createServer({
791
+ apiRootPath: options.apiRootPath,
792
+ apiHost: options.host,
793
+ apiPort: options.port
794
+ });
795
+ await fastify2.start();
796
+ fastify2.log.trace(
797
+ { custom: { ...fastify2.initialConfig } },
798
+ "Fastify server configuration"
799
+ );
800
+ fastify2.log.trace(`Registered plugins
801
+ ${fastify2.printPlugins()}`);
802
+ console.log(import_ansis3.default.dim.italic("Took " + (Date.now() - timeStart) + " ms"));
803
+ let address = fastify2.listeningOrigin;
804
+ if (process.env.NODE_ENV !== "production") {
805
+ address = address.replace(/http:\/\/\[::\]/, "http://localhost");
806
+ }
807
+ const apiServer = import_ansis3.default.magenta(`${address}${options.apiRootPath}`);
808
+ const graphqlEndpoint = import_ansis3.default.magenta(`${apiServer}graphql`);
809
+ console.log(`API server listening at ${apiServer}`);
810
+ console.log(`GraphQL endpoint at ${graphqlEndpoint}`);
811
+ process?.send?.("ready");
812
+ }
813
+ var import_ansis3, import_fastify_web;
814
+ var init_apiCLIConfigHandler = __esm({
815
+ "src/apiCLIConfigHandler.ts"() {
816
+ "use strict";
817
+ import_ansis3 = __toESM(require("ansis"), 1);
818
+ import_fastify_web = require("@cedarjs/fastify-web");
819
+ init_createServer();
820
+ }
821
+ });
822
+
823
+ // src/bothCLIConfigHandler.ts
824
+ async function handler2(options) {
825
+ const timeStart = Date.now();
826
+ console.log(import_ansis4.default.dim.italic("Starting API and Web Servers..."));
827
+ options.webHost ??= getWebHost();
828
+ options.webPort ??= getWebPort();
829
+ options.apiHost ??= getAPIHost();
830
+ options.apiPort ??= getAPIPort();
831
+ options.apiRootPath = (0, import_fastify_web2.coerceRootPath)(options.apiRootPath ?? "/");
832
+ const apiProxyTarget = [
833
+ "http://",
834
+ options.apiHost.includes(":") ? `[${options.apiHost}]` : options.apiHost,
835
+ ":",
836
+ options.apiPort,
837
+ options.apiRootPath
838
+ ].join("");
839
+ const webFastify = await createFastifyInstance();
840
+ webFastify.register(import_fastify_web2.redwoodFastifyWeb, {
841
+ redwood: {
842
+ apiProxyTarget
843
+ }
844
+ });
845
+ const apiFastify = await createServer({
846
+ apiRootPath: options.apiRootPath
847
+ });
848
+ await webFastify.listen({
849
+ port: options.webPort,
850
+ host: options.webHost,
851
+ listenTextResolver: getListenTextResolver("Web")
852
+ });
853
+ webFastify.log.trace(
854
+ { custom: { ...webFastify.initialConfig } },
855
+ "Fastify server configuration"
856
+ );
857
+ webFastify.log.trace(`Registered plugins
858
+ ${webFastify.printPlugins()}`);
859
+ await apiFastify.listen({
860
+ port: options.apiPort,
861
+ host: options.apiHost,
862
+ listenTextResolver: getListenTextResolver("API")
863
+ });
864
+ apiFastify.log.trace(
865
+ { custom: { ...apiFastify.initialConfig } },
866
+ "Fastify server configuration"
867
+ );
868
+ apiFastify.log.trace(`Registered plugins
869
+ ${apiFastify.printPlugins()}`);
870
+ console.log(import_ansis4.default.dim.italic("Took " + (Date.now() - timeStart) + " ms"));
871
+ const webServer = import_ansis4.default.green(webFastify.listeningOrigin);
872
+ const apiServer = import_ansis4.default.magenta(
873
+ `${apiFastify.listeningOrigin}${options.apiRootPath}`
874
+ );
875
+ const graphqlEndpoint = import_ansis4.default.magenta(`${apiServer}graphql`);
876
+ console.log(`Web server listening at ${webServer}`);
877
+ console.log(`API server listening at ${apiServer}`);
878
+ console.log(`GraphQL endpoint at ${graphqlEndpoint}`);
879
+ process?.send?.("ready");
880
+ }
881
+ function getListenTextResolver(side) {
882
+ return (address) => {
883
+ if (process.env.NODE_ENV !== "production") {
884
+ address = address.replace(/http:\/\/\[::\]/, "http://localhost");
885
+ }
886
+ return `${side} server listening at ${address}`;
887
+ };
888
+ }
889
+ var import_ansis4, import_fastify_web2;
890
+ var init_bothCLIConfigHandler = __esm({
891
+ "src/bothCLIConfigHandler.ts"() {
892
+ "use strict";
893
+ import_ansis4 = __toESM(require("ansis"), 1);
894
+ import_fastify_web2 = require("@cedarjs/fastify-web");
895
+ init_cliHelpers();
896
+ init_createServer();
897
+ init_fastify();
898
+ }
899
+ });
900
+
901
+ // src/bin.ts
902
+ var import_path2 = __toESM(require("path"), 1);
903
+ var import_dotenv_defaults2 = require("dotenv-defaults");
904
+ var import_helpers4 = require("yargs/helpers");
905
+ var import_yargs = __toESM(require("yargs/yargs"), 1);
906
+ var import_project_config6 = require("@cedarjs/project-config");
907
+ var import_web_server = require("@cedarjs/web-server");
908
+
909
+ // src/apiCLIConfig.ts
910
+ var description = "Start a server for serving the api side";
911
+ function builder(yargs2) {
912
+ yargs2.options({
913
+ port: {
914
+ description: "The port to listen at",
915
+ type: "number",
916
+ alias: "p"
917
+ },
918
+ host: {
919
+ description: "The host to listen at. Note that you most likely want this to be '0.0.0.0' in production",
920
+ type: "string"
921
+ },
922
+ apiRootPath: {
923
+ description: "Root path where your api functions are served",
924
+ type: "string",
925
+ alias: ["api-root-path", "rootPath", "root-path"],
926
+ default: "/"
927
+ },
928
+ // This became a no-op in v7 because env files weren't loaded by default
929
+ // but removing it would break yargs parsing for older projects,
930
+ // so leaving it here so that yargs doesn't throw an error
931
+ loadEnvFiles: {
932
+ hidden: true
933
+ }
934
+ });
935
+ }
936
+
937
+ // src/bin.ts
938
+ init_apiCLIConfigHandler();
939
+
940
+ // src/bothCLIConfig.ts
941
+ var description2 = "Start a server for serving the api and web sides";
942
+ function builder2(yargs2) {
943
+ yargs2.options({
944
+ webPort: {
945
+ description: "The port for the web server to listen on",
946
+ type: "number",
947
+ alias: ["web-port"]
948
+ },
949
+ webHost: {
950
+ 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",
951
+ type: "string",
952
+ alias: ["web-host"]
953
+ },
954
+ apiPort: {
955
+ description: "The port for the api server to listen on",
956
+ type: "number",
957
+ alias: ["api-port"]
958
+ },
959
+ apiHost: {
960
+ 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",
961
+ type: "string",
962
+ alias: ["api-host"]
963
+ },
964
+ apiRootPath: {
965
+ description: "Root path where your api functions are served",
966
+ type: "string",
967
+ alias: ["api-root-path", "rootPath", "root-path"],
968
+ default: "/"
969
+ }
970
+ });
971
+ }
972
+
973
+ // src/bin.ts
974
+ init_bothCLIConfigHandler();
975
+ if (!process.env.CEDAR_ENV_FILES_LOADED) {
976
+ (0, import_dotenv_defaults2.config)({
977
+ path: import_path2.default.join((0, import_project_config6.getPaths)().base, ".env"),
978
+ defaults: import_path2.default.join((0, import_project_config6.getPaths)().base, ".env.defaults"),
979
+ multiline: true
980
+ });
981
+ process.env.CEDAR_ENV_FILES_LOADED = "true";
982
+ }
983
+ process.env.NODE_ENV ??= "production";
984
+ (0, import_yargs.default)((0, import_helpers4.hideBin)(process.argv)).scriptName("cedar-server").strict().alias("h", "help").alias("v", "version").command(
985
+ "$0",
986
+ description2,
987
+ // @ts-expect-error The yargs types seem wrong; it's ok for builder to be a function
988
+ builder2,
989
+ handler2
990
+ ).command(
991
+ "api",
992
+ description,
993
+ // @ts-expect-error The yargs types seem wrong; it's ok for builder to be a function
994
+ builder,
995
+ handler
996
+ ).command(
997
+ "web",
998
+ import_web_server.description,
999
+ // @ts-expect-error The yargs types seem wrong; it's ok for builder to be a function
1000
+ import_web_server.builder,
1001
+ import_web_server.handler
1002
+ ).parse();