@cedarjs/fastify-web 5.0.7-next.338 → 5.0.7

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,8 +1,32 @@
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);
1
24
  function coerceRootPath(path) {
2
25
  const prefix = !path.startsWith("/") ? "/" : "";
3
26
  const suffix = !path.endsWith("/") ? "/" : "";
4
27
  return `${prefix}${path}${suffix}`;
5
28
  }
6
- export {
29
+ // Annotate the CommonJS export names for ESM import in node:
30
+ 0 && (module.exports = {
7
31
  coerceRootPath
8
- };
32
+ });
package/dist/web.d.ts.map CHANGED
@@ -1 +1 @@
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,iBA0I/B"}
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,cAAc,CAAA;AAE7C,OAAO,KAAK,EAAE,wBAAwB,EAAE,MAAM,YAAY,CAAA;AAE1D,OAAO,EAAE,cAAc,EAAE,CAAA;AACzB,YAAY,EAAE,wBAAwB,EAAE,CAAA;AAExC,wBAAsB,iBAAiB,CACrC,OAAO,EAAE,eAAe,EACxB,IAAI,EAAE,wBAAwB,iBA0G/B"}
package/dist/web.js CHANGED
@@ -1,12 +1,46 @@
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
+
1
30
  // src/web.ts
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";
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");
10
44
 
11
45
  // src/helpers.ts
12
46
  function coerceRootPath(path2) {
@@ -16,13 +50,13 @@ function coerceRootPath(path2) {
16
50
  }
17
51
 
18
52
  // src/resolveOptions.ts
19
- import { getConfig } from "@cedarjs/project-config";
53
+ var import_project_config = require("@cedarjs/project-config");
20
54
  function resolveOptions(options) {
21
55
  const redwoodOptions = options.redwood ?? {};
22
56
  const flags = {
23
57
  shouldRegisterApiUrl: false
24
58
  };
25
- redwoodOptions.apiUrl ??= getConfig().web.apiUrl;
59
+ redwoodOptions.apiUrl ??= (0, import_project_config.getConfig)().web.apiUrl;
26
60
  const apiUrlIsFullyQualifiedUrl = isFullyQualifiedUrl(redwoodOptions.apiUrl);
27
61
  if (redwoodOptions.apiHost && !redwoodOptions.apiProxyTarget) {
28
62
  redwoodOptions.apiProxyTarget = redwoodOptions.apiHost;
@@ -61,26 +95,12 @@ function isFullyQualifiedUrl(url) {
61
95
  }
62
96
 
63
97
  // src/web.ts
64
- var ONE_YEAR_IN_SECONDS = 60 * 60 * 24 * 365;
65
- var HASHED_ASSET_FILENAME = /-[0-9a-f]{8,}\.[^./]+$/i;
66
98
  async function redwoodFastifyWeb(fastify, opts) {
67
99
  const { redwoodOptions, flags } = resolveOptions(opts);
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: (res, filePath) => {
75
- const isHashedAsset = filePath.startsWith(assetsDir) && HASHED_ASSET_FILENAME.test(path.basename(filePath));
76
- res.setHeader(
77
- "Cache-Control",
78
- isHashedAsset ? `public, max-age=${ONE_YEAR_IN_SECONDS}, immutable` : "no-cache"
79
- );
80
- }
81
- });
100
+ fastify.register(import_url_data.default);
101
+ fastify.register(import_static.default, { root: (0, import_project_config2.getPaths)().web.dist });
82
102
  if (redwoodOptions.apiProxyTarget) {
83
- fastify.register(httpProxy, {
103
+ fastify.register(import_http_proxy.default, {
84
104
  prefix: redwoodOptions.apiUrl,
85
105
  upstream: redwoodOptions.apiProxyTarget,
86
106
  disableCache: true,
@@ -113,8 +133,8 @@ async function redwoodFastifyWeb(fastify, opts) {
113
133
  fastify.all(apiUrlWarningPath, apiUrlHandler);
114
134
  fastify.all(`${apiUrlWarningPath}*`, apiUrlHandler);
115
135
  }
116
- const prerenderedFiles = await fg("**/*.html", {
117
- cwd: getPaths().web.dist,
136
+ const prerenderedFiles = await (0, import_fast_glob.default)("**/*.html", {
137
+ cwd: (0, import_project_config2.getPaths)().web.dist,
118
138
  ignore: ["index.html", "200.html", "404.html"]
119
139
  });
120
140
  for (const prerenderedFile of prerenderedFiles) {
@@ -124,11 +144,11 @@ async function redwoodFastifyWeb(fastify, opts) {
124
144
  reply.sendFile(prerenderedFile);
125
145
  });
126
146
  }
127
- const prerenderIndexPath = path.join(getPaths().web.dist, "200.html");
128
- const fallbackIndexPath = fs.existsSync(prerenderIndexPath) ? "200.html" : "index.html";
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";
129
149
  fastify.setNotFoundHandler({}, (req, reply) => {
130
150
  const urlData = req.urlData();
131
- const requestHasExtension = !!path.extname(urlData.path ?? "");
151
+ const requestHasExtension = !!import_path.default.extname(urlData.path ?? "");
132
152
  if (requestHasExtension && urlData.path?.startsWith("/assets/")) {
133
153
  reply.code(404);
134
154
  return reply.send("Not Found");
@@ -137,7 +157,8 @@ async function redwoodFastifyWeb(fastify, opts) {
137
157
  return reply.sendFile(fallbackIndexPath);
138
158
  });
139
159
  }
140
- export {
160
+ // Annotate the CommonJS export names for ESM import in node:
161
+ 0 && (module.exports = {
141
162
  coerceRootPath,
142
163
  redwoodFastifyWeb
143
- };
164
+ });
package/package.json CHANGED
@@ -1,39 +1,38 @@
1
1
  {
2
2
  "name": "@cedarjs/fastify-web",
3
- "version": "5.0.7-next.338",
3
+ "version": "5.0.7",
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
+ "type": "commonjs",
11
11
  "main": "./dist/web.js",
12
12
  "types": "./dist/web.d.ts",
13
13
  "files": [
14
14
  "dist"
15
15
  ],
16
16
  "scripts": {
17
- "build": "node ./build.mts",
17
+ "build": "node ./build.mts && yarn build:types",
18
18
  "build:pack": "yarn pack -o cedarjs-fastify-web.tgz",
19
- "build:types": "tsc --build --verbose ./tsconfig.build.json",
19
+ "build:types": "tsc --build --verbose",
20
20
  "prepublishOnly": "NODE_ENV=production yarn build",
21
21
  "test": "vitest run",
22
22
  "test:watch": "vitest watch"
23
23
  },
24
24
  "dependencies": {
25
- "@cedarjs/project-config": "5.0.7-next.338",
26
- "@fastify/compress": "9.2.0",
27
- "@fastify/http-proxy": "11.6.0",
25
+ "@cedarjs/project-config": "5.0.7",
26
+ "@fastify/http-proxy": "11.5.0",
28
27
  "@fastify/static": "8.3.0",
29
- "@fastify/url-data": "6.0.4",
28
+ "@fastify/url-data": "6.0.3",
30
29
  "fast-glob": "3.3.3"
31
30
  },
32
31
  "devDependencies": {
33
- "@cedarjs/framework-tools": "5.0.7-next.338",
34
- "fastify": "5.12.0",
32
+ "@cedarjs/framework-tools": "5.0.7",
33
+ "fastify": "5.8.5",
35
34
  "typescript": "5.9.3",
36
- "vitest": "4.1.10"
35
+ "vitest": "3.2.6"
37
36
  },
38
37
  "engines": {
39
38
  "node": ">=24"