@cedarjs/fastify-web 9.0.0-canary.1784 → 9.0.0-canary.3124

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/dist/helpers.js CHANGED
@@ -1,32 +1,8 @@
1
- "use strict";
2
- var __defProp = Object.defineProperty;
3
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
- var __getOwnPropNames = Object.getOwnPropertyNames;
5
- var __hasOwnProp = Object.prototype.hasOwnProperty;
6
- var __export = (target, all) => {
7
- for (var name in all)
8
- __defProp(target, name, { get: all[name], enumerable: true });
9
- };
10
- var __copyProps = (to, from, except, desc) => {
11
- if (from && typeof from === "object" || typeof from === "function") {
12
- for (let key of __getOwnPropNames(from))
13
- if (!__hasOwnProp.call(to, key) && key !== except)
14
- __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
- }
16
- return to;
17
- };
18
- var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
- var helpers_exports = {};
20
- __export(helpers_exports, {
21
- coerceRootPath: () => coerceRootPath
22
- });
23
- module.exports = __toCommonJS(helpers_exports);
24
1
  function coerceRootPath(path) {
25
2
  const prefix = !path.startsWith("/") ? "/" : "";
26
3
  const suffix = !path.endsWith("/") ? "/" : "";
27
4
  return `${prefix}${path}${suffix}`;
28
5
  }
29
- // Annotate the CommonJS export names for ESM import in node:
30
- 0 && (module.exports = {
6
+ export {
31
7
  coerceRootPath
32
- });
8
+ };
@@ -1,4 +1,4 @@
1
- import type { RedwoodFastifyWebOptions } from './types';
1
+ import type { RedwoodFastifyWebOptions } from './types.js';
2
2
  export declare function resolveOptions(options: RedwoodFastifyWebOptions): {
3
3
  redwoodOptions: {
4
4
  apiUrl?: string;
@@ -1 +1 @@
1
- {"version":3,"file":"resolveOptions.d.ts","sourceRoot":"","sources":["../src/resolveOptions.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,wBAAwB,EAAE,MAAM,SAAS,CAAA;AAEvD,wBAAgB,cAAc,CAAC,OAAO,EAAE,wBAAwB;;;;;;;;;EA0E/D"}
1
+ {"version":3,"file":"resolveOptions.d.ts","sourceRoot":"","sources":["../src/resolveOptions.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,wBAAwB,EAAE,MAAM,YAAY,CAAA;AAE1D,wBAAgB,cAAc,CAAC,OAAO,EAAE,wBAAwB;;;;;;;;;EA0E/D"}
package/dist/types.d.ts CHANGED
@@ -2,9 +2,9 @@ export interface RedwoodFastifyWebOptions {
2
2
  redwood?: {
3
3
  /**
4
4
  * Specify the URL to your API server.
5
- * This can be a relative URL on the current domain (`/.redwood/functions`),
5
+ * This can be a relative URL on the current domain (`/.api/functions`),
6
6
  * in which case the `apiProxyTarget` option must be set,
7
- * or a fully-qualified URL (`https://api.redwood.horse`).
7
+ * or a fully-qualified URL (`https://api.example.com`).
8
8
  *
9
9
  * Note: This should not include the path to the GraphQL Server.
10
10
  **/
package/dist/web.d.ts CHANGED
@@ -1,6 +1,7 @@
1
1
  import type { FastifyInstance } from 'fastify';
2
- import { coerceRootPath } from './helpers';
3
- import type { RedwoodFastifyWebOptions } from './types';
4
- export { coerceRootPath, RedwoodFastifyWebOptions };
2
+ import { coerceRootPath } from './helpers.js';
3
+ import type { RedwoodFastifyWebOptions } from './types.js';
4
+ export { coerceRootPath };
5
+ export type { RedwoodFastifyWebOptions };
5
6
  export declare function redwoodFastifyWeb(fastify: FastifyInstance, opts: RedwoodFastifyWebOptions): Promise<void>;
6
7
  //# sourceMappingURL=web.d.ts.map
package/dist/web.d.ts.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"web.d.ts","sourceRoot":"","sources":["../src/web.ts"],"names":[],"mappings":"AAOA,OAAO,KAAK,EAAE,eAAe,EAAgC,MAAM,SAAS,CAAA;AAI5E,OAAO,EAAE,cAAc,EAAE,MAAM,WAAW,CAAA;AAE1C,OAAO,KAAK,EAAE,wBAAwB,EAAE,MAAM,SAAS,CAAA;AAEvD,OAAO,EAAE,cAAc,EAAE,wBAAwB,EAAE,CAAA;AAEnD,wBAAsB,iBAAiB,CACrC,OAAO,EAAE,eAAe,EACxB,IAAI,EAAE,wBAAwB,iBA0G/B"}
1
+ {"version":3,"file":"web.d.ts","sourceRoot":"","sources":["../src/web.ts"],"names":[],"mappings":"AAQA,OAAO,KAAK,EAAE,eAAe,EAAgC,MAAM,SAAS,CAAA;AAI5E,OAAO,EAAE,cAAc,EAAE,MAAM,cAAc,CAAA;AAE7C,OAAO,KAAK,EAAE,wBAAwB,EAAE,MAAM,YAAY,CAAA;AAE1D,OAAO,EAAE,cAAc,EAAE,CAAA;AACzB,YAAY,EAAE,wBAAwB,EAAE,CAAA;AAWxC,wBAAsB,iBAAiB,CACrC,OAAO,EAAE,eAAe,EACxB,IAAI,EAAE,wBAAwB,iBAwI/B"}
package/dist/web.js CHANGED
@@ -1,46 +1,12 @@
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
-
30
1
  // src/web.ts
31
- var web_exports = {};
32
- __export(web_exports, {
33
- coerceRootPath: () => coerceRootPath,
34
- redwoodFastifyWeb: () => redwoodFastifyWeb
35
- });
36
- module.exports = __toCommonJS(web_exports);
37
- var import_node_fs = __toESM(require("node:fs"));
38
- var import_path = __toESM(require("path"));
39
- var import_http_proxy = __toESM(require("@fastify/http-proxy"));
40
- var import_static = __toESM(require("@fastify/static"));
41
- var import_url_data = __toESM(require("@fastify/url-data"));
42
- var import_fast_glob = __toESM(require("fast-glob"));
43
- var import_project_config2 = require("@cedarjs/project-config");
2
+ import fs from "node:fs";
3
+ import path from "path";
4
+ import fastifyCompress from "@fastify/compress";
5
+ import httpProxy from "@fastify/http-proxy";
6
+ import fastifyStatic from "@fastify/static";
7
+ import fastifyUrlData from "@fastify/url-data";
8
+ import fg from "fast-glob";
9
+ import { getPaths } from "@cedarjs/project-config";
44
10
 
45
11
  // src/helpers.ts
46
12
  function coerceRootPath(path2) {
@@ -50,13 +16,13 @@ function coerceRootPath(path2) {
50
16
  }
51
17
 
52
18
  // src/resolveOptions.ts
53
- var import_project_config = require("@cedarjs/project-config");
19
+ import { getConfig } from "@cedarjs/project-config";
54
20
  function resolveOptions(options) {
55
21
  const redwoodOptions = options.redwood ?? {};
56
22
  const flags = {
57
23
  shouldRegisterApiUrl: false
58
24
  };
59
- redwoodOptions.apiUrl ??= (0, import_project_config.getConfig)().web.apiUrl;
25
+ redwoodOptions.apiUrl ??= getConfig().web.apiUrl;
60
26
  const apiUrlIsFullyQualifiedUrl = isFullyQualifiedUrl(redwoodOptions.apiUrl);
61
27
  if (redwoodOptions.apiHost && !redwoodOptions.apiProxyTarget) {
62
28
  redwoodOptions.apiProxyTarget = redwoodOptions.apiHost;
@@ -95,12 +61,26 @@ function isFullyQualifiedUrl(url) {
95
61
  }
96
62
 
97
63
  // src/web.ts
64
+ var ONE_YEAR_IN_SECONDS = 60 * 60 * 24 * 365;
65
+ var HASHED_ASSET_FILENAME = /-[0-9a-f]{8,}\.[^./]+$/i;
98
66
  async function redwoodFastifyWeb(fastify, opts) {
99
67
  const { redwoodOptions, flags } = resolveOptions(opts);
100
- fastify.register(import_url_data.default);
101
- fastify.register(import_static.default, { root: (0, import_project_config2.getPaths)().web.dist });
68
+ fastify.register(fastifyUrlData);
69
+ fastify.register(fastifyCompress);
70
+ const assetsDir = path.join(getPaths().web.dist, "assets") + path.sep;
71
+ fastify.register(fastifyStatic, {
72
+ root: getPaths().web.dist,
73
+ cacheControl: false,
74
+ setHeaders: (reply, filePath) => {
75
+ const isHashedAsset = filePath.startsWith(assetsDir) && HASHED_ASSET_FILENAME.test(path.basename(filePath));
76
+ reply.header(
77
+ "Cache-Control",
78
+ isHashedAsset ? `public, max-age=${ONE_YEAR_IN_SECONDS}, immutable` : "no-cache"
79
+ );
80
+ }
81
+ });
102
82
  if (redwoodOptions.apiProxyTarget) {
103
- fastify.register(import_http_proxy.default, {
83
+ fastify.register(httpProxy, {
104
84
  prefix: redwoodOptions.apiUrl,
105
85
  upstream: redwoodOptions.apiProxyTarget,
106
86
  disableCache: true,
@@ -133,8 +113,8 @@ async function redwoodFastifyWeb(fastify, opts) {
133
113
  fastify.all(apiUrlWarningPath, apiUrlHandler);
134
114
  fastify.all(`${apiUrlWarningPath}*`, apiUrlHandler);
135
115
  }
136
- const prerenderedFiles = await (0, import_fast_glob.default)("**/*.html", {
137
- cwd: (0, import_project_config2.getPaths)().web.dist,
116
+ const prerenderedFiles = await fg("**/*.html", {
117
+ cwd: getPaths().web.dist,
138
118
  ignore: ["index.html", "200.html", "404.html"]
139
119
  });
140
120
  for (const prerenderedFile of prerenderedFiles) {
@@ -144,11 +124,11 @@ async function redwoodFastifyWeb(fastify, opts) {
144
124
  reply.sendFile(prerenderedFile);
145
125
  });
146
126
  }
147
- const prerenderIndexPath = import_path.default.join((0, import_project_config2.getPaths)().web.dist, "200.html");
148
- const fallbackIndexPath = import_node_fs.default.existsSync(prerenderIndexPath) ? "200.html" : "index.html";
127
+ const prerenderIndexPath = path.join(getPaths().web.dist, "200.html");
128
+ const fallbackIndexPath = fs.existsSync(prerenderIndexPath) ? "200.html" : "index.html";
149
129
  fastify.setNotFoundHandler({}, (req, reply) => {
150
130
  const urlData = req.urlData();
151
- const requestHasExtension = !!import_path.default.extname(urlData.path ?? "");
131
+ const requestHasExtension = !!path.extname(urlData.path ?? "");
152
132
  if (requestHasExtension && urlData.path?.startsWith("/assets/")) {
153
133
  reply.code(404);
154
134
  return reply.send("Not Found");
@@ -157,8 +137,7 @@ async function redwoodFastifyWeb(fastify, opts) {
157
137
  return reply.sendFile(fallbackIndexPath);
158
138
  });
159
139
  }
160
- // Annotate the CommonJS export names for ESM import in node:
161
- 0 && (module.exports = {
140
+ export {
162
141
  coerceRootPath,
163
142
  redwoodFastifyWeb
164
- });
143
+ };
package/package.json CHANGED
@@ -1,41 +1,45 @@
1
1
  {
2
2
  "name": "@cedarjs/fastify-web",
3
- "version": "9.0.0-canary.1784+baa47810a",
3
+ "version": "9.0.0-canary.3124",
4
4
  "repository": {
5
5
  "type": "git",
6
6
  "url": "git+https://github.com/cedarjs/cedar.git",
7
7
  "directory": "packages/adapters/fastify/web"
8
8
  },
9
9
  "license": "MIT",
10
+ "type": "module",
10
11
  "main": "./dist/web.js",
11
12
  "types": "./dist/web.d.ts",
12
13
  "files": [
13
14
  "dist"
14
15
  ],
15
16
  "scripts": {
16
- "build": "tsx ./build.mts && yarn build:types",
17
+ "build": "node ./build.mts",
17
18
  "build:pack": "yarn pack -o cedarjs-fastify-web.tgz",
18
- "build:types": "tsc --build --verbose",
19
+ "build:types": "tsc --build --verbose ./tsconfig.build.json",
19
20
  "prepublishOnly": "NODE_ENV=production yarn build",
20
21
  "test": "vitest run",
21
22
  "test:watch": "vitest watch"
22
23
  },
23
24
  "dependencies": {
24
- "@cedarjs/project-config": "9.0.0-canary.1784",
25
- "@fastify/http-proxy": "11.4.1",
26
- "@fastify/static": "8.3.0",
27
- "@fastify/url-data": "6.0.3",
25
+ "@cedarjs/project-config": "9.0.0-canary.3124",
26
+ "@fastify/compress": "9.2.0",
27
+ "@fastify/http-proxy": "11.6.2",
28
+ "@fastify/static": "10.1.3",
29
+ "@fastify/url-data": "6.0.4",
28
30
  "fast-glob": "3.3.3"
29
31
  },
30
32
  "devDependencies": {
31
- "@cedarjs/framework-tools": "9.0.0-canary.1784",
32
- "fastify": "5.7.4",
33
- "tsx": "4.21.0",
33
+ "@cedarjs/framework-tools": "9.0.0-canary.3124",
34
+ "fastify": "5.12.3",
34
35
  "typescript": "5.9.3",
35
- "vitest": "3.2.4"
36
+ "vitest": "4.1.11"
37
+ },
38
+ "engines": {
39
+ "node": ">=24"
36
40
  },
37
41
  "publishConfig": {
38
42
  "access": "public"
39
43
  },
40
- "gitHead": "baa47810a7defb73de27fdf513b815d679509b5e"
44
+ "gitHead": "3905ed045508b861b495f8d5630d76c7a157d8f1"
41
45
  }
package/LICENSE DELETED
@@ -1,21 +0,0 @@
1
- MIT License
2
-
3
- Copyright (c) 2025 Cedar
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.