@cedarjs/api-server 6.0.0-canary.2832 → 6.0.0-canary.2833

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":"AAKA,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,YAAY,CAAA;AAElD,wBAAsB,OAAO,CAAC,OAAO,GAAE,gBAAqB,iBAoC3D"}
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,7 +1,12 @@
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";
4
5
  async function handler(options = {}) {
6
+ if (apiDistServerFileExists()) {
7
+ await runApiDistServerFile(options);
8
+ return;
9
+ }
5
10
  const timeStart = Date.now();
6
11
  console.log(ansis.dim.italic("Starting API Server..."));
7
12
  options.apiRootPath = coerceRootPath(options.apiRootPath ?? "/");
package/dist/bin.js CHANGED
@@ -651,8 +651,8 @@ async function cedarFastifyGraphQLServer(fastify2, options) {
651
651
  throw e;
652
652
  }
653
653
  }
654
- function trimSlashes(path5) {
655
- return path5.replace(/^\/|\/$/g, "");
654
+ function trimSlashes(path6) {
655
+ return path6.replace(/^\/|\/$/g, "");
656
656
  }
657
657
  function createFetchRequest(req, reply) {
658
658
  const controller = new AbortController();
@@ -792,10 +792,51 @@ var init_createServer = __esm({
792
792
  }
793
793
  });
794
794
 
795
+ // src/serverFile.ts
796
+ import { spawn } from "node:child_process";
797
+ import fs3 from "node:fs";
798
+ import path4 from "node:path";
799
+ import { getPaths as getPaths5 } from "@cedarjs/project-config";
800
+ function apiDistServerFilePath() {
801
+ return path4.join(getPaths5().api.dist, "server.js");
802
+ }
803
+ function apiDistServerFileExists() {
804
+ return fs3.existsSync(apiDistServerFilePath());
805
+ }
806
+ async function runApiDistServerFile(options = {}) {
807
+ const args = ["--apiRootPath", options.apiRootPath ?? "/"];
808
+ if (options.port !== void 0) {
809
+ args.push("--apiPort", String(options.port));
810
+ }
811
+ await new Promise((resolve, reject) => {
812
+ const child = spawn(process.execPath, [apiDistServerFilePath(), ...args], {
813
+ cwd: getPaths5().api.dist,
814
+ stdio: "inherit"
815
+ });
816
+ child.on("error", reject);
817
+ child.on("exit", (code, signal) => {
818
+ if (signal || code === 0) {
819
+ resolve();
820
+ return;
821
+ }
822
+ reject(new Error(`api/dist/server.js exited with code ${code}`));
823
+ });
824
+ });
825
+ }
826
+ var init_serverFile = __esm({
827
+ "src/serverFile.ts"() {
828
+ "use strict";
829
+ }
830
+ });
831
+
795
832
  // src/apiCLIConfigHandler.ts
796
833
  import ansis3 from "ansis";
797
834
  import { coerceRootPath as coerceRootPath4 } from "@cedarjs/fastify-web";
798
835
  async function handler(options = {}) {
836
+ if (apiDistServerFileExists()) {
837
+ await runApiDistServerFile(options);
838
+ return;
839
+ }
799
840
  const timeStart = Date.now();
800
841
  console.log(ansis3.dim.italic("Starting API Server..."));
801
842
  options.apiRootPath = coerceRootPath4(options.apiRootPath ?? "/");
@@ -826,6 +867,7 @@ var init_apiCLIConfigHandler = __esm({
826
867
  "src/apiCLIConfigHandler.ts"() {
827
868
  "use strict";
828
869
  init_createServer();
870
+ init_serverFile();
829
871
  }
830
872
  });
831
873
 
@@ -833,6 +875,11 @@ var init_apiCLIConfigHandler = __esm({
833
875
  import ansis4 from "ansis";
834
876
  import { redwoodFastifyWeb, coerceRootPath as coerceRootPath5 } from "@cedarjs/fastify-web";
835
877
  async function handler2(options) {
878
+ if (apiDistServerFileExists()) {
879
+ throw new Error(
880
+ "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"
881
+ );
882
+ }
836
883
  const timeStart = Date.now();
837
884
  console.log(ansis4.dim.italic("Starting API and Web Servers..."));
838
885
  options.webHost ??= getWebHost({ isPublicSide: true });
@@ -903,15 +950,16 @@ var init_bothCLIConfigHandler = __esm({
903
950
  init_cliHelpers();
904
951
  init_createServer();
905
952
  init_fastify();
953
+ init_serverFile();
906
954
  }
907
955
  });
908
956
 
909
957
  // src/bin.ts
910
- import path4 from "path";
958
+ import path5 from "path";
911
959
  import { config as config2 } from "dotenv-defaults";
912
960
  import { hideBin } from "yargs/helpers";
913
961
  import yargs from "yargs/yargs";
914
- import { getPaths as getPaths5 } from "@cedarjs/project-config";
962
+ import { getPaths as getPaths6 } from "@cedarjs/project-config";
915
963
  import {
916
964
  description as webDescription,
917
965
  builder as webBuilder,
@@ -986,8 +1034,8 @@ function builder2(yargs2) {
986
1034
  init_bothCLIConfigHandler();
987
1035
  if (!process.env.CEDAR_ENV_FILES_LOADED) {
988
1036
  config2({
989
- path: path4.join(getPaths5().base, ".env"),
990
- defaults: path4.join(getPaths5().base, ".env.defaults"),
1037
+ path: path5.join(getPaths6().base, ".env"),
1038
+ defaults: path5.join(getPaths6().base, ".env.defaults"),
991
1039
  multiline: true
992
1040
  });
993
1041
  process.env.CEDAR_ENV_FILES_LOADED = "true";
@@ -1 +1 @@
1
- {"version":3,"file":"bothCLIConfigHandler.d.ts","sourceRoot":"","sources":["../src/bothCLIConfigHandler.ts"],"names":[],"mappings":"AAOA,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,YAAY,CAAA;AAEnD,wBAAsB,OAAO,CAAC,OAAO,EAAE,iBAAiB,iBAsEvD"}
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"}
@@ -3,7 +3,13 @@ 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";
6
7
  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
+ }
7
13
  const timeStart = Date.now();
8
14
  console.log(ansis.dim.italic("Starting API and Web Servers..."));
9
15
  options.webHost ??= getWebHost({ isPublicSide: true });
@@ -0,0 +1,23 @@
1
+ import type { APIParsedOptions } from './types.js';
2
+ /**
3
+ * Path to a project's built custom server file, if it has one.
4
+ *
5
+ * This checks `api/dist/server.js` — the built output — not
6
+ * `api/src/server.{ts,js}`, which is what `@cedarjs/cli`'s own
7
+ * `serverFileExists()` checks. A production install typically ships only
8
+ * `api/dist`, so checking source would return false in exactly the
9
+ * situation this needs to catch.
10
+ */
11
+ export declare function apiDistServerFilePath(): string;
12
+ export declare function apiDistServerFileExists(): boolean;
13
+ /**
14
+ * Run a project's custom `api/dist/server.js` instead of the default Fastify
15
+ * server.
16
+ *
17
+ * Reimplements what `@cedarjs/cli`'s `apiServerFileHandler` does for
18
+ * `cedar serve api`, rather than importing it — `@cedarjs/cli` pulls in its
19
+ * whole build/dev toolchain, which is exactly what a production install of
20
+ * this package needs to stay clear of.
21
+ */
22
+ export declare function runApiDistServerFile(options?: APIParsedOptions): Promise<void>;
23
+ //# sourceMappingURL=serverFile.d.ts.map
@@ -0,0 +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"}
@@ -0,0 +1,35 @@
1
+ import { spawn } from "node:child_process";
2
+ import fs from "node:fs";
3
+ import path from "node:path";
4
+ import { getPaths } from "@cedarjs/project-config";
5
+ function apiDistServerFilePath() {
6
+ return path.join(getPaths().api.dist, "server.js");
7
+ }
8
+ function apiDistServerFileExists() {
9
+ return fs.existsSync(apiDistServerFilePath());
10
+ }
11
+ async function runApiDistServerFile(options = {}) {
12
+ const args = ["--apiRootPath", options.apiRootPath ?? "/"];
13
+ if (options.port !== void 0) {
14
+ args.push("--apiPort", String(options.port));
15
+ }
16
+ await new Promise((resolve, reject) => {
17
+ const child = spawn(process.execPath, [apiDistServerFilePath(), ...args], {
18
+ cwd: getPaths().api.dist,
19
+ stdio: "inherit"
20
+ });
21
+ child.on("error", reject);
22
+ child.on("exit", (code, signal) => {
23
+ if (signal || code === 0) {
24
+ resolve();
25
+ return;
26
+ }
27
+ reject(new Error(`api/dist/server.js exited with code ${code}`));
28
+ });
29
+ });
30
+ }
31
+ export {
32
+ apiDistServerFileExists,
33
+ apiDistServerFilePath,
34
+ runApiDistServerFile
35
+ };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cedarjs/api-server",
3
- "version": "6.0.0-canary.2832",
3
+ "version": "6.0.0-canary.2833",
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": "6.0.0-canary.2832",
96
- "@cedarjs/context": "6.0.0-canary.2832",
97
- "@cedarjs/fastify-web": "6.0.0-canary.2832",
98
- "@cedarjs/project-config": "6.0.0-canary.2832",
99
- "@cedarjs/web-server": "6.0.0-canary.2832",
95
+ "@cedarjs/api": "6.0.0-canary.2833",
96
+ "@cedarjs/context": "6.0.0-canary.2833",
97
+ "@cedarjs/fastify-web": "6.0.0-canary.2833",
98
+ "@cedarjs/project-config": "6.0.0-canary.2833",
99
+ "@cedarjs/web-server": "6.0.0-canary.2833",
100
100
  "@fastify/multipart": "9.4.0",
101
101
  "@fastify/url-data": "6.0.3",
102
102
  "ansis": "4.3.1",
@@ -113,7 +113,7 @@
113
113
  "yargs": "17.7.3"
114
114
  },
115
115
  "devDependencies": {
116
- "@cedarjs/framework-tools": "6.0.0-canary.2832",
116
+ "@cedarjs/framework-tools": "6.0.0-canary.2833",
117
117
  "@types/aws-lambda": "8.10.162",
118
118
  "@types/dotenv-defaults": "^5.0.0",
119
119
  "@types/split2": "4.2.3",
@@ -128,7 +128,7 @@
128
128
  "vitest": "4.1.10"
129
129
  },
130
130
  "peerDependencies": {
131
- "@cedarjs/graphql-server": "6.0.0-canary.2832"
131
+ "@cedarjs/graphql-server": "6.0.0-canary.2833"
132
132
  },
133
133
  "peerDependenciesMeta": {
134
134
  "@cedarjs/graphql-server": {