@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.
- package/README.md +1 -0
- package/dist/apiCLIConfig.d.ts.map +1 -1
- package/dist/apiCLIConfig.js +1 -1
- package/dist/apiCLIConfigHandler.d.ts.map +1 -1
- package/dist/apiCLIConfigHandler.js +0 -5
- package/dist/bin.js +45 -160
- package/dist/bothCLIConfig.d.ts.map +1 -1
- package/dist/bothCLIConfig.js +2 -2
- package/dist/bothCLIConfigHandler.d.ts.map +1 -1
- package/dist/bothCLIConfigHandler.js +2 -8
- package/dist/buildManager.d.ts +15 -0
- package/dist/buildManager.d.ts.map +1 -0
- package/dist/buildManager.js +55 -0
- package/dist/cjs/apiCLIConfig.d.ts +6 -0
- package/dist/cjs/apiCLIConfig.d.ts.map +1 -0
- package/dist/cjs/apiCLIConfig.js +71 -0
- package/dist/cjs/apiCLIConfigHandler.d.ts +3 -0
- package/dist/cjs/apiCLIConfigHandler.d.ts.map +1 -0
- package/dist/cjs/apiCLIConfigHandler.js +67 -0
- package/dist/cjs/bin.d.ts +2 -0
- package/dist/cjs/bin.d.ts.map +1 -0
- package/dist/cjs/bin.js +1002 -0
- package/dist/cjs/bothCLIConfig.d.ts +6 -0
- package/dist/cjs/bothCLIConfig.d.ts.map +1 -0
- package/dist/cjs/bothCLIConfig.js +76 -0
- package/dist/cjs/bothCLIConfigHandler.d.ts +3 -0
- package/dist/cjs/bothCLIConfigHandler.d.ts.map +1 -0
- package/dist/cjs/bothCLIConfigHandler.js +107 -0
- package/dist/cjs/buildManager.d.ts +15 -0
- package/dist/cjs/buildManager.d.ts.map +1 -0
- package/dist/cjs/buildManager.js +79 -0
- package/dist/cjs/cliHelpers.d.ts +6 -0
- package/dist/cjs/cliHelpers.d.ts.map +1 -0
- package/dist/cjs/cliHelpers.js +57 -0
- package/dist/cjs/createServer.d.ts +30 -0
- package/dist/cjs/createServer.d.ts.map +1 -0
- package/dist/cjs/createServer.js +145 -0
- package/dist/cjs/createServerHelpers.d.ts +38 -0
- package/dist/cjs/createServerHelpers.d.ts.map +1 -0
- package/dist/cjs/createServerHelpers.js +112 -0
- package/dist/cjs/fastify.d.ts +13 -0
- package/dist/cjs/fastify.d.ts.map +1 -0
- package/dist/cjs/fastify.js +96 -0
- package/dist/cjs/logFormatter/ambient.d.js +1 -0
- package/dist/cjs/logFormatter/bin.d.ts +2 -0
- package/dist/cjs/logFormatter/bin.d.ts.map +1 -0
- package/dist/cjs/logFormatter/bin.js +369 -0
- package/dist/cjs/logFormatter/formatters.d.ts +30 -0
- package/dist/cjs/logFormatter/formatters.d.ts.map +1 -0
- package/dist/cjs/logFormatter/formatters.js +275 -0
- package/dist/cjs/logFormatter/index.d.ts +2 -0
- package/dist/cjs/logFormatter/index.d.ts.map +1 -0
- package/dist/cjs/logFormatter/index.js +184 -0
- package/dist/cjs/package.json +1 -0
- package/dist/cjs/plugins/api.d.ts +14 -0
- package/dist/cjs/plugins/api.d.ts.map +1 -0
- package/dist/cjs/plugins/api.js +78 -0
- package/dist/cjs/plugins/graphql.d.ts +10 -0
- package/dist/cjs/plugins/graphql.d.ts.map +1 -0
- package/dist/cjs/plugins/graphql.js +135 -0
- package/dist/cjs/plugins/lambdaLoader.d.ts +34 -0
- package/dist/cjs/plugins/lambdaLoader.d.ts.map +1 -0
- package/dist/cjs/plugins/lambdaLoader.js +199 -0
- package/dist/cjs/requestHandlers/awsLambdaFastify.d.ts +5 -0
- package/dist/cjs/requestHandlers/awsLambdaFastify.d.ts.map +1 -0
- package/dist/cjs/requestHandlers/awsLambdaFastify.js +105 -0
- package/dist/cjs/requestHandlers/utils.d.ts +26 -0
- package/dist/cjs/requestHandlers/utils.d.ts.map +1 -0
- package/dist/cjs/requestHandlers/utils.js +55 -0
- package/dist/cjs/serverManager.d.ts +8 -0
- package/dist/cjs/serverManager.d.ts.map +1 -0
- package/dist/cjs/serverManager.js +137 -0
- package/dist/cjs/types.d.ts +19 -0
- package/dist/cjs/types.d.ts.map +1 -0
- package/dist/cjs/utils.d.ts +6 -0
- package/dist/cjs/utils.d.ts.map +1 -0
- package/dist/cjs/utils.js +58 -0
- package/dist/cjs/watch.d.ts +10 -0
- package/dist/cjs/watch.d.ts.map +1 -0
- package/dist/cjs/watch.js +399 -0
- package/dist/cjs/watchPaths.d.ts +3 -0
- package/dist/cjs/watchPaths.d.ts.map +1 -0
- package/dist/cjs/watchPaths.js +140 -0
- package/dist/cliHelpers.d.ts +4 -21
- package/dist/cliHelpers.d.ts.map +1 -1
- package/dist/cliHelpers.js +11 -39
- package/dist/createServer.d.ts +3 -19
- package/dist/createServer.d.ts.map +1 -1
- package/dist/createServer.js +5 -11
- package/dist/createServerHelpers.d.ts +2 -15
- package/dist/createServerHelpers.d.ts.map +1 -1
- package/dist/createServerHelpers.js +2 -12
- package/dist/logFormatter/formatters.d.ts.map +1 -1
- package/dist/plugins/api.d.ts +3 -2
- package/dist/plugins/api.d.ts.map +1 -1
- package/dist/plugins/api.js +1 -1
- package/dist/plugins/graphql.d.ts +3 -20
- package/dist/plugins/graphql.d.ts.map +1 -1
- package/dist/plugins/graphql.js +13 -31
- package/dist/plugins/lambdaLoader.d.ts.map +1 -1
- package/dist/serverManager.d.ts +8 -0
- package/dist/serverManager.d.ts.map +1 -0
- package/dist/serverManager.js +102 -0
- package/dist/types.d.ts +3 -3
- package/dist/types.d.ts.map +1 -1
- package/dist/utils.d.ts +3 -0
- package/dist/utils.d.ts.map +1 -1
- package/dist/utils.js +20 -0
- package/dist/watch.d.ts +10 -0
- package/dist/watch.d.ts.map +1 -0
- package/dist/watch.js +375 -0
- package/dist/watchPaths.d.ts +3 -0
- package/dist/watchPaths.d.ts.map +1 -0
- package/dist/watchPaths.js +109 -0
- package/package.json +79 -39
- package/dist/serverFile.d.ts +0 -23
- package/dist/serverFile.d.ts.map +0 -1
- package/dist/serverFile.js +0 -35
|
@@ -0,0 +1,140 @@
|
|
|
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 watchPaths_exports = {};
|
|
30
|
+
__export(watchPaths_exports, {
|
|
31
|
+
getIgnoreFunction: () => getIgnoreFunction,
|
|
32
|
+
pathsToWatch: () => pathsToWatch
|
|
33
|
+
});
|
|
34
|
+
module.exports = __toCommonJS(watchPaths_exports);
|
|
35
|
+
var import_node_fs = __toESM(require("node:fs"), 1);
|
|
36
|
+
var import_node_path = __toESM(require("node:path"), 1);
|
|
37
|
+
var import_project_config = require("@cedarjs/project-config");
|
|
38
|
+
async function workspacePackagesPaths() {
|
|
39
|
+
const cedarPaths = (0, import_project_config.getPaths)();
|
|
40
|
+
const packagesDir = import_node_path.default.join(cedarPaths.packages);
|
|
41
|
+
const packages = [];
|
|
42
|
+
try {
|
|
43
|
+
const rootPackageJsonPath = import_node_path.default.join(cedarPaths.base, "package.json");
|
|
44
|
+
const rootPackageJson = JSON.parse(
|
|
45
|
+
import_node_fs.default.readFileSync(rootPackageJsonPath, "utf8")
|
|
46
|
+
);
|
|
47
|
+
const hasPackageJsonWorkspaces = Array.isArray(rootPackageJson.workspaces) && rootPackageJson.workspaces.some((w) => w.startsWith("packages/"));
|
|
48
|
+
if (!hasPackageJsonWorkspaces || !import_node_fs.default.existsSync(packagesDir)) {
|
|
49
|
+
return [];
|
|
50
|
+
}
|
|
51
|
+
const globPattern = import_node_path.default.join(packagesDir, "*").replaceAll("\\", "/");
|
|
52
|
+
const packageDirs = await Array.fromAsync(import_node_fs.default.promises.glob(globPattern));
|
|
53
|
+
const apiPackageJsonPath = import_node_path.default.join(cedarPaths.api.base, "package.json");
|
|
54
|
+
const apiPackageJson = JSON.parse(
|
|
55
|
+
import_node_fs.default.readFileSync(apiPackageJsonPath, "utf8")
|
|
56
|
+
);
|
|
57
|
+
const deps = {
|
|
58
|
+
...apiPackageJson.dependencies ?? {},
|
|
59
|
+
...apiPackageJson.devDependencies ?? {},
|
|
60
|
+
...apiPackageJson.peerDependencies ?? {}
|
|
61
|
+
};
|
|
62
|
+
const workspaceDepNames = /* @__PURE__ */ new Set();
|
|
63
|
+
for (const [name, version] of Object.entries(deps)) {
|
|
64
|
+
if (String(version).startsWith("workspace:")) {
|
|
65
|
+
workspaceDepNames.add(name);
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
for (const packageDir of packageDirs) {
|
|
69
|
+
const packageJsonPath = import_node_path.default.join(packageDir, "package.json");
|
|
70
|
+
if (!import_node_fs.default.existsSync(packageJsonPath)) {
|
|
71
|
+
continue;
|
|
72
|
+
}
|
|
73
|
+
const pkgJson = JSON.parse(import_node_fs.default.readFileSync(packageJsonPath, "utf8"));
|
|
74
|
+
if (workspaceDepNames.has(pkgJson.name)) {
|
|
75
|
+
packages.push(import_node_path.default.join(packageDir, "dist"));
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
} catch {
|
|
79
|
+
}
|
|
80
|
+
return packages;
|
|
81
|
+
}
|
|
82
|
+
async function apiIgnorePaths() {
|
|
83
|
+
const cedarPaths = (0, import_project_config.getPaths)();
|
|
84
|
+
const dbDir = await (0, import_project_config.getDbDir)(cedarPaths.api.prismaConfig);
|
|
85
|
+
if (dbDir === cedarPaths.api.base) {
|
|
86
|
+
throw new Error(
|
|
87
|
+
"Database directory cannot be the same as the API directory"
|
|
88
|
+
);
|
|
89
|
+
}
|
|
90
|
+
const ignoredApiPaths = [
|
|
91
|
+
// TODO: Is this still true?
|
|
92
|
+
// use this, because using cedarPaths.api.dist seems to not ignore on first
|
|
93
|
+
// build
|
|
94
|
+
"api/dist",
|
|
95
|
+
cedarPaths.api.types,
|
|
96
|
+
dbDir
|
|
97
|
+
];
|
|
98
|
+
return ignoredApiPaths;
|
|
99
|
+
}
|
|
100
|
+
async function getIgnoreFunction() {
|
|
101
|
+
const cedarPaths = (0, import_project_config.getPaths)();
|
|
102
|
+
const ignoredApiPaths = await apiIgnorePaths();
|
|
103
|
+
const ignoredExtensions = [
|
|
104
|
+
".DS_Store",
|
|
105
|
+
".db",
|
|
106
|
+
".sqlite",
|
|
107
|
+
"-journal",
|
|
108
|
+
".test.js",
|
|
109
|
+
".test.ts",
|
|
110
|
+
".scenarios.ts",
|
|
111
|
+
".scenarios.js",
|
|
112
|
+
".d.ts",
|
|
113
|
+
".log"
|
|
114
|
+
];
|
|
115
|
+
return (file) => {
|
|
116
|
+
if (file.includes("node_modules")) {
|
|
117
|
+
return true;
|
|
118
|
+
}
|
|
119
|
+
if (ignoredExtensions.some((ext) => file.endsWith(ext))) {
|
|
120
|
+
return true;
|
|
121
|
+
}
|
|
122
|
+
if (file.includes((0, import_project_config.importStatementPath)(cedarPaths.packages)) && file.includes("/src/")) {
|
|
123
|
+
return true;
|
|
124
|
+
}
|
|
125
|
+
if (ignoredApiPaths.some((ignoredPath) => file.includes(ignoredPath))) {
|
|
126
|
+
return true;
|
|
127
|
+
}
|
|
128
|
+
return false;
|
|
129
|
+
};
|
|
130
|
+
}
|
|
131
|
+
async function pathsToWatch() {
|
|
132
|
+
const cedarPaths = (0, import_project_config.getPaths)();
|
|
133
|
+
const watchPaths = [cedarPaths.api.src, ...await workspacePackagesPaths()];
|
|
134
|
+
return watchPaths.map((p) => (0, import_project_config.importStatementPath)(p));
|
|
135
|
+
}
|
|
136
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
137
|
+
0 && (module.exports = {
|
|
138
|
+
getIgnoreFunction,
|
|
139
|
+
pathsToWatch
|
|
140
|
+
});
|
package/dist/cliHelpers.d.ts
CHANGED
|
@@ -1,23 +1,6 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
* Whether this side receives the deployment's public traffic.
|
|
4
|
-
*
|
|
5
|
-
* Container hosts (Railway, Render, Fly.io, Cloud Run, Heroku) tell an app
|
|
6
|
-
* which host and port to bind with the `HOST` and `PORT` env vars. Only the
|
|
7
|
-
* side serving public traffic falls back to them — when the api and web
|
|
8
|
-
* servers run in the same deployment they would otherwise both bind to
|
|
9
|
-
* `PORT` and collide.
|
|
10
|
-
*
|
|
11
|
-
* The web side is the public one whenever both sides are served together,
|
|
12
|
-
* because it proxies api requests. The api side is only public when it is
|
|
13
|
-
* served on its own.
|
|
14
|
-
*/
|
|
15
|
-
isPublicSide?: boolean;
|
|
16
|
-
}
|
|
17
|
-
export declare function getAPIHost({ isPublicSide }?: SideOptions): string;
|
|
18
|
-
export declare function getAPIPort({ isPublicSide }?: SideOptions): number;
|
|
1
|
+
export declare function getAPIHost(): string;
|
|
2
|
+
export declare function getAPIPort(): number;
|
|
19
3
|
export declare function getAPIRootPath(): string;
|
|
20
|
-
export declare function getWebHost(
|
|
21
|
-
export declare function getWebPort(
|
|
22
|
-
export {};
|
|
4
|
+
export declare function getWebHost(): string;
|
|
5
|
+
export declare function getWebPort(): number;
|
|
23
6
|
//# sourceMappingURL=cliHelpers.d.ts.map
|
package/dist/cliHelpers.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"cliHelpers.d.ts","sourceRoot":"","sources":["../src/cliHelpers.ts"],"names":[],"mappings":"AAEA,
|
|
1
|
+
{"version":3,"file":"cliHelpers.d.ts","sourceRoot":"","sources":["../src/cliHelpers.ts"],"names":[],"mappings":"AAEA,wBAAgB,UAAU,WAKzB;AAED,wBAAgB,UAAU,WAIzB;AAED,wBAAgB,cAAc,WAE7B;AAED,wBAAgB,UAAU,WAKzB;AAED,wBAAgB,UAAU,WAIzB"}
|
package/dist/cliHelpers.js
CHANGED
|
@@ -1,52 +1,24 @@
|
|
|
1
|
-
import { getConfig
|
|
2
|
-
function getAPIHost(
|
|
3
|
-
let host =
|
|
4
|
-
deprecatedAlias: "REDWOOD_API_HOST"
|
|
5
|
-
});
|
|
6
|
-
if (isPublicSide) {
|
|
7
|
-
host ??= process.env.HOST;
|
|
8
|
-
}
|
|
1
|
+
import { getConfig } from "@cedarjs/project-config";
|
|
2
|
+
function getAPIHost() {
|
|
3
|
+
let host = process.env.REDWOOD_API_HOST;
|
|
9
4
|
host ??= getConfig().api.host;
|
|
10
|
-
host ??= "::";
|
|
5
|
+
host ??= process.env.NODE_ENV === "production" ? "0.0.0.0" : "::";
|
|
11
6
|
return host;
|
|
12
7
|
}
|
|
13
|
-
function getAPIPort(
|
|
14
|
-
|
|
15
|
-
deprecatedAlias: "REDWOOD_API_PORT"
|
|
16
|
-
});
|
|
17
|
-
if (apiPort) {
|
|
18
|
-
return parsePort(apiPort, "CEDAR_API_PORT");
|
|
19
|
-
}
|
|
20
|
-
if (isPublicSide && process.env.PORT) {
|
|
21
|
-
return parsePort(process.env.PORT, "PORT");
|
|
22
|
-
}
|
|
23
|
-
return getConfig().api.port;
|
|
8
|
+
function getAPIPort() {
|
|
9
|
+
return process.env.REDWOOD_API_PORT ? parseInt(process.env.REDWOOD_API_PORT) : getConfig().api.port;
|
|
24
10
|
}
|
|
25
11
|
function getAPIRootPath() {
|
|
26
12
|
return process.env.CEDAR_API_ROOT_PATH ?? "/";
|
|
27
13
|
}
|
|
28
|
-
function getWebHost(
|
|
29
|
-
let host =
|
|
30
|
-
deprecatedAlias: "REDWOOD_WEB_HOST"
|
|
31
|
-
});
|
|
32
|
-
if (isPublicSide) {
|
|
33
|
-
host ??= process.env.HOST;
|
|
34
|
-
}
|
|
14
|
+
function getWebHost() {
|
|
15
|
+
let host = process.env.REDWOOD_WEB_HOST;
|
|
35
16
|
host ??= getConfig().web.host;
|
|
36
|
-
host ??= "::";
|
|
17
|
+
host ??= process.env.NODE_ENV === "production" ? "0.0.0.0" : "::";
|
|
37
18
|
return host;
|
|
38
19
|
}
|
|
39
|
-
function getWebPort(
|
|
40
|
-
|
|
41
|
-
deprecatedAlias: "REDWOOD_WEB_PORT"
|
|
42
|
-
});
|
|
43
|
-
if (webPort) {
|
|
44
|
-
return parsePort(webPort, "CEDAR_WEB_PORT");
|
|
45
|
-
}
|
|
46
|
-
if (isPublicSide && process.env.PORT) {
|
|
47
|
-
return parsePort(process.env.PORT, "PORT");
|
|
48
|
-
}
|
|
49
|
-
return getConfig().web.port;
|
|
20
|
+
function getWebPort() {
|
|
21
|
+
return process.env.REDWOOD_WEB_PORT ? parseInt(process.env.REDWOOD_WEB_PORT) : getConfig().web.port;
|
|
50
22
|
}
|
|
51
23
|
export {
|
|
52
24
|
getAPIHost,
|
package/dist/createServer.d.ts
CHANGED
|
@@ -11,29 +11,13 @@ import type { CreateServerOptions, Server } from './createServerHelpers.js';
|
|
|
11
11
|
* const server = await createServer({
|
|
12
12
|
* logger,
|
|
13
13
|
* apiRootPath: 'api'
|
|
14
|
-
* configureServer: (server) => {
|
|
15
|
-
* // Runs before the api functions and GraphQL plugins are
|
|
16
|
-
* // registered, i.e. before any routes exist. This is the right
|
|
17
|
-
* // place for plugins with a "global" mode that hooks `onRoute`
|
|
18
|
-
* // (e.g. `@fastify/compress`), since those only affect routes
|
|
19
|
-
* // registered *after* the plugin itself — registering them here
|
|
20
|
-
* // applies them to *both* api functions and the GraphQL endpoint:
|
|
21
|
-
* server.register(compress, { global: true })
|
|
22
|
-
* },
|
|
23
14
|
* configureApiServer: (server) => {
|
|
24
|
-
* // Configure
|
|
25
|
-
* // content type parsers. Doesn't apply to the GraphQL endpoint.
|
|
26
|
-
* },
|
|
27
|
-
* configureGraphQLServer: (server) => {
|
|
28
|
-
* // Configure just the GraphQL fastify instance. Doesn't apply to
|
|
29
|
-
* // api function routes.
|
|
15
|
+
* // Configure the API server fastify instance, e.g. add content type parsers
|
|
30
16
|
* },
|
|
31
17
|
* })
|
|
32
18
|
*
|
|
33
|
-
* //
|
|
34
|
-
*
|
|
35
|
-
* // instance after the fact and will still apply to both:
|
|
36
|
-
* server.addHook('onRequest', myHook)
|
|
19
|
+
* // Configure the returned fastify instance:
|
|
20
|
+
* server.register(myPlugin)
|
|
37
21
|
*
|
|
38
22
|
* // When ready, start the server:
|
|
39
23
|
* await server.start()
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"createServer.d.ts","sourceRoot":"","sources":["../src/createServer.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"createServer.d.ts","sourceRoot":"","sources":["../src/createServer.ts"],"names":[],"mappings":"AAiBA,OAAO,KAAK,EACV,mBAAmB,EACnB,MAAM,EAEP,MAAM,0BAA0B,CAAA;AAsBjC;;;;;;;;;;;;;;;;;;;;;;;;;;GA0BG;AACH,wBAAsB,YAAY,CAAC,OAAO,GAAE,mBAAwB,mBAoHnE"}
|
package/dist/createServer.js
CHANGED
|
@@ -22,9 +22,7 @@ async function createServer(options = {}) {
|
|
|
22
22
|
apiRootPath,
|
|
23
23
|
fastifyServerOptions,
|
|
24
24
|
discoverFunctionsGlob,
|
|
25
|
-
configureServer,
|
|
26
25
|
configureApiServer,
|
|
27
|
-
configureGraphQLServer,
|
|
28
26
|
apiPort,
|
|
29
27
|
apiHost
|
|
30
28
|
} = resolveOptions(options);
|
|
@@ -63,11 +61,8 @@ async function createServer(options = {}) {
|
|
|
63
61
|
server.addHook("onRequest", (_req, _reply, done) => {
|
|
64
62
|
getAsyncStoreInstance().run(/* @__PURE__ */ new Map(), done);
|
|
65
63
|
});
|
|
66
|
-
if (configureServer) {
|
|
67
|
-
await configureServer(server);
|
|
68
|
-
}
|
|
69
64
|
await server.register(cedarFastifyAPI, {
|
|
70
|
-
|
|
65
|
+
redwood: {
|
|
71
66
|
apiRootPath,
|
|
72
67
|
fastGlobOptions: {
|
|
73
68
|
ignore: ["**/dist/functions/graphql.js"]
|
|
@@ -81,13 +76,12 @@ async function createServer(options = {}) {
|
|
|
81
76
|
absolute: true
|
|
82
77
|
});
|
|
83
78
|
if (graphqlFunctionPath) {
|
|
84
|
-
const {
|
|
79
|
+
const { redwoodFastifyGraphQLServer } = await import("./plugins/graphql.js");
|
|
85
80
|
const { __cedar_graphqlOptions } = await import(pathToFileURL(graphqlFunctionPath).href);
|
|
86
|
-
await server.register(
|
|
87
|
-
|
|
81
|
+
await server.register(redwoodFastifyGraphQLServer, {
|
|
82
|
+
redwood: {
|
|
88
83
|
apiRootPath,
|
|
89
|
-
graphql: __cedar_graphqlOptions
|
|
90
|
-
configureServer: configureGraphQLServer
|
|
84
|
+
graphql: __cedar_graphqlOptions
|
|
91
85
|
}
|
|
92
86
|
});
|
|
93
87
|
}
|
|
@@ -18,21 +18,8 @@ export interface CreateServerOptions {
|
|
|
18
18
|
* Defaults to: "dist/functions/**\/*.{ts,js}"
|
|
19
19
|
*/
|
|
20
20
|
discoverFunctionsGlob?: string | string[];
|
|
21
|
-
/**
|
|
22
|
-
|
|
23
|
-
* GraphQL plugins are registered. Use this to register Fastify plugins
|
|
24
|
-
* that need to run before any routes exist — most notably plugins with a
|
|
25
|
-
* "global" mode that works by hooking `onRoute` (e.g. `@fastify/compress`),
|
|
26
|
-
* which only affects routes registered *after* the plugin itself. Simple
|
|
27
|
-
* request-lifecycle hooks (`onRequest`, `onSend`, etc.) don't have this
|
|
28
|
-
* restriction and can also be added to the returned server after
|
|
29
|
-
* `createServer()` resolves.
|
|
30
|
-
*/
|
|
31
|
-
configureServer?: (server: FastifyInstance) => void | Promise<void>;
|
|
32
|
-
/** Customise the API functions fastify plugin before it is registered */
|
|
33
|
-
configureApiServer?: (server: FastifyInstance) => void | Promise<void>;
|
|
34
|
-
/** Customise the GraphQL fastify plugin before it is registered */
|
|
35
|
-
configureGraphQLServer?: (server: FastifyInstance) => void | Promise<void>;
|
|
21
|
+
/** Customise the API server fastify plugin before it is registered */
|
|
22
|
+
configureApiServer?: (server: Server) => void | Promise<void>;
|
|
36
23
|
/** Whether to parse args or not. Defaults to `true` */
|
|
37
24
|
parseArgs?: boolean;
|
|
38
25
|
/** The port to listen on. Defaults to what's configured in cedar.toml */
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"createServerHelpers.d.ts","sourceRoot":"","sources":["../src/createServerHelpers.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EACV,oBAAoB,EACpB,oBAAoB,EACpB,eAAe,EAChB,MAAM,SAAS,CAAA;AAMhB,MAAM,MAAM,YAAY,GAAG,IAAI,CAAC,oBAAoB,EAAE,MAAM,GAAG,MAAM,CAAC,CAAA;AAEtE,MAAM,WAAW,MAAO,SAAQ,eAAe;IAC7C,KAAK,EAAE,CAAC,OAAO,CAAC,EAAE,YAAY,KAAK,OAAO,CAAC,MAAM,CAAC,CAAA;CACnD;AAED,MAAM,WAAW,mBAAmB;IAClC,iDAAiD;IACjD,WAAW,CAAC,EAAE,MAAM,CAAA;IAGpB,iCAAiC;IACjC,MAAM,CAAC,EACH,oBAAoB,CAAC,QAAQ,CAAC,GAC9B,oBAAoB,CAAC,gBAAgB,CAAC,CAAA;IAE1C;;;OAGG;IACH,oBAAoB,CAAC,EAAE,IAAI,CAAC,oBAAoB,EAAE,QAAQ,CAAC,CAAA;IAE3D;;;OAGG;IACH,qBAAqB,CAAC,EAAE,MAAM,GAAG,MAAM,EAAE,CAAA;IAEzC
|
|
1
|
+
{"version":3,"file":"createServerHelpers.d.ts","sourceRoot":"","sources":["../src/createServerHelpers.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EACV,oBAAoB,EACpB,oBAAoB,EACpB,eAAe,EAChB,MAAM,SAAS,CAAA;AAMhB,MAAM,MAAM,YAAY,GAAG,IAAI,CAAC,oBAAoB,EAAE,MAAM,GAAG,MAAM,CAAC,CAAA;AAEtE,MAAM,WAAW,MAAO,SAAQ,eAAe;IAC7C,KAAK,EAAE,CAAC,OAAO,CAAC,EAAE,YAAY,KAAK,OAAO,CAAC,MAAM,CAAC,CAAA;CACnD;AAED,MAAM,WAAW,mBAAmB;IAClC,iDAAiD;IACjD,WAAW,CAAC,EAAE,MAAM,CAAA;IAGpB,iCAAiC;IACjC,MAAM,CAAC,EACH,oBAAoB,CAAC,QAAQ,CAAC,GAC9B,oBAAoB,CAAC,gBAAgB,CAAC,CAAA;IAE1C;;;OAGG;IACH,oBAAoB,CAAC,EAAE,IAAI,CAAC,oBAAoB,EAAE,QAAQ,CAAC,CAAA;IAE3D;;;OAGG;IACH,qBAAqB,CAAC,EAAE,MAAM,GAAG,MAAM,EAAE,CAAA;IAEzC,sEAAsE;IACtE,kBAAkB,CAAC,EAAE,CAAC,MAAM,EAAE,MAAM,KAAK,IAAI,GAAG,OAAO,CAAC,IAAI,CAAC,CAAA;IAE7D,uDAAuD;IACvD,SAAS,CAAC,EAAE,OAAO,CAAA;IAEnB,yEAAyE;IACzE,OAAO,CAAC,EAAE,MAAM,CAAA;IAEhB,uEAAuE;IACvE,OAAO,CAAC,EAAE,MAAM,CAAA;CACjB;AAED,KAAK,0BAA0B,GAAG,QAAQ,CACxC,IAAI,CAAC,mBAAmB,EAAE,sBAAsB,CAAC,GAAG;IAClD,oBAAoB,EAAE,oBAAoB,CAAA;CAC3C,CACF,CAAA;AAID,eAAO,MAAM,6BAA6B,EAAE,MAAM,0BAiB9C,CAAA;AAgBJ,wBAAgB,cAAc,CAC5B,OAAO,GAAE,mBAAwB,EACjC,IAAI,CAAC,EAAE,MAAM,EAAE;0BAdS,oBAAoB;GA4F7C"}
|
|
@@ -12,19 +12,11 @@ const getDefaultCreateServerOptions = () => ({
|
|
|
12
12
|
// 100MB
|
|
13
13
|
},
|
|
14
14
|
discoverFunctionsGlob: "dist/functions/**/*.{ts,js}",
|
|
15
|
-
configureServer: () => {
|
|
16
|
-
},
|
|
17
15
|
configureApiServer: () => {
|
|
18
16
|
},
|
|
19
|
-
configureGraphQLServer: () => {
|
|
20
|
-
},
|
|
21
17
|
parseArgs: true,
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
// serving public traffic on its own, so they get to use the host's
|
|
25
|
-
// `HOST`/`PORT` env vars.
|
|
26
|
-
apiHost: getAPIHost({ isPublicSide: true }),
|
|
27
|
-
apiPort: getAPIPort({ isPublicSide: true })
|
|
18
|
+
apiHost: getAPIHost(),
|
|
19
|
+
apiPort: getAPIPort()
|
|
28
20
|
});
|
|
29
21
|
function isCustomLoggerInstance(logger) {
|
|
30
22
|
return !!logger && typeof logger === "object" && "info" in logger;
|
|
@@ -40,9 +32,7 @@ function resolveOptions(options = {}, args) {
|
|
|
40
32
|
bodyLimit: defaults.fastifyServerOptions.bodyLimit
|
|
41
33
|
},
|
|
42
34
|
discoverFunctionsGlob: options.discoverFunctionsGlob ?? defaults.discoverFunctionsGlob,
|
|
43
|
-
configureServer: options.configureServer ?? defaults.configureServer,
|
|
44
35
|
configureApiServer: options.configureApiServer ?? defaults.configureApiServer,
|
|
45
|
-
configureGraphQLServer: options.configureGraphQLServer ?? defaults.configureGraphQLServer,
|
|
46
36
|
apiHost: options.apiHost ?? defaults.apiHost,
|
|
47
37
|
apiPort: options.apiPort ?? defaults.apiPort
|
|
48
38
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"formatters.d.ts","sourceRoot":"","sources":["../../src/logFormatter/formatters.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"formatters.d.ts","sourceRoot":"","sources":["../../src/logFormatter/formatters.ts"],"names":[],"mappings":"AAOA,eAAO,MAAM,OAAO,OAAO,CAAA;AAE3B,eAAO,MAAM,QAAQ,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAO3C,CAAA;AAED,eAAO,MAAM,iBAAiB,EAAE,MAAM,EASrC,CAAA;AAED,eAAO,MAAM,QAAQ,GAAI,SAAS,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,wBAExD,CAAA;AAED,eAAO,MAAM,aAAa,GAAI,SAAS,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,wBAE7D,CAAA;AAED,eAAO,MAAM,SAAS,GAAI,MAAM,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,wBAEtD,CAAA;AAED,eAAO,MAAM,WAAW,GAAI,WAAW,MAAM,YAE5C,CAAA;AAED,eAAO,MAAM,gBAAgB,GAAI,QAAQ,MAAM,WAI9C,CAAA;AAED,eAAO,MAAM,YAAY,GAAI,QAAQ,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,uBAgB3D,CAAA;AAED,eAAO,MAAM,UAAU,GAAI,OAAO,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,uBAQxD,CAAA;AAED,eAAO,MAAM,UAAU,GAAI,SAAS,IAAI,WAOvC,CAAA;AAED,eAAO,MAAM,eAAe,GAAI,gBAAgB,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,WAgBtE,CAAA;AAED,eAAO,MAAM,WAAW,GAAI,OAAO,GAAG,WAIrC,CAAA;AAED,eAAO,MAAM,cAAc,GAAI,aAAa,MAAM,WAIjD,CAAA;AAED,eAAO,MAAM,aAAa,GAAI,SAAS,GAAG,uBAyBzC,CAAA;AAED,eAAO,MAAM,YAAY,GAAI,QAAQ,MAAM,WAE1C,CAAA;AAED,eAAO,MAAM,eAAe,GAAI,WAAW,MAAM,WAEhD,CAAA;AAED,eAAO,MAAM,QAAQ,GAAI,IAAI,MAAM,WAElC,CAAA;AAED,eAAO,MAAM,UAAU,GAAI,MAAM,MAAM,WAEtC,CAAA;AAED,eAAO,MAAM,iBAAiB,GAAI,SAAS,MAAM,WAYhD,CAAA;AAED,eAAO,MAAM,mBAAmB,GAAI,eAAe,MAAM,WAExD,CAAA;AAED,eAAO,MAAM,WAAW,GAAI,QAAQ,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,uBAQ1D,CAAA;AAED,eAAO,MAAM,mBAAmB,GAC9B,gBAAgB,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,uBAYxC,CAAA;AAED,eAAO,MAAM,gBAAgB,GAAI,YAAY,MAAM,WAGlD,CAAA;AAED,eAAO,MAAM,WAAW,GAAI,QAAQ,MAAM,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,WAMnE,CAAA;AAED,eAAO,MAAM,aAAa,GAAI,OAAO,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,uBAQ3D,CAAA;AAED,eAAO,MAAM,SAAS,GAAI,KAAK,MAAM,WAEpC,CAAA;AAED,eAAO,MAAM,eAAe,GAAI,WAAW,MAAM,WAEhD,CAAA;AAED,eAAO,MAAM,OAAO,GAAI,OAAO,GAAG,YAEjC,CAAA"}
|
package/dist/plugins/api.d.ts
CHANGED
|
@@ -1,12 +1,13 @@
|
|
|
1
1
|
import type { Options as FastGlobOptions } from 'fast-glob';
|
|
2
2
|
import type { FastifyInstance } from 'fastify';
|
|
3
|
+
import type { Server } from '../createServerHelpers.js';
|
|
3
4
|
export interface CedarFastifyAPIOptions {
|
|
4
|
-
|
|
5
|
+
redwood: {
|
|
5
6
|
apiRootPath?: string;
|
|
6
7
|
fastGlobOptions?: FastGlobOptions;
|
|
7
8
|
discoverFunctionsGlob?: string | string[];
|
|
8
9
|
loadUserConfig?: boolean;
|
|
9
|
-
configureServer?: (server:
|
|
10
|
+
configureServer?: (server: Server) => void | Promise<void>;
|
|
10
11
|
};
|
|
11
12
|
}
|
|
12
13
|
export declare function cedarFastifyAPI(fastify: FastifyInstance, opts: CedarFastifyAPIOptions): Promise<void>;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"api.d.ts","sourceRoot":"","sources":["../../src/plugins/api.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,OAAO,IAAI,eAAe,EAAE,MAAM,WAAW,CAAA;AAC3D,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,SAAS,CAAA;
|
|
1
|
+
{"version":3,"file":"api.d.ts","sourceRoot":"","sources":["../../src/plugins/api.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,OAAO,IAAI,eAAe,EAAE,MAAM,WAAW,CAAA;AAC3D,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,SAAS,CAAA;AAO9C,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,2BAA2B,CAAA;AAKvD,MAAM,WAAW,sBAAsB;IAErC,OAAO,EAAE;QACP,WAAW,CAAC,EAAE,MAAM,CAAA;QACpB,eAAe,CAAC,EAAE,eAAe,CAAA;QACjC,qBAAqB,CAAC,EAAE,MAAM,GAAG,MAAM,EAAE,CAAA;QACzC,cAAc,CAAC,EAAE,OAAO,CAAA;QACxB,eAAe,CAAC,EAAE,CAAC,MAAM,EAAE,MAAM,KAAK,IAAI,GAAG,OAAO,CAAC,IAAI,CAAC,CAAA;KAI3D,CAAA;CACF;AAED,wBAAsB,eAAe,CACnC,OAAO,EAAE,eAAe,EACxB,IAAI,EAAE,sBAAsB,iBA4C7B"}
|
package/dist/plugins/api.js
CHANGED
|
@@ -5,7 +5,7 @@ import { coerceRootPath } from "@cedarjs/fastify-web/dist/helpers.js";
|
|
|
5
5
|
import { loadFastifyConfig } from "../fastify.js";
|
|
6
6
|
import { lambdaRequestHandler, loadFunctionsFromDist } from "./lambdaLoader.js";
|
|
7
7
|
async function cedarFastifyAPI(fastify, opts) {
|
|
8
|
-
const cedarOptions = opts.
|
|
8
|
+
const cedarOptions = opts.redwood ?? {};
|
|
9
9
|
cedarOptions.apiRootPath ??= "/";
|
|
10
10
|
cedarOptions.apiRootPath = coerceRootPath(cedarOptions.apiRootPath);
|
|
11
11
|
cedarOptions.fastGlobOptions ??= {};
|
|
@@ -1,27 +1,10 @@
|
|
|
1
1
|
import type { FastifyInstance } from 'fastify';
|
|
2
2
|
import type { GraphQLYogaOptions } from '@cedarjs/graphql-server';
|
|
3
|
-
export interface
|
|
4
|
-
|
|
3
|
+
export interface RedwoodFastifyGraphQLOptions {
|
|
4
|
+
redwood: {
|
|
5
5
|
apiRootPath?: string;
|
|
6
6
|
graphql?: GraphQLYogaOptions;
|
|
7
|
-
configureServer?: (server: FastifyInstance) => void | Promise<void>;
|
|
8
7
|
};
|
|
9
8
|
}
|
|
10
|
-
export declare function
|
|
11
|
-
/**
|
|
12
|
-
* Detects errors that indicate the client disconnected before the response
|
|
13
|
-
* finished, rather than a genuine server-side failure.
|
|
14
|
-
*
|
|
15
|
-
* `ERR_STREAM_PREMATURE_CLOSE` can surface from the underlying Node stream
|
|
16
|
-
* closing early. The `DOMException` named `AbortError` is thrown by Yoga
|
|
17
|
-
* when the AbortSignal wired up in `createFetchRequest`'s
|
|
18
|
-
* `reply.raw.on('close', ...)` handler is aborted, which only happens when
|
|
19
|
-
* the client itself has gone away.
|
|
20
|
-
*
|
|
21
|
-
* The `DOMException` check (rather than just `name === 'AbortError'`) is
|
|
22
|
-
* deliberate: a resolver or hook could throw a plain `Error` renamed to
|
|
23
|
-
* `AbortError`, which would otherwise be misclassified as a benign
|
|
24
|
-
* disconnect and hide a real server-side failure behind a 499.
|
|
25
|
-
*/
|
|
26
|
-
export declare function isClientDisconnectError(e: unknown): boolean;
|
|
9
|
+
export declare function redwoodFastifyGraphQLServer(fastify: FastifyInstance, options: RedwoodFastifyGraphQLOptions): Promise<void>;
|
|
27
10
|
//# sourceMappingURL=graphql.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"graphql.d.ts","sourceRoot":"","sources":["../../src/plugins/graphql.ts"],"names":[],"mappings":"AAKA,OAAO,KAAK,EACV,eAAe,EAIhB,MAAM,SAAS,CAAA;AAOhB,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,yBAAyB,CAAA;AAKjE,MAAM,WAAW,
|
|
1
|
+
{"version":3,"file":"graphql.d.ts","sourceRoot":"","sources":["../../src/plugins/graphql.ts"],"names":[],"mappings":"AAKA,OAAO,KAAK,EACV,eAAe,EAIhB,MAAM,SAAS,CAAA;AAOhB,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,yBAAyB,CAAA;AAKjE,MAAM,WAAW,4BAA4B;IAC3C,OAAO,EAAE;QACP,WAAW,CAAC,EAAE,MAAM,CAAA;QACpB,OAAO,CAAC,EAAE,kBAAkB,CAAA;KAC7B,CAAA;CACF;AAED,wBAAsB,2BAA2B,CAC/C,OAAO,EAAE,eAAe,EACxB,OAAO,EAAE,4BAA4B,iBAuHtC"}
|
package/dist/plugins/graphql.js
CHANGED
|
@@ -2,27 +2,24 @@ import { pathToFileURL } from "node:url";
|
|
|
2
2
|
import fastifyMultiPart from "@fastify/multipart";
|
|
3
3
|
import fastifyUrlData from "@fastify/url-data";
|
|
4
4
|
import fg from "fast-glob";
|
|
5
|
-
import { buildCedarContext } from "@cedarjs/api/runtime";
|
|
5
|
+
import { buildCedarContext, noopAuthDecoder } from "@cedarjs/api/runtime";
|
|
6
6
|
import { getAsyncStoreInstance } from "@cedarjs/context/dist/store";
|
|
7
7
|
import { coerceRootPath } from "@cedarjs/fastify-web/dist/helpers.js";
|
|
8
8
|
import { createGraphQLYoga } from "@cedarjs/graphql-server";
|
|
9
9
|
import { getPaths } from "@cedarjs/project-config";
|
|
10
10
|
import { lambdaEventForFastifyRequest } from "../requestHandlers/awsLambdaFastify.js";
|
|
11
|
-
async function
|
|
12
|
-
const
|
|
13
|
-
|
|
14
|
-
|
|
11
|
+
async function redwoodFastifyGraphQLServer(fastify, options) {
|
|
12
|
+
const redwoodOptions = options.redwood ?? {};
|
|
13
|
+
redwoodOptions.apiRootPath ??= "/";
|
|
14
|
+
redwoodOptions.apiRootPath = coerceRootPath(redwoodOptions.apiRootPath);
|
|
15
15
|
fastify.register(fastifyUrlData);
|
|
16
16
|
fastify.register(fastifyMultiPart);
|
|
17
17
|
const method = ["GET", "POST", "OPTIONS"];
|
|
18
18
|
fastify.addHook("onRequest", (_req, _reply, done) => {
|
|
19
19
|
getAsyncStoreInstance().run(/* @__PURE__ */ new Map(), done);
|
|
20
20
|
});
|
|
21
|
-
if (cedarOptions.configureServer) {
|
|
22
|
-
await cedarOptions.configureServer(fastify);
|
|
23
|
-
}
|
|
24
21
|
try {
|
|
25
|
-
if (!
|
|
22
|
+
if (!redwoodOptions.graphql) {
|
|
26
23
|
const [graphqlFunctionPath] = await fg("dist/functions/graphql.{ts,js}", {
|
|
27
24
|
cwd: getPaths().api.base,
|
|
28
25
|
absolute: true
|
|
@@ -32,9 +29,9 @@ async function cedarFastifyGraphQLServer(fastify, options) {
|
|
|
32
29
|
if (!__cedar_graphqlOptions) {
|
|
33
30
|
return;
|
|
34
31
|
}
|
|
35
|
-
|
|
32
|
+
redwoodOptions.graphql = __cedar_graphqlOptions;
|
|
36
33
|
}
|
|
37
|
-
const graphqlOptions =
|
|
34
|
+
const graphqlOptions = redwoodOptions.graphql;
|
|
38
35
|
if (graphqlOptions?.realtime?.subscriptions) {
|
|
39
36
|
method.push("PUT");
|
|
40
37
|
}
|
|
@@ -43,12 +40,12 @@ async function cedarFastifyGraphQLServer(fastify, options) {
|
|
|
43
40
|
const routePaths = ["", "/health", "/readiness", "/stream"];
|
|
44
41
|
for (const routePath of routePaths) {
|
|
45
42
|
fastify.route({
|
|
46
|
-
url: `${
|
|
43
|
+
url: `${redwoodOptions.apiRootPath}${graphqlEndpoint}${routePath}`,
|
|
47
44
|
method,
|
|
48
45
|
handler: async (req, reply) => {
|
|
49
46
|
const request = createFetchRequest(req, reply);
|
|
50
47
|
const cedarContext = await buildCedarContext(request, {
|
|
51
|
-
authDecoder: graphqlOptions.authDecoder
|
|
48
|
+
authDecoder: graphqlOptions.authDecoder ?? noopAuthDecoder
|
|
52
49
|
});
|
|
53
50
|
try {
|
|
54
51
|
return await yoga.handle(request, {
|
|
@@ -58,7 +55,7 @@ async function cedarFastifyGraphQLServer(fastify, options) {
|
|
|
58
55
|
requestContext: void 0
|
|
59
56
|
});
|
|
60
57
|
} catch (e) {
|
|
61
|
-
if (
|
|
58
|
+
if (!!e && typeof e === "object" && "code" in e && e.code === "ERR_STREAM_PREMATURE_CLOSE") {
|
|
62
59
|
return new Response(null, { status: 499 });
|
|
63
60
|
}
|
|
64
61
|
throw e;
|
|
@@ -77,26 +74,12 @@ async function cedarFastifyGraphQLServer(fastify, options) {
|
|
|
77
74
|
done();
|
|
78
75
|
});
|
|
79
76
|
} catch (e) {
|
|
80
|
-
|
|
81
|
-
fastify.log.error(e, `Failed to set up the GraphQL server: ${message}`);
|
|
82
|
-
throw e;
|
|
77
|
+
console.log(e);
|
|
83
78
|
}
|
|
84
79
|
}
|
|
85
80
|
function trimSlashes(path) {
|
|
86
81
|
return path.replace(/^\/|\/$/g, "");
|
|
87
82
|
}
|
|
88
|
-
function isClientDisconnectError(e) {
|
|
89
|
-
if (!e || typeof e !== "object") {
|
|
90
|
-
return false;
|
|
91
|
-
}
|
|
92
|
-
if ("code" in e && e.code === "ERR_STREAM_PREMATURE_CLOSE") {
|
|
93
|
-
return true;
|
|
94
|
-
}
|
|
95
|
-
if (e instanceof DOMException && e.name === "AbortError") {
|
|
96
|
-
return true;
|
|
97
|
-
}
|
|
98
|
-
return false;
|
|
99
|
-
}
|
|
100
83
|
function createFetchRequest(req, reply) {
|
|
101
84
|
const controller = new AbortController();
|
|
102
85
|
reply.raw.on("close", () => {
|
|
@@ -114,6 +97,5 @@ function createFetchRequest(req, reply) {
|
|
|
114
97
|
});
|
|
115
98
|
}
|
|
116
99
|
export {
|
|
117
|
-
|
|
118
|
-
isClientDisconnectError
|
|
100
|
+
redwoodFastifyGraphQLServer
|
|
119
101
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"lambdaLoader.d.ts","sourceRoot":"","sources":["../../src/plugins/lambdaLoader.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"lambdaLoader.d.ts","sourceRoot":"","sources":["../../src/plugins/lambdaLoader.ts"],"names":[],"mappings":"AAOA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,YAAY,CAAA;AAEzC,OAAO,KAAK,EAAE,OAAO,IAAI,eAAe,EAAE,MAAM,WAAW,CAAA;AAC3D,OAAO,KAAK,EACV,YAAY,EACZ,cAAc,EACd,uBAAuB,EACxB,MAAM,SAAS,CAAA;AAGhB,OAAO,KAAK,EACV,YAAY,EACZ,gBAAgB,EAEjB,MAAM,sBAAsB,CAAA;AAO7B,eAAO,MAAM,gBAAgB,sBAA6B,CAAA;AAC1D,eAAO,MAAM,cAAc,2BAAkC,CAAA;AAG7D;;;;;GAKG;AACH,eAAO,MAAM,qBAAqB,0BAAgC,CAAA;AAIlE,eAAO,MAAM,kBAAkB,GAAU,gBAAgB,MAAM,EAAE,kBAuGhE,CAAA;AAED,KAAK,4BAA4B,GAAG;IAClC,eAAe,CAAC,EAAE,eAAe,CAAA;IACjC,qBAAqB,CAAC,EAAE,MAAM,GAAG,MAAM,EAAE,CAAA;CAC1C,CAAA;AAGD,eAAO,MAAM,qBAAqB,GAChC,UAAS,4BAAiC,kBAe3C,CAAA;AA0BD,UAAU,oBAAqB,SAAQ,uBAAuB;IAC5D,MAAM,EAAE;QACN,SAAS,EAAE,MAAM,CAAA;KAClB,CAAA;CACF;AAED;;;;;;GAMG;AACH,eAAO,MAAM,oBAAoB,GAC/B,KAAK,cAAc,CAAC,oBAAoB,CAAC,EACzC,OAAO,YAAY,kBAqEpB,CAAA"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"serverManager.d.ts","sourceRoot":"","sources":["../src/serverManager.ts"],"names":[],"mappings":"AA6BA,qBAAa,aAAa;IACxB,OAAO,CAAC,iBAAiB,CAA4B;YAEvC,cAAc;IAyDtB,gBAAgB;IAKhB,aAAa;CAmCpB;AAED,eAAO,MAAM,aAAa,eAAsB,CAAA"}
|