@redmix/api-server 0.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (66) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +64 -0
  3. package/dist/apiCLIConfig.d.ts +6 -0
  4. package/dist/apiCLIConfig.d.ts.map +1 -0
  5. package/dist/apiCLIConfig.js +71 -0
  6. package/dist/apiCLIConfigHandler.d.ts +3 -0
  7. package/dist/apiCLIConfigHandler.d.ts.map +1 -0
  8. package/dist/apiCLIConfigHandler.js +68 -0
  9. package/dist/bin.d.ts +2 -0
  10. package/dist/bin.d.ts.map +1 -0
  11. package/dist/bin.js +850 -0
  12. package/dist/bothCLIConfig.d.ts +6 -0
  13. package/dist/bothCLIConfig.d.ts.map +1 -0
  14. package/dist/bothCLIConfig.js +76 -0
  15. package/dist/bothCLIConfigHandler.d.ts +3 -0
  16. package/dist/bothCLIConfigHandler.d.ts.map +1 -0
  17. package/dist/bothCLIConfigHandler.js +107 -0
  18. package/dist/buildManager.d.ts +15 -0
  19. package/dist/buildManager.d.ts.map +1 -0
  20. package/dist/buildManager.js +74 -0
  21. package/dist/cliHelpers.d.ts +5 -0
  22. package/dist/cliHelpers.d.ts.map +1 -0
  23. package/dist/cliHelpers.js +52 -0
  24. package/dist/createServer.d.ts +30 -0
  25. package/dist/createServer.d.ts.map +1 -0
  26. package/dist/createServer.js +142 -0
  27. package/dist/createServerHelpers.d.ts +39 -0
  28. package/dist/createServerHelpers.d.ts.map +1 -0
  29. package/dist/createServerHelpers.js +101 -0
  30. package/dist/fastify.d.ts +14 -0
  31. package/dist/fastify.d.ts.map +1 -0
  32. package/dist/fastify.js +88 -0
  33. package/dist/logFormatter/ambient.d.js +1 -0
  34. package/dist/logFormatter/bin.d.ts +2 -0
  35. package/dist/logFormatter/bin.d.ts.map +1 -0
  36. package/dist/logFormatter/bin.js +369 -0
  37. package/dist/logFormatter/formatters.d.ts +30 -0
  38. package/dist/logFormatter/formatters.d.ts.map +1 -0
  39. package/dist/logFormatter/formatters.js +275 -0
  40. package/dist/logFormatter/index.d.ts +2 -0
  41. package/dist/logFormatter/index.d.ts.map +1 -0
  42. package/dist/logFormatter/index.js +184 -0
  43. package/dist/plugins/api.d.ts +13 -0
  44. package/dist/plugins/api.d.ts.map +1 -0
  45. package/dist/plugins/api.js +77 -0
  46. package/dist/plugins/graphql.d.ts +10 -0
  47. package/dist/plugins/graphql.d.ts.map +1 -0
  48. package/dist/plugins/graphql.js +115 -0
  49. package/dist/plugins/lambdaLoader.d.ts +23 -0
  50. package/dist/plugins/lambdaLoader.d.ts.map +1 -0
  51. package/dist/plugins/lambdaLoader.js +116 -0
  52. package/dist/requestHandlers/awsLambdaFastify.d.ts +5 -0
  53. package/dist/requestHandlers/awsLambdaFastify.d.ts.map +1 -0
  54. package/dist/requestHandlers/awsLambdaFastify.js +103 -0
  55. package/dist/requestHandlers/utils.d.ts +26 -0
  56. package/dist/requestHandlers/utils.d.ts.map +1 -0
  57. package/dist/requestHandlers/utils.js +55 -0
  58. package/dist/serverManager.d.ts +8 -0
  59. package/dist/serverManager.d.ts.map +1 -0
  60. package/dist/serverManager.js +138 -0
  61. package/dist/types.d.ts +19 -0
  62. package/dist/types.d.ts.map +1 -0
  63. package/dist/watch.d.ts +2 -0
  64. package/dist/watch.d.ts.map +1 -0
  65. package/dist/watch.js +274 -0
  66. package/package.json +77 -0
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2025 Redmix
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,64 @@
1
+ # Redwood [Fastify](https://www.fastify.io) Server
2
+
3
+ ## About
4
+
5
+ This package contains code for Redwood's Fastify server:
6
+
7
+ - used during local dev for API Side
8
+ - used for Production Deploys requiring long-running process (i.e. not serverless)
9
+
10
+ #### TODO
11
+
12
+ - add code structure walk-through
13
+ - add package leads
14
+ - add contributing related info
15
+
16
+ ## package.json Server Binaries
17
+
18
+ Run the Redwood Fastify Server programmatically.
19
+
20
+ From package.json
21
+
22
+ ```
23
+ "bin": {
24
+ "rw-api-server-watch": "./dist/watch.js",
25
+ "rw-log-formatter": "./dist/logFormatter/bin.js",
26
+ "rw-server": "./dist/index.js"
27
+ },
28
+ ```
29
+
30
+ > Note: because we use Yargs to parse in index, using these within the context of a Redwood CLI command will throw due to Yargs object "collision". Needs to be re-architected in the future.
31
+
32
+ ### `rw-server`
33
+
34
+ Indended for dev and prototyping (i.e. pre-production).
35
+
36
+ This command runs both the API and Web server on the same port and is not performant at scale for production use. Instead, use the separate commands to run the API and (if needed) Web servers independently, along with tools like PM2, Nginx, or Kubernetes, which appropriately handle concurrent requests, errors, static asset, etc. for production contexts.
37
+
38
+ - Runs web on redwood.toml web.port (default 8910)
39
+ - API listens on web port at path redwood.toml web.apiUrl
40
+ - Command Options:
41
+ - port (default 8910)
42
+ - socket (optional)
43
+ - apiHost (default redwood.toml web.apiUrl)
44
+
45
+ ### `rw-server api`
46
+
47
+ For production use.
48
+
49
+ - Runs api on redwood.toml api.port (default 8911)
50
+ - Command Options:
51
+ - port (default 8911)
52
+ - socket (optional)
53
+ - apiRootPath (default '/')
54
+
55
+ ### `rw-server web`
56
+
57
+ Not optimized for production use at scale (see comments above for `rw-server`). Recommended to use CDN or Nginx as performant alternatives.
58
+
59
+ - Runs web on redwood.toml web.port (default 8910)
60
+ - GraphQL endpoint is set to redwood.toml web.apiUrl/graphql
61
+ - Command Options:
62
+ - port (default 8910)
63
+ - socket (optional)
64
+ - apiHost (default redwood.toml web.apiUrl)
@@ -0,0 +1,6 @@
1
+ import type { Argv } from 'yargs';
2
+ import type { APIParsedOptions } from './types';
3
+ export declare const description = "Start a server for serving the api side";
4
+ export declare function builder(yargs: Argv<APIParsedOptions>): void;
5
+ export declare function handler(options: APIParsedOptions): Promise<void>;
6
+ //# sourceMappingURL=apiCLIConfig.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"apiCLIConfig.d.ts","sourceRoot":"","sources":["../src/apiCLIConfig.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,OAAO,CAAA;AAEjC,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,SAAS,CAAA;AAE/C,eAAO,MAAM,WAAW,4CAA4C,CAAA;AAEpE,wBAAgB,OAAO,CAAC,KAAK,EAAE,IAAI,CAAC,gBAAgB,CAAC,QAyBpD;AAED,wBAAsB,OAAO,CAAC,OAAO,EAAE,gBAAgB,iBAGtD"}
@@ -0,0 +1,71 @@
1
+ "use strict";
2
+ var __create = Object.create;
3
+ var __defProp = Object.defineProperty;
4
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
+ var __getOwnPropNames = Object.getOwnPropertyNames;
6
+ var __getProtoOf = Object.getPrototypeOf;
7
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
8
+ var __export = (target, all) => {
9
+ for (var name in all)
10
+ __defProp(target, name, { get: all[name], enumerable: true });
11
+ };
12
+ var __copyProps = (to, from, except, desc) => {
13
+ if (from && typeof from === "object" || typeof from === "function") {
14
+ for (let key of __getOwnPropNames(from))
15
+ if (!__hasOwnProp.call(to, key) && key !== except)
16
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
17
+ }
18
+ return to;
19
+ };
20
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
21
+ // If the importer is in node compatibility mode or this is not an ESM
22
+ // file that has been converted to a CommonJS file using a Babel-
23
+ // compatible transform (i.e. "__esModule" has not been set), then set
24
+ // "default" to the CommonJS "module.exports" for node compatibility.
25
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
26
+ mod
27
+ ));
28
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
29
+ var apiCLIConfig_exports = {};
30
+ __export(apiCLIConfig_exports, {
31
+ builder: () => builder,
32
+ description: () => description,
33
+ handler: () => handler
34
+ });
35
+ module.exports = __toCommonJS(apiCLIConfig_exports);
36
+ const description = "Start a server for serving the api side";
37
+ function builder(yargs) {
38
+ yargs.options({
39
+ port: {
40
+ description: "The port to listen at",
41
+ type: "number",
42
+ alias: "p"
43
+ },
44
+ host: {
45
+ description: "The host to listen at. Note that you most likely want this to be '0.0.0.0' in production",
46
+ type: "string"
47
+ },
48
+ apiRootPath: {
49
+ description: "Root path where your api functions are served",
50
+ type: "string",
51
+ alias: ["api-root-path", "rootPath", "root-path"],
52
+ default: "/"
53
+ },
54
+ // This became a no-op in v7 because env files weren't loaded by default
55
+ // but removing it would break yargs parsing for older projects,
56
+ // so leaving it here so that yargs doesn't throw an error
57
+ loadEnvFiles: {
58
+ hidden: true
59
+ }
60
+ });
61
+ }
62
+ async function handler(options) {
63
+ const { handler: handler2 } = await import("./apiCLIConfigHandler.js");
64
+ await handler2(options);
65
+ }
66
+ // Annotate the CommonJS export names for ESM import in node:
67
+ 0 && (module.exports = {
68
+ builder,
69
+ description,
70
+ handler
71
+ });
@@ -0,0 +1,3 @@
1
+ import type { APIParsedOptions } from './types';
2
+ export declare function handler(options?: APIParsedOptions): Promise<void>;
3
+ //# sourceMappingURL=apiCLIConfigHandler.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"apiCLIConfigHandler.d.ts","sourceRoot":"","sources":["../src/apiCLIConfigHandler.ts"],"names":[],"mappings":"AAMA,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,SAAS,CAAA;AAE/C,wBAAsB,OAAO,CAAC,OAAO,GAAE,gBAAqB,iBAqC3D"}
@@ -0,0 +1,68 @@
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 apiCLIConfigHandler_exports = {};
30
+ __export(apiCLIConfigHandler_exports, {
31
+ handler: () => handler
32
+ });
33
+ module.exports = __toCommonJS(apiCLIConfigHandler_exports);
34
+ var import_chalk = __toESM(require("chalk"));
35
+ var import_fastify_web = require("@redmix/fastify-web");
36
+ var import_cliHelpers = require("./cliHelpers");
37
+ var import_createServer = require("./createServer");
38
+ async function handler(options = {}) {
39
+ const timeStart = Date.now();
40
+ console.log(import_chalk.default.dim.italic("Starting API Server..."));
41
+ options.apiRootPath = (0, import_fastify_web.coerceRootPath)(options.apiRootPath ?? "/");
42
+ const fastify = await (0, import_createServer.createServer)({
43
+ apiRootPath: options.apiRootPath
44
+ });
45
+ options.host ??= (0, import_cliHelpers.getAPIHost)();
46
+ options.port ??= (0, import_cliHelpers.getAPIPort)();
47
+ await fastify.start();
48
+ fastify.log.trace(
49
+ { custom: { ...fastify.initialConfig } },
50
+ "Fastify server configuration"
51
+ );
52
+ fastify.log.trace(`Registered plugins
53
+ ${fastify.printPlugins()}`);
54
+ console.log(import_chalk.default.dim.italic("Took " + (Date.now() - timeStart) + " ms"));
55
+ let address = fastify.listeningOrigin;
56
+ if (process.env.NODE_ENV !== "production") {
57
+ address = address.replace(/http:\/\/\[::\]/, "http://localhost");
58
+ }
59
+ const apiServer = import_chalk.default.magenta(`${address}${options.apiRootPath}`);
60
+ const graphqlEndpoint = import_chalk.default.magenta(`${apiServer}graphql`);
61
+ console.log(`API server listening at ${apiServer}`);
62
+ console.log(`GraphQL endpoint at ${graphqlEndpoint}`);
63
+ process?.send?.("ready");
64
+ }
65
+ // Annotate the CommonJS export names for ESM import in node:
66
+ 0 && (module.exports = {
67
+ handler
68
+ });
package/dist/bin.d.ts ADDED
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=bin.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"bin.d.ts","sourceRoot":"","sources":["../src/bin.ts"],"names":[],"mappings":""}