@cedarjs/fastify-web 6.0.0-rc.189 → 6.0.0-rc.241

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/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,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"}
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"}
package/dist/web.js CHANGED
@@ -1,6 +1,7 @@
1
1
  // src/web.ts
2
2
  import fs from "node:fs";
3
3
  import path from "path";
4
+ import fastifyCompress from "@fastify/compress";
4
5
  import httpProxy from "@fastify/http-proxy";
5
6
  import fastifyStatic from "@fastify/static";
6
7
  import fastifyUrlData from "@fastify/url-data";
@@ -60,10 +61,24 @@ function isFullyQualifiedUrl(url) {
60
61
  }
61
62
 
62
63
  // src/web.ts
64
+ var ONE_YEAR_IN_SECONDS = 60 * 60 * 24 * 365;
65
+ var HASHED_ASSET_FILENAME = /-[0-9a-f]{8,}\.[^./]+$/i;
63
66
  async function redwoodFastifyWeb(fastify, opts) {
64
67
  const { redwoodOptions, flags } = resolveOptions(opts);
65
68
  fastify.register(fastifyUrlData);
66
- fastify.register(fastifyStatic, { root: getPaths().web.dist });
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
+ });
67
82
  if (redwoodOptions.apiProxyTarget) {
68
83
  fastify.register(httpProxy, {
69
84
  prefix: redwoodOptions.apiUrl,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cedarjs/fastify-web",
3
- "version": "6.0.0-rc.189",
3
+ "version": "6.0.0-rc.241",
4
4
  "repository": {
5
5
  "type": "git",
6
6
  "url": "git+https://github.com/cedarjs/cedar.git",
@@ -22,14 +22,15 @@
22
22
  "test:watch": "vitest watch"
23
23
  },
24
24
  "dependencies": {
25
- "@cedarjs/project-config": "6.0.0-rc.189",
25
+ "@cedarjs/project-config": "6.0.0-rc.241",
26
+ "@fastify/compress": "9.1.1",
26
27
  "@fastify/http-proxy": "11.6.0",
27
28
  "@fastify/static": "8.3.0",
28
29
  "@fastify/url-data": "6.0.3",
29
30
  "fast-glob": "3.3.3"
30
31
  },
31
32
  "devDependencies": {
32
- "@cedarjs/framework-tools": "6.0.0-rc.189",
33
+ "@cedarjs/framework-tools": "6.0.0-rc.241",
33
34
  "fastify": "5.10.0",
34
35
  "typescript": "5.9.3",
35
36
  "vitest": "4.1.10"