@cedarjs/api-server 8.0.0-canary.3603 → 8.0.0-canary.3604

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.
@@ -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":"AAKA,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,YAAY,CAAA;AAElD,wBAAsB,OAAO,CAAC,OAAO,GAAE,gBAAqB,iBA0D3D"}
@@ -1,12 +1,17 @@
1
1
  import ansis from "ansis";
2
- import { coerceRootPath } from "@cedarjs/fastify-web";
3
- import { createServer } from "./createServer.js";
2
+ import { getOTelSetupFileUrl } from "@cedarjs/project-config";
4
3
  import { apiDistServerFileExists, runApiDistServerFile } from "./serverFile.js";
5
4
  async function handler(options = {}) {
6
5
  if (apiDistServerFileExists()) {
7
6
  await runApiDistServerFile(options);
8
7
  return;
9
8
  }
9
+ const otelSetupFileUrl = getOTelSetupFileUrl();
10
+ if (otelSetupFileUrl !== void 0) {
11
+ await import(otelSetupFileUrl);
12
+ }
13
+ const { coerceRootPath } = await import("@cedarjs/fastify-web");
14
+ const { createServer } = await import("./createServer.js");
10
15
  const timeStart = Date.now();
11
16
  console.log(ansis.dim.italic("Starting API Server..."));
12
17
  options.apiRootPath = coerceRootPath(options.apiRootPath ?? "/");
package/dist/bin.js CHANGED
@@ -71,6 +71,47 @@ var init_cliHelpers = __esm({
71
71
  }
72
72
  });
73
73
 
74
+ // src/serverFile.ts
75
+ import { spawn } from "node:child_process";
76
+ import fs from "node:fs";
77
+ import path from "node:path";
78
+ import { getOTelImportArgs, getPaths } from "@cedarjs/project-config";
79
+ function apiDistServerFilePath() {
80
+ return path.join(getPaths().api.dist, "server.js");
81
+ }
82
+ function apiDistServerFileExists() {
83
+ return fs.existsSync(apiDistServerFilePath());
84
+ }
85
+ async function runApiDistServerFile(options = {}) {
86
+ const args = ["--apiRootPath", options.apiRootPath ?? "/"];
87
+ if (options.port !== void 0) {
88
+ args.push("--apiPort", String(options.port));
89
+ }
90
+ await new Promise((resolve, reject) => {
91
+ const child = spawn(
92
+ process.execPath,
93
+ [...getOTelImportArgs(), apiDistServerFilePath(), ...args],
94
+ {
95
+ cwd: getPaths().api.dist,
96
+ stdio: "inherit"
97
+ }
98
+ );
99
+ child.on("error", reject);
100
+ child.on("exit", (code, signal) => {
101
+ if (signal || code === 0) {
102
+ resolve();
103
+ return;
104
+ }
105
+ reject(new Error(`api/dist/server.js exited with code ${code}`));
106
+ });
107
+ });
108
+ }
109
+ var init_serverFile = __esm({
110
+ "src/serverFile.ts"() {
111
+ "use strict";
112
+ }
113
+ });
114
+
74
115
  // src/createServerHelpers.ts
75
116
  import { parseArgs } from "util";
76
117
  import { coerceRootPath } from "@cedarjs/fastify-web/dist/helpers.js";
@@ -173,18 +214,24 @@ var init_createServerHelpers = __esm({
173
214
  });
174
215
 
175
216
  // src/fastify.ts
176
- import fs from "node:fs";
177
- import path from "path";
217
+ var fastify_exports = {};
218
+ __export(fastify_exports, {
219
+ DEFAULT_OPTIONS: () => DEFAULT_OPTIONS,
220
+ createFastifyInstance: () => createFastifyInstance,
221
+ loadFastifyConfig: () => loadFastifyConfig
222
+ });
223
+ import fs2 from "node:fs";
224
+ import path2 from "path";
178
225
  import { pathToFileURL } from "url";
179
226
  import Fastify from "fastify";
180
227
  import { getAsyncStoreInstance } from "@cedarjs/context/dist/store";
181
- import { getPaths, getConfig as getConfig2 } from "@cedarjs/project-config";
228
+ import { getPaths as getPaths2, getConfig as getConfig2 } from "@cedarjs/project-config";
182
229
  async function loadFastifyConfig() {
183
- const serverConfigPath = path.join(
184
- getPaths().base,
230
+ const serverConfigPath = path2.join(
231
+ getPaths2().base,
185
232
  getConfig2().api.serverConfig
186
233
  );
187
- if (!fs.existsSync(serverConfigPath)) {
234
+ if (!fs2.existsSync(serverConfigPath)) {
188
235
  return serverConfigFile;
189
236
  }
190
237
  if (loadedServerConfigPath !== serverConfigPath) {
@@ -370,13 +417,13 @@ var init_utils2 = __esm({
370
417
  });
371
418
 
372
419
  // src/plugins/lambdaLoader.ts
373
- import path2 from "node:path";
420
+ import path3 from "node:path";
374
421
  import { pathToFileURL as pathToFileURL2 } from "node:url";
375
422
  import ansis from "ansis";
376
423
  import fg from "fast-glob";
377
424
  import { terminalLink } from "termi-link";
378
425
  import { buildCedarContext, wrapLegacyHandler } from "@cedarjs/api/runtime";
379
- import { getPaths as getPaths2 } from "@cedarjs/project-config";
426
+ import { getPaths as getPaths3 } from "@cedarjs/project-config";
380
427
  var LAMBDA_FUNCTIONS, CEDAR_HANDLERS, cedarRouteManifest, setLambdaFunctions, loadFunctionsFromDist, findApiDistFunctions, lambdaRequestHandler;
381
428
  var init_lambdaLoader = __esm({
382
429
  "src/plugins/lambdaLoader.ts"() {
@@ -394,7 +441,7 @@ var init_lambdaLoader = __esm({
394
441
  CEDAR_HANDLERS.clear();
395
442
  const imports = foundFunctions.map(async (fnPath) => {
396
443
  const ts = Date.now();
397
- const routeName = path2.basename(fnPath).replace(".js", "");
444
+ const routeName = path3.basename(fnPath).replace(".js", "");
398
445
  const routePath = `/${routeName}`;
399
446
  const fnImport = await import(pathToFileURL2(fnPath).href);
400
447
  const handler3 = (() => {
@@ -452,11 +499,11 @@ var init_lambdaLoader = __esm({
452
499
  };
453
500
  loadFunctionsFromDist = async (options = {}) => {
454
501
  const serverFunctions = findApiDistFunctions({
455
- cwd: getPaths2().api.base,
502
+ cwd: getPaths3().api.base,
456
503
  options: options?.fastGlobOptions,
457
504
  discoverFunctionsGlob: options?.discoverFunctionsGlob
458
505
  });
459
- const i = serverFunctions.findIndex((x) => path2.basename(x) === "graphql.js");
506
+ const i = serverFunctions.findIndex((x) => path3.basename(x) === "graphql.js");
460
507
  if (i >= 0) {
461
508
  const graphQLFn = serverFunctions.splice(i, 1)[0];
462
509
  serverFunctions.unshift(graphQLFn);
@@ -465,7 +512,7 @@ var init_lambdaLoader = __esm({
465
512
  };
466
513
  findApiDistFunctions = (params) => {
467
514
  const {
468
- cwd = getPaths2().api.base,
515
+ cwd = getPaths3().api.base,
469
516
  options = {},
470
517
  discoverFunctionsGlob = "dist/functions/**/*.{ts,js}"
471
518
  } = params;
@@ -589,7 +636,7 @@ import fg2 from "fast-glob";
589
636
  import { getAsyncStoreInstance as getAsyncStoreInstance3 } from "@cedarjs/context/dist/store";
590
637
  import { coerceRootPath as coerceRootPath3 } from "@cedarjs/fastify-web/dist/helpers.js";
591
638
  import { createGraphQLServer } from "@cedarjs/graphql-server";
592
- import { getPaths as getPaths3 } from "@cedarjs/project-config";
639
+ import { getPaths as getPaths4 } from "@cedarjs/project-config";
593
640
  async function cedarFastifyGraphQLServer(fastify2, options) {
594
641
  const cedarOptions = options.cedar ?? {};
595
642
  cedarOptions.apiRootPath ??= "/";
@@ -606,7 +653,7 @@ async function cedarFastifyGraphQLServer(fastify2, options) {
606
653
  try {
607
654
  if (!cedarOptions.graphql) {
608
655
  const [graphqlFunctionPath] = await fg2("dist/functions/graphql.{ts,js}", {
609
- cwd: getPaths3().api.base,
656
+ cwd: getPaths4().api.base,
610
657
  absolute: true
611
658
  });
612
659
  const filePath = pathToFileURL3(graphqlFunctionPath).href;
@@ -701,8 +748,12 @@ var init_graphql = __esm({
701
748
  });
702
749
 
703
750
  // src/createServer.ts
704
- import fs2 from "node:fs";
705
- import path3 from "node:path";
751
+ var createServer_exports = {};
752
+ __export(createServer_exports, {
753
+ createServer: () => createServer
754
+ });
755
+ import fs3 from "node:fs";
756
+ import path4 from "node:path";
706
757
  import { pathToFileURL as pathToFileURL4 } from "node:url";
707
758
  import ansis2 from "ansis";
708
759
  import { config } from "dotenv-defaults";
@@ -711,7 +762,7 @@ import fastify from "fastify";
711
762
  import { getAsyncStoreInstance as getAsyncStoreInstance4 } from "@cedarjs/context/dist/store";
712
763
  import {
713
764
  getConfig as getConfig3,
714
- getPaths as getPaths4,
765
+ getPaths as getPaths5,
715
766
  writeApiProcessMeta
716
767
  } from "@cedarjs/project-config";
717
768
  async function createServer(options = {}) {
@@ -725,11 +776,11 @@ async function createServer(options = {}) {
725
776
  apiPort,
726
777
  apiHost
727
778
  } = resolveOptions(options);
728
- const serverConfigPath = path3.join(
729
- getPaths4().base,
779
+ const serverConfigPath = path4.join(
780
+ getPaths5().base,
730
781
  getConfig3().api.serverConfig
731
782
  );
732
- if (fs2.existsSync(serverConfigPath)) {
783
+ if (fs3.existsSync(serverConfigPath)) {
733
784
  console.warn(
734
785
  ansis2.yellow(
735
786
  [
@@ -774,7 +825,7 @@ async function createServer(options = {}) {
774
825
  }
775
826
  });
776
827
  const [graphqlFunctionPath] = await fg3("dist/functions/graphql.{ts,js}", {
777
- cwd: getPaths4().api.base,
828
+ cwd: getPaths5().api.base,
778
829
  absolute: true
779
830
  });
780
831
  if (graphqlFunctionPath) {
@@ -829,8 +880,8 @@ var init_createServer = __esm({
829
880
  init_api();
830
881
  if (!process.env.CEDAR_ENV_FILES_LOADED) {
831
882
  config({
832
- path: path3.join(getPaths4().base, ".env"),
833
- defaults: path3.join(getPaths4().base, ".env.defaults"),
883
+ path: path4.join(getPaths5().base, ".env"),
884
+ defaults: path4.join(getPaths5().base, ".env.defaults"),
834
885
  multiline: true
835
886
  });
836
887
  process.env.CEDAR_ENV_FILES_LOADED = "true";
@@ -838,101 +889,33 @@ var init_createServer = __esm({
838
889
  }
839
890
  });
840
891
 
841
- // src/serverFile.ts
842
- import { spawn } from "node:child_process";
843
- import fs3 from "node:fs";
844
- import path4 from "node:path";
845
- import { getPaths as getPaths5 } from "@cedarjs/project-config";
846
- function apiDistServerFilePath() {
847
- return path4.join(getPaths5().api.dist, "server.js");
848
- }
849
- function apiDistServerFileExists() {
850
- return fs3.existsSync(apiDistServerFilePath());
851
- }
852
- async function runApiDistServerFile(options = {}) {
853
- const args = ["--apiRootPath", options.apiRootPath ?? "/"];
854
- if (options.port !== void 0) {
855
- args.push("--apiPort", String(options.port));
856
- }
857
- await new Promise((resolve, reject) => {
858
- const child = spawn(process.execPath, [apiDistServerFilePath(), ...args], {
859
- cwd: getPaths5().api.dist,
860
- stdio: "inherit"
861
- });
862
- child.on("error", reject);
863
- child.on("exit", (code, signal) => {
864
- if (signal || code === 0) {
865
- resolve();
866
- return;
867
- }
868
- reject(new Error(`api/dist/server.js exited with code ${code}`));
869
- });
870
- });
871
- }
872
- var init_serverFile = __esm({
873
- "src/serverFile.ts"() {
874
- "use strict";
875
- }
892
+ // src/bothCLIConfigHandler.ts
893
+ var bothCLIConfigHandler_exports = {};
894
+ __export(bothCLIConfigHandler_exports, {
895
+ handler: () => handler
876
896
  });
877
-
878
- // src/apiCLIConfigHandler.ts
879
897
  import ansis3 from "ansis";
880
- import { coerceRootPath as coerceRootPath4 } from "@cedarjs/fastify-web";
881
- async function handler(options = {}) {
882
- if (apiDistServerFileExists()) {
883
- await runApiDistServerFile(options);
884
- return;
885
- }
886
- const timeStart = Date.now();
887
- console.log(ansis3.dim.italic("Starting API Server..."));
888
- options.apiRootPath = coerceRootPath4(options.apiRootPath ?? "/");
889
- const fastify2 = await createServer({
890
- apiRootPath: options.apiRootPath,
891
- apiHost: options.host,
892
- apiPort: options.port
893
- });
894
- await fastify2.start();
895
- fastify2.log.trace(
896
- { custom: { ...fastify2.initialConfig } },
897
- "Fastify server configuration"
898
- );
899
- fastify2.log.trace(`Registered plugins
900
- ${fastify2.printPlugins()}`);
901
- console.log(ansis3.dim.italic("Took " + (Date.now() - timeStart) + " ms"));
902
- let address = fastify2.listeningOrigin;
903
- if (process.env.NODE_ENV !== "production") {
904
- address = address.replace(/http:\/\/\[::\]/, "http://localhost");
905
- }
906
- const apiServer = ansis3.magenta(`${address}${options.apiRootPath}`);
907
- const graphqlEndpoint = ansis3.magenta(`${apiServer}graphql`);
908
- console.log(`API server listening at ${apiServer}`);
909
- console.log(`GraphQL endpoint at ${graphqlEndpoint}`);
910
- process?.send?.("ready");
911
- }
912
- var init_apiCLIConfigHandler = __esm({
913
- "src/apiCLIConfigHandler.ts"() {
914
- "use strict";
915
- init_createServer();
916
- init_serverFile();
917
- }
918
- });
919
-
920
- // src/bothCLIConfigHandler.ts
921
- import ansis4 from "ansis";
922
- import { redwoodFastifyWeb, coerceRootPath as coerceRootPath5 } from "@cedarjs/fastify-web";
923
- async function handler2(options) {
898
+ import { getOTelSetupFileUrl } from "@cedarjs/project-config";
899
+ async function handler(options) {
924
900
  if (apiDistServerFileExists()) {
925
901
  throw new Error(
926
902
  "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"
927
903
  );
928
904
  }
905
+ const otelSetupFileUrl = getOTelSetupFileUrl();
906
+ if (otelSetupFileUrl !== void 0) {
907
+ await import(otelSetupFileUrl);
908
+ }
909
+ const { redwoodFastifyWeb, coerceRootPath: coerceRootPath4 } = await import("@cedarjs/fastify-web");
910
+ const { createServer: createApiServer } = await Promise.resolve().then(() => (init_createServer(), createServer_exports));
911
+ const { createFastifyInstance: createFastifyInstance2 } = await Promise.resolve().then(() => (init_fastify(), fastify_exports));
929
912
  const timeStart = Date.now();
930
- console.log(ansis4.dim.italic("Starting API and Web Servers..."));
913
+ console.log(ansis3.dim.italic("Starting API and Web Servers..."));
931
914
  options.webHost ??= getWebHost({ isPublicSide: true });
932
915
  options.webPort ??= getWebPort({ isPublicSide: true });
933
916
  options.apiHost ??= getAPIHost();
934
917
  options.apiPort ??= getAPIPort();
935
- options.apiRootPath = coerceRootPath5(options.apiRootPath ?? "/");
918
+ options.apiRootPath = coerceRootPath4(options.apiRootPath ?? "/");
936
919
  const apiProxyTarget = [
937
920
  "http://",
938
921
  options.apiHost.includes(":") ? `[${options.apiHost}]` : options.apiHost,
@@ -940,13 +923,13 @@ async function handler2(options) {
940
923
  options.apiPort,
941
924
  options.apiRootPath
942
925
  ].join("");
943
- const webFastify = await createFastifyInstance();
926
+ const webFastify = await createFastifyInstance2();
944
927
  webFastify.register(redwoodFastifyWeb, {
945
928
  redwood: {
946
929
  apiProxyTarget
947
930
  }
948
931
  });
949
- const apiFastify = await createServer({
932
+ const apiFastify = await createApiServer({
950
933
  apiRootPath: options.apiRootPath
951
934
  });
952
935
  await webFastify.listen({
@@ -971,12 +954,12 @@ ${webFastify.printPlugins()}`);
971
954
  );
972
955
  apiFastify.log.trace(`Registered plugins
973
956
  ${apiFastify.printPlugins()}`);
974
- console.log(ansis4.dim.italic("Took " + (Date.now() - timeStart) + " ms"));
975
- const webServer = ansis4.green(webFastify.listeningOrigin);
976
- const apiServer = ansis4.magenta(
957
+ console.log(ansis3.dim.italic("Took " + (Date.now() - timeStart) + " ms"));
958
+ const webServer = ansis3.green(webFastify.listeningOrigin);
959
+ const apiServer = ansis3.magenta(
977
960
  `${apiFastify.listeningOrigin}${options.apiRootPath}`
978
961
  );
979
- const graphqlEndpoint = ansis4.magenta(`${apiServer}graphql`);
962
+ const graphqlEndpoint = ansis3.magenta(`${apiServer}graphql`);
980
963
  console.log(`Web server listening at ${webServer}`);
981
964
  console.log(`API server listening at ${apiServer}`);
982
965
  console.log(`GraphQL endpoint at ${graphqlEndpoint}`);
@@ -994,8 +977,57 @@ var init_bothCLIConfigHandler = __esm({
994
977
  "src/bothCLIConfigHandler.ts"() {
995
978
  "use strict";
996
979
  init_cliHelpers();
997
- init_createServer();
998
- init_fastify();
980
+ init_serverFile();
981
+ }
982
+ });
983
+
984
+ // src/apiCLIConfigHandler.ts
985
+ var apiCLIConfigHandler_exports = {};
986
+ __export(apiCLIConfigHandler_exports, {
987
+ handler: () => handler2
988
+ });
989
+ import ansis4 from "ansis";
990
+ import { getOTelSetupFileUrl as getOTelSetupFileUrl2 } from "@cedarjs/project-config";
991
+ async function handler2(options = {}) {
992
+ if (apiDistServerFileExists()) {
993
+ await runApiDistServerFile(options);
994
+ return;
995
+ }
996
+ const otelSetupFileUrl = getOTelSetupFileUrl2();
997
+ if (otelSetupFileUrl !== void 0) {
998
+ await import(otelSetupFileUrl);
999
+ }
1000
+ const { coerceRootPath: coerceRootPath4 } = await import("@cedarjs/fastify-web");
1001
+ const { createServer: createServer2 } = await Promise.resolve().then(() => (init_createServer(), createServer_exports));
1002
+ const timeStart = Date.now();
1003
+ console.log(ansis4.dim.italic("Starting API Server..."));
1004
+ options.apiRootPath = coerceRootPath4(options.apiRootPath ?? "/");
1005
+ const fastify2 = await createServer2({
1006
+ apiRootPath: options.apiRootPath,
1007
+ apiHost: options.host,
1008
+ apiPort: options.port
1009
+ });
1010
+ await fastify2.start();
1011
+ fastify2.log.trace(
1012
+ { custom: { ...fastify2.initialConfig } },
1013
+ "Fastify server configuration"
1014
+ );
1015
+ fastify2.log.trace(`Registered plugins
1016
+ ${fastify2.printPlugins()}`);
1017
+ console.log(ansis4.dim.italic("Took " + (Date.now() - timeStart) + " ms"));
1018
+ let address = fastify2.listeningOrigin;
1019
+ if (process.env.NODE_ENV !== "production") {
1020
+ address = address.replace(/http:\/\/\[::\]/, "http://localhost");
1021
+ }
1022
+ const apiServer = ansis4.magenta(`${address}${options.apiRootPath}`);
1023
+ const graphqlEndpoint = ansis4.magenta(`${apiServer}graphql`);
1024
+ console.log(`API server listening at ${apiServer}`);
1025
+ console.log(`GraphQL endpoint at ${graphqlEndpoint}`);
1026
+ process?.send?.("ready");
1027
+ }
1028
+ var init_apiCLIConfigHandler = __esm({
1029
+ "src/apiCLIConfigHandler.ts"() {
1030
+ "use strict";
999
1031
  init_serverFile();
1000
1032
  }
1001
1033
  });
@@ -1040,9 +1072,6 @@ function builder(yargs2) {
1040
1072
  });
1041
1073
  }
1042
1074
 
1043
- // src/bin.ts
1044
- init_apiCLIConfigHandler();
1045
-
1046
1075
  // src/bothCLIConfig.ts
1047
1076
  var description2 = "Start a server for serving the api and web sides";
1048
1077
  function builder2(yargs2) {
@@ -1077,7 +1106,6 @@ function builder2(yargs2) {
1077
1106
  }
1078
1107
 
1079
1108
  // src/bin.ts
1080
- init_bothCLIConfigHandler();
1081
1109
  if (!process.env.CEDAR_ENV_FILES_LOADED) {
1082
1110
  config2({
1083
1111
  path: path5.join(getPaths6().base, ".env"),
@@ -1092,13 +1120,22 @@ yargs(hideBin(process.argv)).scriptName("cedar-server").strict().alias("h", "hel
1092
1120
  description2,
1093
1121
  // @ts-expect-error The yargs types seem wrong; it's ok for builder to be a function
1094
1122
  builder2,
1095
- handler2
1123
+ // The API handlers import Fastify and the app's own modules, so they are
1124
+ // loaded lazily: the OpenTelemetry setup they import must be able to run
1125
+ // first through the preload flags placed on this process.
1126
+ async (argv) => {
1127
+ const { handler: handler3 } = await Promise.resolve().then(() => (init_bothCLIConfigHandler(), bothCLIConfigHandler_exports));
1128
+ await handler3(argv);
1129
+ }
1096
1130
  ).command(
1097
1131
  "api",
1098
1132
  description,
1099
1133
  // @ts-expect-error The yargs types seem wrong; it's ok for builder to be a function
1100
1134
  builder,
1101
- handler
1135
+ async (argv) => {
1136
+ const { handler: handler3 } = await Promise.resolve().then(() => (init_apiCLIConfigHandler(), apiCLIConfigHandler_exports));
1137
+ await handler3(argv);
1138
+ }
1102
1139
  ).command(
1103
1140
  "web",
1104
1141
  webDescription,
@@ -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":"AAMA,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,YAAY,CAAA;AAEnD,wBAAsB,OAAO,CAAC,OAAO,EAAE,iBAAiB,iBA0GvD"}
@@ -1,8 +1,6 @@
1
1
  import ansis from "ansis";
2
- import { redwoodFastifyWeb, coerceRootPath } from "@cedarjs/fastify-web";
2
+ import { getOTelSetupFileUrl } from "@cedarjs/project-config";
3
3
  import { getWebHost, getWebPort, getAPIHost, getAPIPort } from "./cliHelpers.js";
4
- import { createServer as createApiServer } from "./createServer.js";
5
- import { createFastifyInstance } from "./fastify.js";
6
4
  import { apiDistServerFileExists } from "./serverFile.js";
7
5
  async function handler(options) {
8
6
  if (apiDistServerFileExists()) {
@@ -10,6 +8,13 @@ async function handler(options) {
10
8
  "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
9
  );
12
10
  }
11
+ const otelSetupFileUrl = getOTelSetupFileUrl();
12
+ if (otelSetupFileUrl !== void 0) {
13
+ await import(otelSetupFileUrl);
14
+ }
15
+ const { redwoodFastifyWeb, coerceRootPath } = await import("@cedarjs/fastify-web");
16
+ const { createServer: createApiServer } = await import("./createServer.js");
17
+ const { createFastifyInstance } = await import("./fastify.js");
13
18
  const timeStart = Date.now();
14
19
  console.log(ansis.dim.italic("Starting API and Web Servers..."));
15
20
  options.webHost ??= getWebHost({ isPublicSide: true });
@@ -1 +1 @@
1
- {"version":3,"file":"serverFile.d.ts","sourceRoot":"","sources":["../src/serverFile.ts"],"names":[],"mappings":"AAMA,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,YAAY,CAAA;AAElD;;;;;;;;GAQG;AACH,wBAAgB,qBAAqB,IAAI,MAAM,CAE9C;AAED,wBAAgB,uBAAuB,IAAI,OAAO,CAEjD;AAED;;;;;;;;GAQG;AACH,wBAAsB,oBAAoB,CACxC,OAAO,GAAE,gBAAqB,GAC7B,OAAO,CAAC,IAAI,CAAC,CA4Bf"}
1
+ {"version":3,"file":"serverFile.d.ts","sourceRoot":"","sources":["../src/serverFile.ts"],"names":[],"mappings":"AAMA,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,YAAY,CAAA;AAElD;;;;;;;;GAQG;AACH,wBAAgB,qBAAqB,IAAI,MAAM,CAE9C;AAED,wBAAgB,uBAAuB,IAAI,OAAO,CAEjD;AAED;;;;;;;;GAQG;AACH,wBAAsB,oBAAoB,CACxC,OAAO,GAAE,gBAAqB,GAC7B,OAAO,CAAC,IAAI,CAAC,CAgCf"}
@@ -1,7 +1,7 @@
1
1
  import { spawn } from "node:child_process";
2
2
  import fs from "node:fs";
3
3
  import path from "node:path";
4
- import { getPaths } from "@cedarjs/project-config";
4
+ import { getOTelImportArgs, getPaths } from "@cedarjs/project-config";
5
5
  function apiDistServerFilePath() {
6
6
  return path.join(getPaths().api.dist, "server.js");
7
7
  }
@@ -14,10 +14,14 @@ async function runApiDistServerFile(options = {}) {
14
14
  args.push("--apiPort", String(options.port));
15
15
  }
16
16
  await new Promise((resolve, reject) => {
17
- const child = spawn(process.execPath, [apiDistServerFilePath(), ...args], {
18
- cwd: getPaths().api.dist,
19
- stdio: "inherit"
20
- });
17
+ const child = spawn(
18
+ process.execPath,
19
+ [...getOTelImportArgs(), apiDistServerFilePath(), ...args],
20
+ {
21
+ cwd: getPaths().api.dist,
22
+ stdio: "inherit"
23
+ }
24
+ );
21
25
  child.on("error", reject);
22
26
  child.on("exit", (code, signal) => {
23
27
  if (signal || code === 0) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cedarjs/api-server",
3
- "version": "8.0.0-canary.3603",
3
+ "version": "8.0.0-canary.3604",
4
4
  "description": "CedarJS's HTTP server for Serverless Functions",
5
5
  "repository": {
6
6
  "type": "git",
@@ -92,11 +92,11 @@
92
92
  "test:watch": "vitest watch"
93
93
  },
94
94
  "dependencies": {
95
- "@cedarjs/api": "8.0.0-canary.3603",
96
- "@cedarjs/context": "8.0.0-canary.3603",
97
- "@cedarjs/fastify-web": "8.0.0-canary.3603",
98
- "@cedarjs/project-config": "8.0.0-canary.3603",
99
- "@cedarjs/web-server": "8.0.0-canary.3603",
95
+ "@cedarjs/api": "8.0.0-canary.3604",
96
+ "@cedarjs/context": "8.0.0-canary.3604",
97
+ "@cedarjs/fastify-web": "8.0.0-canary.3604",
98
+ "@cedarjs/project-config": "8.0.0-canary.3604",
99
+ "@cedarjs/web-server": "8.0.0-canary.3604",
100
100
  "@fastify/multipart": "9.4.0",
101
101
  "@fastify/url-data": "6.0.5",
102
102
  "ansis": "4.4.0",
@@ -113,7 +113,7 @@
113
113
  "yargs": "18.2.0"
114
114
  },
115
115
  "devDependencies": {
116
- "@cedarjs/framework-tools": "8.0.0-canary.3603",
116
+ "@cedarjs/framework-tools": "8.0.0-canary.3604",
117
117
  "@fastify/compress": "9.3.0",
118
118
  "@types/aws-lambda": "8.10.164",
119
119
  "@types/dotenv-defaults": "^5.0.0",
@@ -130,7 +130,7 @@
130
130
  "vitest": "5.0.5"
131
131
  },
132
132
  "peerDependencies": {
133
- "@cedarjs/graphql-server": "8.0.0-canary.3603"
133
+ "@cedarjs/graphql-server": "8.0.0-canary.3604"
134
134
  },
135
135
  "peerDependenciesMeta": {
136
136
  "@cedarjs/graphql-server": {