@cedarjs/api-server 5.0.7-next.338 → 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
package/README.md CHANGED
@@ -16,6 +16,7 @@ From package.json
16
16
 
17
17
  ```
18
18
  "bin": {
19
+ "cedarjs-api-server-watch": "./dist/watch.js",
19
20
  "cedarjs-log-formatter": "./dist/logFormatter/bin.js",
20
21
  "cedarjs-server": "./dist/bin.js",
21
22
  },
@@ -1 +1 @@
1
- {"version":3,"file":"apiCLIConfig.d.ts","sourceRoot":"","sources":["../src/apiCLIConfig.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,OAAO,CAAA;AAEjC,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,YAAY,CAAA;AAElD,eAAO,MAAM,WAAW,4CAA4C,CAAA;AAEpE,wBAAgB,OAAO,CAAC,KAAK,EAAE,IAAI,CAAC,gBAAgB,CAAC,QAwBpD;AAED,wBAAsB,OAAO,CAAC,OAAO,EAAE,gBAAgB,iBAGtD"}
1
+ {"version":3,"file":"apiCLIConfig.d.ts","sourceRoot":"","sources":["../src/apiCLIConfig.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,OAAO,CAAA;AAEjC,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,YAAY,CAAA;AAElD,eAAO,MAAM,WAAW,4CAA4C,CAAA;AAEpE,wBAAgB,OAAO,CAAC,KAAK,EAAE,IAAI,CAAC,gBAAgB,CAAC,QA0BpD;AAED,wBAAsB,OAAO,CAAC,OAAO,EAAE,gBAAgB,iBAGtD"}
@@ -7,7 +7,7 @@ function builder(yargs) {
7
7
  alias: "p"
8
8
  },
9
9
  host: {
10
- description: "The host to listen at",
10
+ description: "The host to listen at. Note that you most likely want this to be '0.0.0.0' in production",
11
11
  type: "string"
12
12
  },
13
13
  apiRootPath: {
@@ -1 +1 @@
1
- {"version":3,"file":"apiCLIConfigHandler.d.ts","sourceRoot":"","sources":["../src/apiCLIConfigHandler.ts"],"names":[],"mappings":"AAMA,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,YAAY,CAAA;AAElD,wBAAsB,OAAO,CAAC,OAAO,GAAE,gBAAqB,iBA4C3D"}
1
+ {"version":3,"file":"apiCLIConfigHandler.d.ts","sourceRoot":"","sources":["../src/apiCLIConfigHandler.ts"],"names":[],"mappings":"AAQA,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,YAAY,CAAA;AAElD,wBAAsB,OAAO,CAAC,OAAO,GAAE,gBAAqB,iBAoC3D"}
@@ -1,12 +1,7 @@
1
1
  import ansis from "ansis";
2
2
  import { coerceRootPath } from "@cedarjs/fastify-web";
3
3
  import { createServer } from "./createServer.js";
4
- import { apiDistServerFileExists, runApiDistServerFile } from "./serverFile.js";
5
4
  async function handler(options = {}) {
6
- if (apiDistServerFileExists()) {
7
- await runApiDistServerFile(options);
8
- return;
9
- }
10
5
  const timeStart = Date.now();
11
6
  console.log(ansis.dim.italic("Starting API Server..."));
12
7
  options.apiRootPath = coerceRootPath(options.apiRootPath ?? "/");
package/dist/bin.js CHANGED
@@ -1,13 +1,8 @@
1
1
  #!/usr/bin/env node
2
2
  var __defProp = Object.defineProperty;
3
3
  var __getOwnPropNames = Object.getOwnPropertyNames;
4
- var __esm = (fn, res, err) => function __init() {
5
- if (err) throw err[0];
6
- try {
7
- return fn && (res = (0, fn[__getOwnPropNames(fn)[0]])(fn = 0)), res;
8
- } catch (e) {
9
- throw err = [e], e;
10
- }
4
+ var __esm = (fn, res) => function __init() {
5
+ return fn && (res = (0, fn[__getOwnPropNames(fn)[0]])(fn = 0)), res;
11
6
  };
12
7
  var __export = (target, all) => {
13
8
  for (var name in all)
@@ -15,55 +10,27 @@ var __export = (target, all) => {
15
10
  };
16
11
 
17
12
  // src/cliHelpers.ts
18
- import { getConfig, parsePort, readEnvVar } from "@cedarjs/project-config";
19
- function getAPIHost({ isPublicSide = false } = {}) {
20
- let host = readEnvVar("CEDAR_API_HOST", {
21
- deprecatedAlias: "REDWOOD_API_HOST"
22
- });
23
- if (isPublicSide) {
24
- host ??= process.env.HOST;
25
- }
13
+ import { getConfig } from "@cedarjs/project-config";
14
+ function getAPIHost() {
15
+ let host = process.env.REDWOOD_API_HOST;
26
16
  host ??= getConfig().api.host;
27
- host ??= "::";
17
+ host ??= process.env.NODE_ENV === "production" ? "0.0.0.0" : "::";
28
18
  return host;
29
19
  }
30
- function getAPIPort({ isPublicSide = false } = {}) {
31
- const apiPort = readEnvVar("CEDAR_API_PORT", {
32
- deprecatedAlias: "REDWOOD_API_PORT"
33
- });
34
- if (apiPort) {
35
- return parsePort(apiPort, "CEDAR_API_PORT");
36
- }
37
- if (isPublicSide && process.env.PORT) {
38
- return parsePort(process.env.PORT, "PORT");
39
- }
40
- return getConfig().api.port;
20
+ function getAPIPort() {
21
+ return process.env.REDWOOD_API_PORT ? parseInt(process.env.REDWOOD_API_PORT) : getConfig().api.port;
41
22
  }
42
23
  function getAPIRootPath() {
43
24
  return process.env.CEDAR_API_ROOT_PATH ?? "/";
44
25
  }
45
- function getWebHost({ isPublicSide = false } = {}) {
46
- let host = readEnvVar("CEDAR_WEB_HOST", {
47
- deprecatedAlias: "REDWOOD_WEB_HOST"
48
- });
49
- if (isPublicSide) {
50
- host ??= process.env.HOST;
51
- }
26
+ function getWebHost() {
27
+ let host = process.env.REDWOOD_WEB_HOST;
52
28
  host ??= getConfig().web.host;
53
- host ??= "::";
29
+ host ??= process.env.NODE_ENV === "production" ? "0.0.0.0" : "::";
54
30
  return host;
55
31
  }
56
- function getWebPort({ isPublicSide = false } = {}) {
57
- const webPort = readEnvVar("CEDAR_WEB_PORT", {
58
- deprecatedAlias: "REDWOOD_WEB_PORT"
59
- });
60
- if (webPort) {
61
- return parsePort(webPort, "CEDAR_WEB_PORT");
62
- }
63
- if (isPublicSide && process.env.PORT) {
64
- return parsePort(process.env.PORT, "PORT");
65
- }
66
- return getConfig().web.port;
32
+ function getWebPort() {
33
+ return process.env.REDWOOD_WEB_PORT ? parseInt(process.env.REDWOOD_WEB_PORT) : getConfig().web.port;
67
34
  }
68
35
  var init_cliHelpers = __esm({
69
36
  "src/cliHelpers.ts"() {
@@ -88,9 +55,7 @@ function resolveOptions(options = {}, args) {
88
55
  bodyLimit: defaults.fastifyServerOptions.bodyLimit
89
56
  },
90
57
  discoverFunctionsGlob: options.discoverFunctionsGlob ?? defaults.discoverFunctionsGlob,
91
- configureServer: options.configureServer ?? defaults.configureServer,
92
58
  configureApiServer: options.configureApiServer ?? defaults.configureApiServer,
93
- configureGraphQLServer: options.configureGraphQLServer ?? defaults.configureGraphQLServer,
94
59
  apiHost: options.apiHost ?? defaults.apiHost,
95
60
  apiPort: options.apiPort ?? defaults.apiPort
96
61
  };
@@ -155,19 +120,11 @@ var init_createServerHelpers = __esm({
155
120
  // 100MB
156
121
  },
157
122
  discoverFunctionsGlob: "dist/functions/**/*.{ts,js}",
158
- configureServer: () => {
159
- },
160
123
  configureApiServer: () => {
161
124
  },
162
- configureGraphQLServer: () => {
163
- },
164
125
  parseArgs: true,
165
- // `createServer()`'s only callers are `cedarjs-server api` and custom
166
- // `api/src/server.ts` files — both only ever run with the api side
167
- // serving public traffic on its own, so they get to use the host's
168
- // `HOST`/`PORT` env vars.
169
- apiHost: getAPIHost({ isPublicSide: true }),
170
- apiPort: getAPIPort({ isPublicSide: true })
126
+ apiHost: getAPIHost(),
127
+ apiPort: getAPIPort()
171
128
  });
172
129
  }
173
130
  });
@@ -534,7 +491,7 @@ import fastifyRawBody from "fastify-raw-body";
534
491
  import { getAsyncStoreInstance as getAsyncStoreInstance2 } from "@cedarjs/context/dist/store";
535
492
  import { coerceRootPath as coerceRootPath2 } from "@cedarjs/fastify-web/dist/helpers.js";
536
493
  async function cedarFastifyAPI(fastify2, opts) {
537
- const cedarOptions = opts.cedar ?? {};
494
+ const cedarOptions = opts.redwood ?? {};
538
495
  cedarOptions.apiRootPath ??= "/";
539
496
  cedarOptions.apiRootPath = coerceRootPath2(cedarOptions.apiRootPath);
540
497
  cedarOptions.fastGlobOptions ??= {};
@@ -579,33 +536,29 @@ var init_api = __esm({
579
536
  // src/plugins/graphql.ts
580
537
  var graphql_exports = {};
581
538
  __export(graphql_exports, {
582
- cedarFastifyGraphQLServer: () => cedarFastifyGraphQLServer,
583
- isClientDisconnectError: () => isClientDisconnectError
539
+ redwoodFastifyGraphQLServer: () => redwoodFastifyGraphQLServer
584
540
  });
585
541
  import { pathToFileURL as pathToFileURL3 } from "node:url";
586
542
  import fastifyMultiPart from "@fastify/multipart";
587
543
  import fastifyUrlData2 from "@fastify/url-data";
588
544
  import fg2 from "fast-glob";
589
- import { buildCedarContext as buildCedarContext2 } from "@cedarjs/api/runtime";
545
+ import { buildCedarContext as buildCedarContext2, noopAuthDecoder } from "@cedarjs/api/runtime";
590
546
  import { getAsyncStoreInstance as getAsyncStoreInstance3 } from "@cedarjs/context/dist/store";
591
547
  import { coerceRootPath as coerceRootPath3 } from "@cedarjs/fastify-web/dist/helpers.js";
592
548
  import { createGraphQLYoga } from "@cedarjs/graphql-server";
593
549
  import { getPaths as getPaths3 } from "@cedarjs/project-config";
594
- async function cedarFastifyGraphQLServer(fastify2, options) {
595
- const cedarOptions = options.cedar ?? {};
596
- cedarOptions.apiRootPath ??= "/";
597
- cedarOptions.apiRootPath = coerceRootPath3(cedarOptions.apiRootPath);
550
+ async function redwoodFastifyGraphQLServer(fastify2, options) {
551
+ const redwoodOptions = options.redwood ?? {};
552
+ redwoodOptions.apiRootPath ??= "/";
553
+ redwoodOptions.apiRootPath = coerceRootPath3(redwoodOptions.apiRootPath);
598
554
  fastify2.register(fastifyUrlData2);
599
555
  fastify2.register(fastifyMultiPart);
600
556
  const method = ["GET", "POST", "OPTIONS"];
601
557
  fastify2.addHook("onRequest", (_req, _reply, done) => {
602
558
  getAsyncStoreInstance3().run(/* @__PURE__ */ new Map(), done);
603
559
  });
604
- if (cedarOptions.configureServer) {
605
- await cedarOptions.configureServer(fastify2);
606
- }
607
560
  try {
608
- if (!cedarOptions.graphql) {
561
+ if (!redwoodOptions.graphql) {
609
562
  const [graphqlFunctionPath] = await fg2("dist/functions/graphql.{ts,js}", {
610
563
  cwd: getPaths3().api.base,
611
564
  absolute: true
@@ -615,9 +568,9 @@ async function cedarFastifyGraphQLServer(fastify2, options) {
615
568
  if (!__cedar_graphqlOptions) {
616
569
  return;
617
570
  }
618
- cedarOptions.graphql = __cedar_graphqlOptions;
571
+ redwoodOptions.graphql = __cedar_graphqlOptions;
619
572
  }
620
- const graphqlOptions = cedarOptions.graphql;
573
+ const graphqlOptions = redwoodOptions.graphql;
621
574
  if (graphqlOptions?.realtime?.subscriptions) {
622
575
  method.push("PUT");
623
576
  }
@@ -626,12 +579,12 @@ async function cedarFastifyGraphQLServer(fastify2, options) {
626
579
  const routePaths = ["", "/health", "/readiness", "/stream"];
627
580
  for (const routePath of routePaths) {
628
581
  fastify2.route({
629
- url: `${cedarOptions.apiRootPath}${graphqlEndpoint}${routePath}`,
582
+ url: `${redwoodOptions.apiRootPath}${graphqlEndpoint}${routePath}`,
630
583
  method,
631
584
  handler: async (req, reply) => {
632
585
  const request = createFetchRequest(req, reply);
633
586
  const cedarContext = await buildCedarContext2(request, {
634
- authDecoder: graphqlOptions.authDecoder
587
+ authDecoder: graphqlOptions.authDecoder ?? noopAuthDecoder
635
588
  });
636
589
  try {
637
590
  return await yoga.handle(request, {
@@ -641,7 +594,7 @@ async function cedarFastifyGraphQLServer(fastify2, options) {
641
594
  requestContext: void 0
642
595
  });
643
596
  } catch (e) {
644
- if (isClientDisconnectError(e)) {
597
+ if (!!e && typeof e === "object" && "code" in e && e.code === "ERR_STREAM_PREMATURE_CLOSE") {
645
598
  return new Response(null, { status: 499 });
646
599
  }
647
600
  throw e;
@@ -660,25 +613,11 @@ async function cedarFastifyGraphQLServer(fastify2, options) {
660
613
  done();
661
614
  });
662
615
  } catch (e) {
663
- const message = e instanceof Error ? e.message : String(e);
664
- fastify2.log.error(e, `Failed to set up the GraphQL server: ${message}`);
665
- throw e;
616
+ console.log(e);
666
617
  }
667
618
  }
668
- function trimSlashes(path6) {
669
- return path6.replace(/^\/|\/$/g, "");
670
- }
671
- function isClientDisconnectError(e) {
672
- if (!e || typeof e !== "object") {
673
- return false;
674
- }
675
- if ("code" in e && e.code === "ERR_STREAM_PREMATURE_CLOSE") {
676
- return true;
677
- }
678
- if (e instanceof DOMException && e.name === "AbortError") {
679
- return true;
680
- }
681
- return false;
619
+ function trimSlashes(path5) {
620
+ return path5.replace(/^\/|\/$/g, "");
682
621
  }
683
622
  function createFetchRequest(req, reply) {
684
623
  const controller = new AbortController();
@@ -718,9 +657,7 @@ async function createServer(options = {}) {
718
657
  apiRootPath,
719
658
  fastifyServerOptions,
720
659
  discoverFunctionsGlob,
721
- configureServer,
722
660
  configureApiServer,
723
- configureGraphQLServer,
724
661
  apiPort,
725
662
  apiHost
726
663
  } = resolveOptions(options);
@@ -759,11 +696,8 @@ async function createServer(options = {}) {
759
696
  server.addHook("onRequest", (_req, _reply, done) => {
760
697
  getAsyncStoreInstance4().run(/* @__PURE__ */ new Map(), done);
761
698
  });
762
- if (configureServer) {
763
- await configureServer(server);
764
- }
765
699
  await server.register(cedarFastifyAPI, {
766
- cedar: {
700
+ redwood: {
767
701
  apiRootPath,
768
702
  fastGlobOptions: {
769
703
  ignore: ["**/dist/functions/graphql.js"]
@@ -777,13 +711,12 @@ async function createServer(options = {}) {
777
711
  absolute: true
778
712
  });
779
713
  if (graphqlFunctionPath) {
780
- const { cedarFastifyGraphQLServer: cedarFastifyGraphQLServer2 } = await Promise.resolve().then(() => (init_graphql(), graphql_exports));
714
+ const { redwoodFastifyGraphQLServer: redwoodFastifyGraphQLServer2 } = await Promise.resolve().then(() => (init_graphql(), graphql_exports));
781
715
  const { __cedar_graphqlOptions } = await import(pathToFileURL4(graphqlFunctionPath).href);
782
- await server.register(cedarFastifyGraphQLServer2, {
783
- cedar: {
716
+ await server.register(redwoodFastifyGraphQLServer2, {
717
+ redwood: {
784
718
  apiRootPath,
785
- graphql: __cedar_graphqlOptions,
786
- configureServer: configureGraphQLServer
719
+ graphql: __cedar_graphqlOptions
787
720
  }
788
721
  });
789
722
  }
@@ -824,51 +757,10 @@ var init_createServer = __esm({
824
757
  }
825
758
  });
826
759
 
827
- // src/serverFile.ts
828
- import { spawn } from "node:child_process";
829
- import fs3 from "node:fs";
830
- import path4 from "node:path";
831
- import { getPaths as getPaths5 } from "@cedarjs/project-config";
832
- function apiDistServerFilePath() {
833
- return path4.join(getPaths5().api.dist, "server.js");
834
- }
835
- function apiDistServerFileExists() {
836
- return fs3.existsSync(apiDistServerFilePath());
837
- }
838
- async function runApiDistServerFile(options = {}) {
839
- const args = ["--apiRootPath", options.apiRootPath ?? "/"];
840
- if (options.port !== void 0) {
841
- args.push("--apiPort", String(options.port));
842
- }
843
- await new Promise((resolve, reject) => {
844
- const child = spawn(process.execPath, [apiDistServerFilePath(), ...args], {
845
- cwd: getPaths5().api.dist,
846
- stdio: "inherit"
847
- });
848
- child.on("error", reject);
849
- child.on("exit", (code, signal) => {
850
- if (signal || code === 0) {
851
- resolve();
852
- return;
853
- }
854
- reject(new Error(`api/dist/server.js exited with code ${code}`));
855
- });
856
- });
857
- }
858
- var init_serverFile = __esm({
859
- "src/serverFile.ts"() {
860
- "use strict";
861
- }
862
- });
863
-
864
760
  // src/apiCLIConfigHandler.ts
865
761
  import ansis3 from "ansis";
866
762
  import { coerceRootPath as coerceRootPath4 } from "@cedarjs/fastify-web";
867
763
  async function handler(options = {}) {
868
- if (apiDistServerFileExists()) {
869
- await runApiDistServerFile(options);
870
- return;
871
- }
872
764
  const timeStart = Date.now();
873
765
  console.log(ansis3.dim.italic("Starting API Server..."));
874
766
  options.apiRootPath = coerceRootPath4(options.apiRootPath ?? "/");
@@ -899,7 +791,6 @@ var init_apiCLIConfigHandler = __esm({
899
791
  "src/apiCLIConfigHandler.ts"() {
900
792
  "use strict";
901
793
  init_createServer();
902
- init_serverFile();
903
794
  }
904
795
  });
905
796
 
@@ -907,15 +798,10 @@ var init_apiCLIConfigHandler = __esm({
907
798
  import ansis4 from "ansis";
908
799
  import { redwoodFastifyWeb, coerceRootPath as coerceRootPath5 } from "@cedarjs/fastify-web";
909
800
  async function handler2(options) {
910
- if (apiDistServerFileExists()) {
911
- throw new Error(
912
- "api/dist/server.js was found, but a custom server file is not supported when serving both sides from one process (`cedarjs-server` / `cedar serve`). It is a Fastify concept. Anything registered there (Realtime, custom plugins, custom middleware) would silently be skipped if this continued.\n\nRun the api and web sides as separate processes instead, so the api side goes through `cedarjs-server api`, which does run your server file:\n\n cedarjs-server api\n cedarjs-server web"
913
- );
914
- }
915
801
  const timeStart = Date.now();
916
802
  console.log(ansis4.dim.italic("Starting API and Web Servers..."));
917
- options.webHost ??= getWebHost({ isPublicSide: true });
918
- options.webPort ??= getWebPort({ isPublicSide: true });
803
+ options.webHost ??= getWebHost();
804
+ options.webPort ??= getWebPort();
919
805
  options.apiHost ??= getAPIHost();
920
806
  options.apiPort ??= getAPIPort();
921
807
  options.apiRootPath = coerceRootPath5(options.apiRootPath ?? "/");
@@ -982,16 +868,15 @@ var init_bothCLIConfigHandler = __esm({
982
868
  init_cliHelpers();
983
869
  init_createServer();
984
870
  init_fastify();
985
- init_serverFile();
986
871
  }
987
872
  });
988
873
 
989
874
  // src/bin.ts
990
- import path5 from "path";
875
+ import path4 from "path";
991
876
  import { config as config2 } from "dotenv-defaults";
992
877
  import { hideBin } from "yargs/helpers";
993
878
  import yargs from "yargs/yargs";
994
- import { getPaths as getPaths6 } from "@cedarjs/project-config";
879
+ import { getPaths as getPaths5 } from "@cedarjs/project-config";
995
880
  import {
996
881
  description as webDescription,
997
882
  builder as webBuilder,
@@ -1008,7 +893,7 @@ function builder(yargs2) {
1008
893
  alias: "p"
1009
894
  },
1010
895
  host: {
1011
- description: "The host to listen at",
896
+ description: "The host to listen at. Note that you most likely want this to be '0.0.0.0' in production",
1012
897
  type: "string"
1013
898
  },
1014
899
  apiRootPath: {
@@ -1039,7 +924,7 @@ function builder2(yargs2) {
1039
924
  alias: ["web-port"]
1040
925
  },
1041
926
  webHost: {
1042
- description: "The host for the web server to listen on",
927
+ 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",
1043
928
  type: "string",
1044
929
  alias: ["web-host"]
1045
930
  },
@@ -1049,7 +934,7 @@ function builder2(yargs2) {
1049
934
  alias: ["api-port"]
1050
935
  },
1051
936
  apiHost: {
1052
- description: "The host for the api server to listen on",
937
+ 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",
1053
938
  type: "string",
1054
939
  alias: ["api-host"]
1055
940
  },
@@ -1066,8 +951,8 @@ function builder2(yargs2) {
1066
951
  init_bothCLIConfigHandler();
1067
952
  if (!process.env.CEDAR_ENV_FILES_LOADED) {
1068
953
  config2({
1069
- path: path5.join(getPaths6().base, ".env"),
1070
- defaults: path5.join(getPaths6().base, ".env.defaults"),
954
+ path: path4.join(getPaths5().base, ".env"),
955
+ defaults: path4.join(getPaths5().base, ".env.defaults"),
1071
956
  multiline: true
1072
957
  });
1073
958
  process.env.CEDAR_ENV_FILES_LOADED = "true";
@@ -1 +1 @@
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,QA6BrD;AAED,wBAAsB,OAAO,CAAC,OAAO,EAAE,iBAAiB,iBAGvD"}
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"}
@@ -7,7 +7,7 @@ function builder(yargs) {
7
7
  alias: ["web-port"]
8
8
  },
9
9
  webHost: {
10
- description: "The host for the web server to listen on",
10
+ 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",
11
11
  type: "string",
12
12
  alias: ["web-host"]
13
13
  },
@@ -17,7 +17,7 @@ function builder(yargs) {
17
17
  alias: ["api-port"]
18
18
  },
19
19
  apiHost: {
20
- description: "The host for the api server to listen on",
20
+ 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",
21
21
  type: "string",
22
22
  alias: ["api-host"]
23
23
  },
@@ -1 +1 @@
1
- {"version":3,"file":"bothCLIConfigHandler.d.ts","sourceRoot":"","sources":["../src/bothCLIConfigHandler.ts"],"names":[],"mappings":"AAQA,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,YAAY,CAAA;AAEnD,wBAAsB,OAAO,CAAC,OAAO,EAAE,iBAAiB,iBA0FvD"}
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"}
@@ -3,17 +3,11 @@ import { redwoodFastifyWeb, coerceRootPath } from "@cedarjs/fastify-web";
3
3
  import { getWebHost, getWebPort, getAPIHost, getAPIPort } from "./cliHelpers.js";
4
4
  import { createServer as createApiServer } from "./createServer.js";
5
5
  import { createFastifyInstance } from "./fastify.js";
6
- import { apiDistServerFileExists } from "./serverFile.js";
7
6
  async function handler(options) {
8
- if (apiDistServerFileExists()) {
9
- throw new Error(
10
- "api/dist/server.js was found, but a custom server file is not supported when serving both sides from one process (`cedarjs-server` / `cedar serve`). It is a Fastify concept. Anything registered there (Realtime, custom plugins, custom middleware) would silently be skipped if this continued.\n\nRun the api and web sides as separate processes instead, so the api side goes through `cedarjs-server api`, which does run your server file:\n\n cedarjs-server api\n cedarjs-server web"
11
- );
12
- }
13
7
  const timeStart = Date.now();
14
8
  console.log(ansis.dim.italic("Starting API and Web Servers..."));
15
- options.webHost ??= getWebHost({ isPublicSide: true });
16
- options.webPort ??= getWebPort({ isPublicSide: true });
9
+ options.webHost ??= getWebHost();
10
+ options.webPort ??= getWebPort();
17
11
  options.apiHost ??= getAPIHost();
18
12
  options.apiPort ??= getAPIPort();
19
13
  options.apiRootPath = coerceRootPath(options.apiRootPath ?? "/");
@@ -0,0 +1,15 @@
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
@@ -0,0 +1 @@
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;IAsCjE,GAAG,CAAC,OAAO,EAAE,sBAAsB;IAWzC,oBAAoB;CAGrB;AAED,OAAO,EAAE,YAAY,EAAE,CAAA"}
@@ -0,0 +1,55 @@
1
+ import { debounce } from "./utils.js";
2
+ class BuildManager {
3
+ shouldRebuild;
4
+ shouldClean;
5
+ debouncedBuild;
6
+ buildFn;
7
+ constructor(buildFn) {
8
+ this.shouldRebuild = true;
9
+ this.shouldClean = false;
10
+ this.buildFn = buildFn;
11
+ if (process.env.RWJS_DELAY_RESTART) {
12
+ console.warn(
13
+ "[DEPRECATED] RWJS_DELAY_RESTART is deprecated and will be removed in the next major release. Please rename it to CEDAR_DELAY_API_RESTART in your .env file."
14
+ );
15
+ }
16
+ const delay = process.env.CEDAR_DELAY_API_RESTART || process.env.RWJS_DELAY_RESTART;
17
+ this.debouncedBuild = debounce(
18
+ async (options) => {
19
+ try {
20
+ await this.buildFn({
21
+ ...options,
22
+ rebuild: this.shouldRebuild,
23
+ clean: this.shouldClean
24
+ });
25
+ } finally {
26
+ this.shouldRebuild = true;
27
+ this.shouldClean = false;
28
+ }
29
+ },
30
+ // We want to delay execution when multiple files are modified on the
31
+ // filesystem. This usually happens when running Cedar generator commands.
32
+ // Local writes are very fast, but writes in e2e environments are not, so
33
+ // allow the default to be adjusted with an env-var.
34
+ delay ? parseInt(delay, 10) : 500
35
+ );
36
+ }
37
+ // Wrapper method to handle options and set precedence flags.
38
+ // If we ever see a `rebuild: false` option while debouncing, we never want to rebuild.
39
+ // If we ever see a `clean: true` option, we always want to clean.
40
+ async run(options) {
41
+ if (options.rebuild === false) {
42
+ this.shouldRebuild = false;
43
+ }
44
+ if (options.clean) {
45
+ this.shouldClean = true;
46
+ }
47
+ await this.debouncedBuild(options);
48
+ }
49
+ cancelScheduledBuild() {
50
+ this.debouncedBuild.cancel();
51
+ }
52
+ }
53
+ export {
54
+ BuildManager
55
+ };
@@ -0,0 +1,6 @@
1
+ import type { Argv } from 'yargs';
2
+ import type { APIParsedOptions } from './types.js';
3
+ export declare const description = "Start a server for serving the api side";
4
+ export declare function builder(yargs: Argv<APIParsedOptions>): void;
5
+ export declare function handler(options: APIParsedOptions): Promise<void>;
6
+ //# sourceMappingURL=apiCLIConfig.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"apiCLIConfig.d.ts","sourceRoot":"","sources":["../../src/apiCLIConfig.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,OAAO,CAAA;AAEjC,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,YAAY,CAAA;AAElD,eAAO,MAAM,WAAW,4CAA4C,CAAA;AAEpE,wBAAgB,OAAO,CAAC,KAAK,EAAE,IAAI,CAAC,gBAAgB,CAAC,QA0BpD;AAED,wBAAsB,OAAO,CAAC,OAAO,EAAE,gBAAgB,iBAGtD"}
@@ -0,0 +1,71 @@
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 apiCLIConfig_exports = {};
30
+ __export(apiCLIConfig_exports, {
31
+ builder: () => builder,
32
+ description: () => description,
33
+ handler: () => handler
34
+ });
35
+ module.exports = __toCommonJS(apiCLIConfig_exports);
36
+ const description = "Start a server for serving the api side";
37
+ function builder(yargs) {
38
+ yargs.options({
39
+ port: {
40
+ description: "The port to listen at",
41
+ type: "number",
42
+ alias: "p"
43
+ },
44
+ host: {
45
+ description: "The host to listen at. Note that you most likely want this to be '0.0.0.0' in production",
46
+ type: "string"
47
+ },
48
+ apiRootPath: {
49
+ description: "Root path where your api functions are served",
50
+ type: "string",
51
+ alias: ["api-root-path", "rootPath", "root-path"],
52
+ default: "/"
53
+ },
54
+ // This became a no-op in v7 because env files weren't loaded by default
55
+ // but removing it would break yargs parsing for older projects,
56
+ // so leaving it here so that yargs doesn't throw an error
57
+ loadEnvFiles: {
58
+ hidden: true
59
+ }
60
+ });
61
+ }
62
+ async function handler(options) {
63
+ const { handler: handler2 } = await import("./apiCLIConfigHandler.js");
64
+ await handler2(options);
65
+ }
66
+ // Annotate the CommonJS export names for ESM import in node:
67
+ 0 && (module.exports = {
68
+ builder,
69
+ description,
70
+ handler
71
+ });
@@ -0,0 +1,3 @@
1
+ import type { APIParsedOptions } from './types.js';
2
+ export declare function handler(options?: APIParsedOptions): Promise<void>;
3
+ //# sourceMappingURL=apiCLIConfigHandler.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"apiCLIConfigHandler.d.ts","sourceRoot":"","sources":["../../src/apiCLIConfigHandler.ts"],"names":[],"mappings":"AAQA,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,YAAY,CAAA;AAElD,wBAAsB,OAAO,CAAC,OAAO,GAAE,gBAAqB,iBAoC3D"}