@cedarjs/fastify-web 5.0.6 → 5.0.7-next.219
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 +2 -26
- package/dist/web.d.ts.map +1 -1
- package/dist/web.js +34 -55
- package/package.json +10 -9
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
|
-
|
|
30
|
-
0 && (module.exports = {
|
|
6
|
+
export {
|
|
31
7
|
coerceRootPath
|
|
32
|
-
}
|
|
8
|
+
};
|
package/dist/web.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"web.d.ts","sourceRoot":"","sources":["../src/web.ts"],"names":[],"mappings":"
|
|
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,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
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
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
|
-
|
|
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 ??=
|
|
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(
|
|
101
|
-
fastify.register(
|
|
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
|
+
});
|
|
102
82
|
if (redwoodOptions.apiProxyTarget) {
|
|
103
|
-
fastify.register(
|
|
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 (
|
|
137
|
-
cwd:
|
|
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 =
|
|
148
|
-
const fallbackIndexPath =
|
|
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 = !!
|
|
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
|
-
|
|
161
|
-
0 && (module.exports = {
|
|
140
|
+
export {
|
|
162
141
|
coerceRootPath,
|
|
163
142
|
redwoodFastifyWeb
|
|
164
|
-
}
|
|
143
|
+
};
|
package/package.json
CHANGED
|
@@ -1,38 +1,39 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@cedarjs/fastify-web",
|
|
3
|
-
"version": "5.0.
|
|
3
|
+
"version": "5.0.7-next.219",
|
|
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": "
|
|
10
|
+
"type": "module",
|
|
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",
|
|
18
18
|
"build:pack": "yarn pack -o cedarjs-fastify-web.tgz",
|
|
19
|
-
"build:types": "tsc --build --verbose",
|
|
19
|
+
"build:types": "tsc --build --verbose ./tsconfig.build.json",
|
|
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.
|
|
26
|
-
"@fastify/
|
|
25
|
+
"@cedarjs/project-config": "5.0.7-next.219",
|
|
26
|
+
"@fastify/compress": "9.1.1",
|
|
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": "5.0.
|
|
33
|
-
"fastify": "5.
|
|
33
|
+
"@cedarjs/framework-tools": "5.0.7-next.219",
|
|
34
|
+
"fastify": "5.10.0",
|
|
34
35
|
"typescript": "5.9.3",
|
|
35
|
-
"vitest": "
|
|
36
|
+
"vitest": "4.1.10"
|
|
36
37
|
},
|
|
37
38
|
"engines": {
|
|
38
39
|
"node": ">=24"
|