@cedarjs/api-server 1.0.0-canary.12509 → 1.0.0-canary.12511
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 +8 -7
- package/dist/apiCLIConfig.js +2 -38
- package/dist/apiCLIConfigHandler.d.ts.map +1 -1
- package/dist/apiCLIConfigHandler.js +11 -45
- package/dist/bin.js +118 -141
- package/dist/bothCLIConfig.js +2 -38
- package/dist/bothCLIConfigHandler.d.ts.map +1 -1
- package/dist/bothCLIConfigHandler.js +20 -54
- package/dist/buildManager.js +4 -28
- 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 +907 -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 +74 -0
- package/dist/cjs/cliHelpers.d.ts +5 -0
- package/dist/cjs/cliHelpers.d.ts.map +1 -0
- package/dist/cjs/cliHelpers.js +52 -0
- package/dist/cjs/createServer.d.ts +30 -0
- package/dist/cjs/createServer.d.ts.map +1 -0
- package/dist/cjs/createServer.js +144 -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 +14 -0
- package/dist/cjs/fastify.d.ts.map +1 -0
- package/dist/cjs/fastify.js +93 -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 +119 -0
- package/dist/cjs/plugins/lambdaLoader.d.ts +24 -0
- package/dist/cjs/plugins/lambdaLoader.d.ts.map +1 -0
- package/dist/cjs/plugins/lambdaLoader.js +134 -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 +103 -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 +2 -0
- package/dist/cjs/watch.d.ts.map +1 -0
- package/dist/cjs/watch.js +292 -0
- package/dist/cliHelpers.js +7 -34
- package/dist/createServer.d.ts.map +1 -1
- package/dist/createServer.js +27 -61
- package/dist/createServerHelpers.js +9 -34
- package/dist/fastify.js +17 -53
- package/dist/logFormatter/ambient.d.js +0 -1
- package/dist/logFormatter/bin.js +33 -56
- package/dist/logFormatter/formatters.d.ts.map +1 -1
- package/dist/logFormatter/formatters.js +31 -93
- package/dist/logFormatter/index.js +58 -67
- package/dist/plugins/api.js +16 -50
- package/dist/plugins/graphql.js +18 -52
- package/dist/plugins/lambdaLoader.d.ts.map +1 -1
- package/dist/plugins/lambdaLoader.js +19 -56
- package/dist/requestHandlers/awsLambdaFastify.js +7 -42
- package/dist/requestHandlers/utils.js +2 -27
- package/dist/serverManager.d.ts.map +1 -1
- package/dist/serverManager.js +25 -61
- package/dist/utils.js +2 -27
- package/dist/watch.js +50 -70
- package/package.json +20 -13
package/dist/bin.js
CHANGED
|
@@ -1,11 +1,6 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
"use strict";
|
|
3
|
-
var __create = Object.create;
|
|
4
2
|
var __defProp = Object.defineProperty;
|
|
5
|
-
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
6
3
|
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
7
|
-
var __getProtoOf = Object.getPrototypeOf;
|
|
8
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
9
4
|
var __esm = (fn, res) => function __init() {
|
|
10
5
|
return fn && (res = (0, fn[__getOwnPropNames(fn)[0]])(fn = 0)), res;
|
|
11
6
|
};
|
|
@@ -13,51 +8,36 @@ var __export = (target, all) => {
|
|
|
13
8
|
for (var name in all)
|
|
14
9
|
__defProp(target, name, { get: all[name], enumerable: true });
|
|
15
10
|
};
|
|
16
|
-
var __copyProps = (to, from, except, desc) => {
|
|
17
|
-
if (from && typeof from === "object" || typeof from === "function") {
|
|
18
|
-
for (let key of __getOwnPropNames(from))
|
|
19
|
-
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
20
|
-
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
21
|
-
}
|
|
22
|
-
return to;
|
|
23
|
-
};
|
|
24
|
-
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
25
|
-
// If the importer is in node compatibility mode or this is not an ESM
|
|
26
|
-
// file that has been converted to a CommonJS file using a Babel-
|
|
27
|
-
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
28
|
-
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
29
|
-
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
30
|
-
mod
|
|
31
|
-
));
|
|
32
11
|
|
|
33
12
|
// src/cliHelpers.ts
|
|
13
|
+
import { getConfig } from "@cedarjs/project-config";
|
|
34
14
|
function getAPIHost() {
|
|
35
15
|
let host = process.env.REDWOOD_API_HOST;
|
|
36
|
-
host ??=
|
|
16
|
+
host ??= getConfig().api.host;
|
|
37
17
|
host ??= process.env.NODE_ENV === "production" ? "0.0.0.0" : "::";
|
|
38
18
|
return host;
|
|
39
19
|
}
|
|
40
20
|
function getAPIPort() {
|
|
41
|
-
return process.env.REDWOOD_API_PORT ? parseInt(process.env.REDWOOD_API_PORT) :
|
|
21
|
+
return process.env.REDWOOD_API_PORT ? parseInt(process.env.REDWOOD_API_PORT) : getConfig().api.port;
|
|
42
22
|
}
|
|
43
23
|
function getWebHost() {
|
|
44
24
|
let host = process.env.REDWOOD_WEB_HOST;
|
|
45
|
-
host ??=
|
|
25
|
+
host ??= getConfig().web.host;
|
|
46
26
|
host ??= process.env.NODE_ENV === "production" ? "0.0.0.0" : "::";
|
|
47
27
|
return host;
|
|
48
28
|
}
|
|
49
29
|
function getWebPort() {
|
|
50
|
-
return process.env.REDWOOD_WEB_PORT ? parseInt(process.env.REDWOOD_WEB_PORT) :
|
|
30
|
+
return process.env.REDWOOD_WEB_PORT ? parseInt(process.env.REDWOOD_WEB_PORT) : getConfig().web.port;
|
|
51
31
|
}
|
|
52
|
-
var import_project_config;
|
|
53
32
|
var init_cliHelpers = __esm({
|
|
54
33
|
"src/cliHelpers.ts"() {
|
|
55
34
|
"use strict";
|
|
56
|
-
import_project_config = require("@cedarjs/project-config");
|
|
57
35
|
}
|
|
58
36
|
});
|
|
59
37
|
|
|
60
38
|
// src/createServerHelpers.ts
|
|
39
|
+
import { parseArgs } from "util";
|
|
40
|
+
import { coerceRootPath } from "@cedarjs/fastify-web/dist/helpers.js";
|
|
61
41
|
function isCustomLoggerInstance(logger) {
|
|
62
42
|
return !!logger && typeof logger === "object" && "info" in logger;
|
|
63
43
|
}
|
|
@@ -83,7 +63,7 @@ function resolveOptions(options = {}, args) {
|
|
|
83
63
|
resolvedOptions.fastifyServerOptions.logger = logger;
|
|
84
64
|
}
|
|
85
65
|
if (options.parseArgs) {
|
|
86
|
-
const { values } =
|
|
66
|
+
const { values } = parseArgs({
|
|
87
67
|
options: {
|
|
88
68
|
apiHost: {
|
|
89
69
|
type: "string"
|
|
@@ -118,15 +98,13 @@ function resolveOptions(options = {}, args) {
|
|
|
118
98
|
resolvedOptions.apiRootPath = values.apiRootPath;
|
|
119
99
|
}
|
|
120
100
|
}
|
|
121
|
-
resolvedOptions.apiRootPath =
|
|
101
|
+
resolvedOptions.apiRootPath = coerceRootPath(resolvedOptions.apiRootPath);
|
|
122
102
|
return resolvedOptions;
|
|
123
103
|
}
|
|
124
|
-
var
|
|
104
|
+
var getDefaultCreateServerOptions;
|
|
125
105
|
var init_createServerHelpers = __esm({
|
|
126
106
|
"src/createServerHelpers.ts"() {
|
|
127
107
|
"use strict";
|
|
128
|
-
import_util = require("util");
|
|
129
|
-
import_helpers = require("@cedarjs/fastify-web/dist/helpers");
|
|
130
108
|
init_cliHelpers();
|
|
131
109
|
getDefaultCreateServerOptions = () => ({
|
|
132
110
|
apiRootPath: "/",
|
|
@@ -149,36 +127,36 @@ var init_createServerHelpers = __esm({
|
|
|
149
127
|
});
|
|
150
128
|
|
|
151
129
|
// src/fastify.ts
|
|
130
|
+
import fs from "fs";
|
|
131
|
+
import path from "path";
|
|
132
|
+
import { pathToFileURL } from "url";
|
|
133
|
+
import Fastify from "fastify";
|
|
134
|
+
import { getAsyncStoreInstance } from "@cedarjs/context/dist/store";
|
|
135
|
+
import { getPaths, getConfig as getConfig2 } from "@cedarjs/project-config";
|
|
152
136
|
async function loadFastifyConfig() {
|
|
153
|
-
const serverConfigPath =
|
|
154
|
-
|
|
155
|
-
(
|
|
137
|
+
const serverConfigPath = path.join(
|
|
138
|
+
getPaths().base,
|
|
139
|
+
getConfig2().api.serverConfig
|
|
156
140
|
);
|
|
157
|
-
if (!
|
|
141
|
+
if (!fs.existsSync(serverConfigPath)) {
|
|
158
142
|
return serverConfigFile;
|
|
159
143
|
}
|
|
160
144
|
if (!isServerConfigLoaded) {
|
|
161
145
|
console.log(`Loading server config from ${serverConfigPath}`);
|
|
162
146
|
console.log(`Loading server config from URL file://${serverConfigPath}`);
|
|
163
147
|
console.log(
|
|
164
|
-
`Loading server config from URL ${
|
|
148
|
+
`Loading server config from URL ${pathToFileURL(serverConfigPath).href}`
|
|
165
149
|
);
|
|
166
|
-
const config3 = await import(
|
|
150
|
+
const config3 = await import(pathToFileURL(serverConfigPath).href);
|
|
167
151
|
serverConfigFile = { ...config3.default };
|
|
168
152
|
isServerConfigLoaded = true;
|
|
169
153
|
}
|
|
170
154
|
return serverConfigFile;
|
|
171
155
|
}
|
|
172
|
-
var
|
|
156
|
+
var DEFAULT_OPTIONS, isServerConfigLoaded, serverConfigFile, createFastifyInstance, fastify_default;
|
|
173
157
|
var init_fastify = __esm({
|
|
174
158
|
"src/fastify.ts"() {
|
|
175
159
|
"use strict";
|
|
176
|
-
import_fs = __toESM(require("fs"));
|
|
177
|
-
import_path = __toESM(require("path"));
|
|
178
|
-
import_url = require("url");
|
|
179
|
-
import_fastify = __toESM(require("fastify"));
|
|
180
|
-
import_store = require("@cedarjs/context/dist/store");
|
|
181
|
-
import_project_config2 = require("@cedarjs/project-config");
|
|
182
160
|
DEFAULT_OPTIONS = {
|
|
183
161
|
logger: {
|
|
184
162
|
level: process.env.NODE_ENV === "development" ? "debug" : "info"
|
|
@@ -197,9 +175,9 @@ var init_fastify = __esm({
|
|
|
197
175
|
};
|
|
198
176
|
createFastifyInstance = async (options) => {
|
|
199
177
|
const { config: config3 } = await loadFastifyConfig();
|
|
200
|
-
const fastify2 = (
|
|
178
|
+
const fastify2 = Fastify(options || config3 || DEFAULT_OPTIONS);
|
|
201
179
|
fastify2.addHook("onRequest", (_req, _reply, done) => {
|
|
202
|
-
|
|
180
|
+
getAsyncStoreInstance().run(/* @__PURE__ */ new Map(), done);
|
|
203
181
|
});
|
|
204
182
|
return fastify2;
|
|
205
183
|
};
|
|
@@ -242,18 +220,18 @@ var init_utils = __esm({
|
|
|
242
220
|
});
|
|
243
221
|
|
|
244
222
|
// src/requestHandlers/awsLambdaFastify.ts
|
|
245
|
-
|
|
223
|
+
import qs from "qs";
|
|
224
|
+
var lambdaEventForFastifyRequest, fastifyResponseForLambdaResult, fastifyResponseForLambdaError, requestHandler;
|
|
246
225
|
var init_awsLambdaFastify = __esm({
|
|
247
226
|
"src/requestHandlers/awsLambdaFastify.ts"() {
|
|
248
227
|
"use strict";
|
|
249
|
-
import_qs = __toESM(require("qs"));
|
|
250
228
|
init_utils();
|
|
251
229
|
lambdaEventForFastifyRequest = (request) => {
|
|
252
230
|
return {
|
|
253
231
|
httpMethod: request.method,
|
|
254
232
|
headers: request.headers,
|
|
255
233
|
path: request.urlData("path"),
|
|
256
|
-
queryStringParameters:
|
|
234
|
+
queryStringParameters: qs.parse(request.url.split(/\?(.+)/)[1]),
|
|
257
235
|
requestContext: {
|
|
258
236
|
requestId: request.id,
|
|
259
237
|
identity: {
|
|
@@ -331,23 +309,23 @@ var init_utils2 = __esm({
|
|
|
331
309
|
});
|
|
332
310
|
|
|
333
311
|
// src/plugins/lambdaLoader.ts
|
|
334
|
-
|
|
312
|
+
import path2 from "path";
|
|
313
|
+
import ansis from "ansis";
|
|
314
|
+
import fg from "fast-glob";
|
|
315
|
+
import { getPaths as getPaths2 } from "@cedarjs/project-config";
|
|
316
|
+
var LAMBDA_FUNCTIONS, setLambdaFunctions, loadFunctionsFromDist, findApiDistFunctions, lambdaRequestHandler;
|
|
335
317
|
var init_lambdaLoader = __esm({
|
|
336
318
|
"src/plugins/lambdaLoader.ts"() {
|
|
337
319
|
"use strict";
|
|
338
|
-
import_path2 = __toESM(require("path"));
|
|
339
|
-
import_ansis = __toESM(require("ansis"));
|
|
340
|
-
import_fast_glob = __toESM(require("fast-glob"));
|
|
341
|
-
import_project_config3 = require("@cedarjs/project-config");
|
|
342
320
|
init_awsLambdaFastify();
|
|
343
321
|
init_utils2();
|
|
344
322
|
LAMBDA_FUNCTIONS = {};
|
|
345
323
|
setLambdaFunctions = async (foundFunctions) => {
|
|
346
324
|
const tsImport = Date.now();
|
|
347
|
-
console.log(
|
|
325
|
+
console.log(ansis.dim.italic("Importing Server Functions... "));
|
|
348
326
|
const imports = foundFunctions.map(async (fnPath) => {
|
|
349
327
|
const ts = Date.now();
|
|
350
|
-
const routeName =
|
|
328
|
+
const routeName = path2.basename(fnPath).replace(".js", "");
|
|
351
329
|
const fnImport = await import(`file://${fnPath}`);
|
|
352
330
|
const handler3 = (() => {
|
|
353
331
|
if ("handler" in fnImport) {
|
|
@@ -370,22 +348,22 @@ var init_lambdaLoader = __esm({
|
|
|
370
348
|
);
|
|
371
349
|
}
|
|
372
350
|
console.log(
|
|
373
|
-
|
|
374
|
-
|
|
351
|
+
ansis.magenta("/" + routeName),
|
|
352
|
+
ansis.dim.italic(Date.now() - ts + " ms")
|
|
375
353
|
);
|
|
376
354
|
});
|
|
377
355
|
await Promise.all(imports);
|
|
378
356
|
console.log(
|
|
379
|
-
|
|
357
|
+
ansis.dim.italic("...Done importing in " + (Date.now() - tsImport) + " ms")
|
|
380
358
|
);
|
|
381
359
|
};
|
|
382
360
|
loadFunctionsFromDist = async (options = {}) => {
|
|
383
361
|
const serverFunctions = findApiDistFunctions({
|
|
384
|
-
cwd: (
|
|
362
|
+
cwd: getPaths2().api.base,
|
|
385
363
|
options: options?.fastGlobOptions,
|
|
386
364
|
discoverFunctionsGlob: options?.discoverFunctionsGlob
|
|
387
365
|
});
|
|
388
|
-
const i = serverFunctions.findIndex((x) =>
|
|
366
|
+
const i = serverFunctions.findIndex((x) => path2.basename(x) === "graphql.js");
|
|
389
367
|
if (i >= 0) {
|
|
390
368
|
const graphQLFn = serverFunctions.splice(i, 1)[0];
|
|
391
369
|
serverFunctions.unshift(graphQLFn);
|
|
@@ -394,11 +372,11 @@ var init_lambdaLoader = __esm({
|
|
|
394
372
|
};
|
|
395
373
|
findApiDistFunctions = (params) => {
|
|
396
374
|
const {
|
|
397
|
-
cwd = (
|
|
375
|
+
cwd = getPaths2().api.base,
|
|
398
376
|
options = {},
|
|
399
377
|
discoverFunctionsGlob = "dist/functions/**/*.{ts,js}"
|
|
400
378
|
} = params;
|
|
401
|
-
return
|
|
379
|
+
return fg.sync(discoverFunctionsGlob, {
|
|
402
380
|
cwd,
|
|
403
381
|
// We don't support deeply nested api functions, to maximise compatibility
|
|
404
382
|
// with deployment providers
|
|
@@ -430,16 +408,20 @@ var init_lambdaLoader = __esm({
|
|
|
430
408
|
});
|
|
431
409
|
|
|
432
410
|
// src/plugins/api.ts
|
|
411
|
+
import fastifyUrlData from "@fastify/url-data";
|
|
412
|
+
import fastifyRawBody from "fastify-raw-body";
|
|
413
|
+
import { getAsyncStoreInstance as getAsyncStoreInstance2 } from "@cedarjs/context/dist/store";
|
|
414
|
+
import { coerceRootPath as coerceRootPath2 } from "@cedarjs/fastify-web/dist/helpers.js";
|
|
433
415
|
async function redwoodFastifyAPI(fastify2, opts) {
|
|
434
416
|
const redwoodOptions = opts.redwood ?? {};
|
|
435
417
|
redwoodOptions.apiRootPath ??= "/";
|
|
436
|
-
redwoodOptions.apiRootPath = (
|
|
418
|
+
redwoodOptions.apiRootPath = coerceRootPath2(redwoodOptions.apiRootPath);
|
|
437
419
|
redwoodOptions.fastGlobOptions ??= {};
|
|
438
420
|
redwoodOptions.loadUserConfig ??= false;
|
|
439
|
-
fastify2.register(
|
|
440
|
-
await fastify2.register(
|
|
421
|
+
fastify2.register(fastifyUrlData);
|
|
422
|
+
await fastify2.register(fastifyRawBody);
|
|
441
423
|
fastify2.addHook("onRequest", (_req, _reply, done) => {
|
|
442
|
-
(
|
|
424
|
+
getAsyncStoreInstance2().run(/* @__PURE__ */ new Map(), done);
|
|
443
425
|
});
|
|
444
426
|
fastify2.addContentTypeParser(
|
|
445
427
|
["application/x-www-form-urlencoded", "multipart/form-data"],
|
|
@@ -465,14 +447,9 @@ async function redwoodFastifyAPI(fastify2, opts) {
|
|
|
465
447
|
discoverFunctionsGlob: redwoodOptions.discoverFunctionsGlob
|
|
466
448
|
});
|
|
467
449
|
}
|
|
468
|
-
var import_url_data, import_fastify_raw_body, import_store2, import_helpers2;
|
|
469
450
|
var init_api = __esm({
|
|
470
451
|
"src/plugins/api.ts"() {
|
|
471
452
|
"use strict";
|
|
472
|
-
import_url_data = __toESM(require("@fastify/url-data"));
|
|
473
|
-
import_fastify_raw_body = __toESM(require("fastify-raw-body"));
|
|
474
|
-
import_store2 = require("@cedarjs/context/dist/store");
|
|
475
|
-
import_helpers2 = require("@cedarjs/fastify-web/dist/helpers");
|
|
476
453
|
init_fastify();
|
|
477
454
|
init_lambdaLoader();
|
|
478
455
|
}
|
|
@@ -483,20 +460,27 @@ var graphql_exports = {};
|
|
|
483
460
|
__export(graphql_exports, {
|
|
484
461
|
redwoodFastifyGraphQLServer: () => redwoodFastifyGraphQLServer
|
|
485
462
|
});
|
|
463
|
+
import fastifyMultiPart from "@fastify/multipart";
|
|
464
|
+
import fastifyUrlData2 from "@fastify/url-data";
|
|
465
|
+
import fg2 from "fast-glob";
|
|
466
|
+
import { getAsyncStoreInstance as getAsyncStoreInstance3 } from "@cedarjs/context/dist/store";
|
|
467
|
+
import { coerceRootPath as coerceRootPath3 } from "@cedarjs/fastify-web/dist/helpers.js";
|
|
468
|
+
import { createGraphQLYoga } from "@cedarjs/graphql-server";
|
|
469
|
+
import { getPaths as getPaths3 } from "@cedarjs/project-config";
|
|
486
470
|
async function redwoodFastifyGraphQLServer(fastify2, options) {
|
|
487
471
|
const redwoodOptions = options.redwood ?? {};
|
|
488
472
|
redwoodOptions.apiRootPath ??= "/";
|
|
489
|
-
redwoodOptions.apiRootPath = (
|
|
490
|
-
fastify2.register(
|
|
491
|
-
fastify2.register(
|
|
473
|
+
redwoodOptions.apiRootPath = coerceRootPath3(redwoodOptions.apiRootPath);
|
|
474
|
+
fastify2.register(fastifyUrlData2);
|
|
475
|
+
fastify2.register(fastifyMultiPart);
|
|
492
476
|
const method = ["GET", "POST", "OPTIONS"];
|
|
493
477
|
fastify2.addHook("onRequest", (_req, _reply, done) => {
|
|
494
|
-
(
|
|
478
|
+
getAsyncStoreInstance3().run(/* @__PURE__ */ new Map(), done);
|
|
495
479
|
});
|
|
496
480
|
try {
|
|
497
481
|
if (!redwoodOptions.graphql) {
|
|
498
|
-
const [graphqlFunctionPath] = await (
|
|
499
|
-
cwd: (
|
|
482
|
+
const [graphqlFunctionPath] = await fg2("dist/functions/graphql.{ts,js}", {
|
|
483
|
+
cwd: getPaths3().api.base,
|
|
500
484
|
absolute: true
|
|
501
485
|
});
|
|
502
486
|
const filePath = `file://${graphqlFunctionPath}`;
|
|
@@ -516,7 +500,7 @@ async function redwoodFastifyGraphQLServer(fastify2, options) {
|
|
|
516
500
|
method.push("PUT");
|
|
517
501
|
}
|
|
518
502
|
}
|
|
519
|
-
const { yoga } =
|
|
503
|
+
const { yoga } = createGraphQLYoga(graphqlOptions);
|
|
520
504
|
const graphQLYogaHandler = async (req, reply) => {
|
|
521
505
|
const response = await yoga.handleNodeRequest(req, {
|
|
522
506
|
req,
|
|
@@ -557,22 +541,22 @@ async function redwoodFastifyGraphQLServer(fastify2, options) {
|
|
|
557
541
|
function trimSlashes(path5) {
|
|
558
542
|
return path5.replace(/^\/|\/$/g, "");
|
|
559
543
|
}
|
|
560
|
-
var import_multipart, import_url_data2, import_fast_glob2, import_store3, import_helpers3, import_graphql_server, import_project_config4;
|
|
561
544
|
var init_graphql = __esm({
|
|
562
545
|
"src/plugins/graphql.ts"() {
|
|
563
546
|
"use strict";
|
|
564
|
-
import_multipart = __toESM(require("@fastify/multipart"));
|
|
565
|
-
import_url_data2 = __toESM(require("@fastify/url-data"));
|
|
566
|
-
import_fast_glob2 = __toESM(require("fast-glob"));
|
|
567
|
-
import_store3 = require("@cedarjs/context/dist/store");
|
|
568
|
-
import_helpers3 = require("@cedarjs/fastify-web/dist/helpers");
|
|
569
|
-
import_graphql_server = require("@cedarjs/graphql-server");
|
|
570
|
-
import_project_config4 = require("@cedarjs/project-config");
|
|
571
547
|
init_awsLambdaFastify();
|
|
572
548
|
}
|
|
573
549
|
});
|
|
574
550
|
|
|
575
551
|
// src/createServer.ts
|
|
552
|
+
import fs2 from "fs";
|
|
553
|
+
import path3 from "path";
|
|
554
|
+
import ansis2 from "ansis";
|
|
555
|
+
import { config } from "dotenv-defaults";
|
|
556
|
+
import fg3 from "fast-glob";
|
|
557
|
+
import fastify from "fastify";
|
|
558
|
+
import { getAsyncStoreInstance as getAsyncStoreInstance4 } from "@cedarjs/context/dist/store";
|
|
559
|
+
import { getConfig as getConfig3, getPaths as getPaths4 } from "@cedarjs/project-config";
|
|
576
560
|
async function createServer(options = {}) {
|
|
577
561
|
const {
|
|
578
562
|
apiRootPath,
|
|
@@ -582,13 +566,13 @@ async function createServer(options = {}) {
|
|
|
582
566
|
apiPort,
|
|
583
567
|
apiHost
|
|
584
568
|
} = resolveOptions(options);
|
|
585
|
-
const serverConfigPath =
|
|
586
|
-
(
|
|
587
|
-
(
|
|
569
|
+
const serverConfigPath = path3.join(
|
|
570
|
+
getPaths4().base,
|
|
571
|
+
getConfig3().api.serverConfig
|
|
588
572
|
);
|
|
589
|
-
if (
|
|
573
|
+
if (fs2.existsSync(serverConfigPath)) {
|
|
590
574
|
console.warn(
|
|
591
|
-
|
|
575
|
+
ansis2.yellow(
|
|
592
576
|
[
|
|
593
577
|
"",
|
|
594
578
|
`Ignoring \`config\` and \`configureServer\` in api/server.config.js.`,
|
|
@@ -608,14 +592,14 @@ async function createServer(options = {}) {
|
|
|
608
592
|
)
|
|
609
593
|
);
|
|
610
594
|
}
|
|
611
|
-
const server = Object.assign((
|
|
595
|
+
const server = Object.assign(fastify(fastifyServerOptions), {
|
|
612
596
|
// `start` will get replaced further down in this file
|
|
613
597
|
start: async () => {
|
|
614
598
|
throw new Error("Not implemented yet");
|
|
615
599
|
}
|
|
616
600
|
});
|
|
617
601
|
server.addHook("onRequest", (_req, _reply, done) => {
|
|
618
|
-
(
|
|
602
|
+
getAsyncStoreInstance4().run(/* @__PURE__ */ new Map(), done);
|
|
619
603
|
});
|
|
620
604
|
await server.register(redwoodFastifyAPI, {
|
|
621
605
|
redwood: {
|
|
@@ -627,8 +611,8 @@ async function createServer(options = {}) {
|
|
|
627
611
|
configureServer: configureApiServer
|
|
628
612
|
}
|
|
629
613
|
});
|
|
630
|
-
const [graphqlFunctionPath] = await (
|
|
631
|
-
cwd: (
|
|
614
|
+
const [graphqlFunctionPath] = await fg3("dist/functions/graphql.{ts,js}", {
|
|
615
|
+
cwd: getPaths4().api.base,
|
|
632
616
|
absolute: true
|
|
633
617
|
});
|
|
634
618
|
if (graphqlFunctionPath) {
|
|
@@ -647,7 +631,7 @@ async function createServer(options = {}) {
|
|
|
647
631
|
});
|
|
648
632
|
server.addHook("onListen", (done) => {
|
|
649
633
|
console.log(
|
|
650
|
-
`Server listening at ${
|
|
634
|
+
`Server listening at ${ansis2.magenta(
|
|
651
635
|
`${server.listeningOrigin}${apiRootPath}`
|
|
652
636
|
)}`
|
|
653
637
|
);
|
|
@@ -662,24 +646,15 @@ async function createServer(options = {}) {
|
|
|
662
646
|
};
|
|
663
647
|
return server;
|
|
664
648
|
}
|
|
665
|
-
var import_fs2, import_path3, import_ansis2, import_dotenv_defaults, import_fast_glob3, import_fastify3, import_store4, import_project_config5;
|
|
666
649
|
var init_createServer = __esm({
|
|
667
650
|
"src/createServer.ts"() {
|
|
668
651
|
"use strict";
|
|
669
|
-
import_fs2 = __toESM(require("fs"));
|
|
670
|
-
import_path3 = __toESM(require("path"));
|
|
671
|
-
import_ansis2 = __toESM(require("ansis"));
|
|
672
|
-
import_dotenv_defaults = require("dotenv-defaults");
|
|
673
|
-
import_fast_glob3 = __toESM(require("fast-glob"));
|
|
674
|
-
import_fastify3 = __toESM(require("fastify"));
|
|
675
|
-
import_store4 = require("@cedarjs/context/dist/store");
|
|
676
|
-
import_project_config5 = require("@cedarjs/project-config");
|
|
677
652
|
init_createServerHelpers();
|
|
678
653
|
init_api();
|
|
679
654
|
if (!process.env.REDWOOD_ENV_FILES_LOADED) {
|
|
680
|
-
|
|
681
|
-
path:
|
|
682
|
-
defaults:
|
|
655
|
+
config({
|
|
656
|
+
path: path3.join(getPaths4().base, ".env"),
|
|
657
|
+
defaults: path3.join(getPaths4().base, ".env.defaults"),
|
|
683
658
|
multiline: true
|
|
684
659
|
});
|
|
685
660
|
process.env.REDWOOD_ENV_FILES_LOADED = "true";
|
|
@@ -688,10 +663,12 @@ var init_createServer = __esm({
|
|
|
688
663
|
});
|
|
689
664
|
|
|
690
665
|
// src/apiCLIConfigHandler.ts
|
|
666
|
+
import ansis3 from "ansis";
|
|
667
|
+
import { coerceRootPath as coerceRootPath4 } from "@cedarjs/fastify-web";
|
|
691
668
|
async function handler(options = {}) {
|
|
692
669
|
const timeStart = Date.now();
|
|
693
|
-
console.log(
|
|
694
|
-
options.apiRootPath = (
|
|
670
|
+
console.log(ansis3.dim.italic("Starting API Server..."));
|
|
671
|
+
options.apiRootPath = coerceRootPath4(options.apiRootPath ?? "/");
|
|
695
672
|
const fastify2 = await createServer({
|
|
696
673
|
apiRootPath: options.apiRootPath,
|
|
697
674
|
apiHost: options.host,
|
|
@@ -704,36 +681,35 @@ async function handler(options = {}) {
|
|
|
704
681
|
);
|
|
705
682
|
fastify2.log.trace(`Registered plugins
|
|
706
683
|
${fastify2.printPlugins()}`);
|
|
707
|
-
console.log(
|
|
684
|
+
console.log(ansis3.dim.italic("Took " + (Date.now() - timeStart) + " ms"));
|
|
708
685
|
let address = fastify2.listeningOrigin;
|
|
709
686
|
if (process.env.NODE_ENV !== "production") {
|
|
710
687
|
address = address.replace(/http:\/\/\[::\]/, "http://localhost");
|
|
711
688
|
}
|
|
712
|
-
const apiServer =
|
|
713
|
-
const graphqlEndpoint =
|
|
689
|
+
const apiServer = ansis3.magenta(`${address}${options.apiRootPath}`);
|
|
690
|
+
const graphqlEndpoint = ansis3.magenta(`${apiServer}graphql`);
|
|
714
691
|
console.log(`API server listening at ${apiServer}`);
|
|
715
692
|
console.log(`GraphQL endpoint at ${graphqlEndpoint}`);
|
|
716
693
|
process?.send?.("ready");
|
|
717
694
|
}
|
|
718
|
-
var import_ansis3, import_fastify_web;
|
|
719
695
|
var init_apiCLIConfigHandler = __esm({
|
|
720
696
|
"src/apiCLIConfigHandler.ts"() {
|
|
721
697
|
"use strict";
|
|
722
|
-
import_ansis3 = __toESM(require("ansis"));
|
|
723
|
-
import_fastify_web = require("@cedarjs/fastify-web");
|
|
724
698
|
init_createServer();
|
|
725
699
|
}
|
|
726
700
|
});
|
|
727
701
|
|
|
728
702
|
// src/bothCLIConfigHandler.ts
|
|
703
|
+
import ansis4 from "ansis";
|
|
704
|
+
import { redwoodFastifyWeb, coerceRootPath as coerceRootPath5 } from "@cedarjs/fastify-web";
|
|
729
705
|
async function handler2(options) {
|
|
730
706
|
const timeStart = Date.now();
|
|
731
|
-
console.log(
|
|
707
|
+
console.log(ansis4.dim.italic("Starting API and Web Servers..."));
|
|
732
708
|
options.webHost ??= getWebHost();
|
|
733
709
|
options.webPort ??= getWebPort();
|
|
734
710
|
options.apiHost ??= getAPIHost();
|
|
735
711
|
options.apiPort ??= getAPIPort();
|
|
736
|
-
options.apiRootPath = (
|
|
712
|
+
options.apiRootPath = coerceRootPath5(options.apiRootPath ?? "/");
|
|
737
713
|
const apiProxyTarget = [
|
|
738
714
|
"http://",
|
|
739
715
|
options.apiHost.includes(":") ? `[${options.apiHost}]` : options.apiHost,
|
|
@@ -742,7 +718,7 @@ async function handler2(options) {
|
|
|
742
718
|
options.apiRootPath
|
|
743
719
|
].join("");
|
|
744
720
|
const webFastify = await fastify_default();
|
|
745
|
-
webFastify.register(
|
|
721
|
+
webFastify.register(redwoodFastifyWeb, {
|
|
746
722
|
redwood: {
|
|
747
723
|
apiProxyTarget
|
|
748
724
|
}
|
|
@@ -772,12 +748,12 @@ ${webFastify.printPlugins()}`);
|
|
|
772
748
|
);
|
|
773
749
|
apiFastify.log.trace(`Registered plugins
|
|
774
750
|
${apiFastify.printPlugins()}`);
|
|
775
|
-
console.log(
|
|
776
|
-
const webServer =
|
|
777
|
-
const apiServer =
|
|
751
|
+
console.log(ansis4.dim.italic("Took " + (Date.now() - timeStart) + " ms"));
|
|
752
|
+
const webServer = ansis4.green(webFastify.listeningOrigin);
|
|
753
|
+
const apiServer = ansis4.magenta(
|
|
778
754
|
`${apiFastify.listeningOrigin}${options.apiRootPath}`
|
|
779
755
|
);
|
|
780
|
-
const graphqlEndpoint =
|
|
756
|
+
const graphqlEndpoint = ansis4.magenta(`${apiServer}graphql`);
|
|
781
757
|
console.log(`Web server listening at ${webServer}`);
|
|
782
758
|
console.log(`API server listening at ${apiServer}`);
|
|
783
759
|
console.log(`GraphQL endpoint at ${graphqlEndpoint}`);
|
|
@@ -791,12 +767,9 @@ function getListenTextResolver(side) {
|
|
|
791
767
|
return `${side} server listening at ${address}`;
|
|
792
768
|
};
|
|
793
769
|
}
|
|
794
|
-
var import_ansis4, import_fastify_web2;
|
|
795
770
|
var init_bothCLIConfigHandler = __esm({
|
|
796
771
|
"src/bothCLIConfigHandler.ts"() {
|
|
797
772
|
"use strict";
|
|
798
|
-
import_ansis4 = __toESM(require("ansis"));
|
|
799
|
-
import_fastify_web2 = require("@cedarjs/fastify-web");
|
|
800
773
|
init_cliHelpers();
|
|
801
774
|
init_createServer();
|
|
802
775
|
init_fastify();
|
|
@@ -804,12 +777,16 @@ var init_bothCLIConfigHandler = __esm({
|
|
|
804
777
|
});
|
|
805
778
|
|
|
806
779
|
// src/bin.ts
|
|
807
|
-
|
|
808
|
-
|
|
809
|
-
|
|
810
|
-
|
|
811
|
-
|
|
812
|
-
|
|
780
|
+
import path4 from "path";
|
|
781
|
+
import { config as config2 } from "dotenv-defaults";
|
|
782
|
+
import { hideBin } from "yargs/helpers";
|
|
783
|
+
import yargs from "yargs/yargs";
|
|
784
|
+
import { getPaths as getPaths5 } from "@cedarjs/project-config";
|
|
785
|
+
import {
|
|
786
|
+
description as webDescription,
|
|
787
|
+
builder as webBuilder,
|
|
788
|
+
handler as webHandler
|
|
789
|
+
} from "@cedarjs/web-server";
|
|
813
790
|
|
|
814
791
|
// src/apiCLIConfig.ts
|
|
815
792
|
var description = "Start a server for serving the api side";
|
|
@@ -878,15 +855,15 @@ function builder2(yargs2) {
|
|
|
878
855
|
// src/bin.ts
|
|
879
856
|
init_bothCLIConfigHandler();
|
|
880
857
|
if (!process.env.REDWOOD_ENV_FILES_LOADED) {
|
|
881
|
-
(
|
|
882
|
-
path:
|
|
883
|
-
defaults:
|
|
858
|
+
config2({
|
|
859
|
+
path: path4.join(getPaths5().base, ".env"),
|
|
860
|
+
defaults: path4.join(getPaths5().base, ".env.defaults"),
|
|
884
861
|
multiline: true
|
|
885
862
|
});
|
|
886
863
|
process.env.REDWOOD_ENV_FILES_LOADED = "true";
|
|
887
864
|
}
|
|
888
865
|
process.env.NODE_ENV ??= "production";
|
|
889
|
-
(
|
|
866
|
+
yargs(hideBin(process.argv)).scriptName("rw-server").strict().alias("h", "help").alias("v", "version").command(
|
|
890
867
|
"$0",
|
|
891
868
|
description2,
|
|
892
869
|
// @ts-expect-error The yargs types seem wrong; it's ok for builder to be a function
|
|
@@ -900,8 +877,8 @@ process.env.NODE_ENV ??= "production";
|
|
|
900
877
|
handler
|
|
901
878
|
).command(
|
|
902
879
|
"web",
|
|
903
|
-
|
|
880
|
+
webDescription,
|
|
904
881
|
// @ts-expect-error The yargs types seem wrong; it's ok for builder to be a function
|
|
905
|
-
|
|
906
|
-
|
|
882
|
+
webBuilder,
|
|
883
|
+
webHandler
|
|
907
884
|
).parse();
|
package/dist/bothCLIConfig.js
CHANGED
|
@@ -1,38 +1,3 @@
|
|
|
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 bothCLIConfig_exports = {};
|
|
30
|
-
__export(bothCLIConfig_exports, {
|
|
31
|
-
builder: () => builder,
|
|
32
|
-
description: () => description,
|
|
33
|
-
handler: () => handler
|
|
34
|
-
});
|
|
35
|
-
module.exports = __toCommonJS(bothCLIConfig_exports);
|
|
36
1
|
const description = "Start a server for serving the api and web sides";
|
|
37
2
|
function builder(yargs) {
|
|
38
3
|
yargs.options({
|
|
@@ -68,9 +33,8 @@ async function handler(options) {
|
|
|
68
33
|
const { handler: handler2 } = await import("./bothCLIConfigHandler.js");
|
|
69
34
|
await handler2(options);
|
|
70
35
|
}
|
|
71
|
-
|
|
72
|
-
0 && (module.exports = {
|
|
36
|
+
export {
|
|
73
37
|
builder,
|
|
74
38
|
description,
|
|
75
39
|
handler
|
|
76
|
-
}
|
|
40
|
+
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"bothCLIConfigHandler.d.ts","sourceRoot":"","sources":["../src/bothCLIConfigHandler.ts"],"names":[],"mappings":"
|
|
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"}
|