@cocreate/file-server 1.18.3 → 1.18.5
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/CHANGELOG.md +16 -0
- package/package.json +1 -9
- package/src/index.js +64 -17
package/CHANGELOG.md
CHANGED
|
@@ -1,3 +1,19 @@
|
|
|
1
|
+
## [1.18.5](https://github.com/CoCreate-app/CoCreate-file-server/compare/v1.18.4...v1.18.5) (2025-09-02)
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
### Bug Fixes
|
|
5
|
+
|
|
6
|
+
* enhance Cache-Control header handling in sendResponse function ([7b6f29c](https://github.com/CoCreate-app/CoCreate-file-server/commit/7b6f29cbe1511be4fa41670db55747e8ad61bc00))
|
|
7
|
+
|
|
8
|
+
## [1.18.4](https://github.com/CoCreate-app/CoCreate-file-server/compare/v1.18.3...v1.18.4) (2025-09-01)
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
### Bug Fixes
|
|
12
|
+
|
|
13
|
+
* enhance file retrieval with BCP 47 language support and improve fallback logic ([f3f44f8](https://github.com/CoCreate-app/CoCreate-file-server/commit/f3f44f83a7b6403a3a080dc8e040eb0141dcfab1))
|
|
14
|
+
* improve language handling in HTML rendering by conditionally setting langRegion and lang ([ea72c6e](https://github.com/CoCreate-app/CoCreate-file-server/commit/ea72c6eb2519d0564d7af181fcaee387ff5ee0b3))
|
|
15
|
+
* refactor send method to use urlObject and enhance BCP 47 language handling ([c9f8591](https://github.com/CoCreate-app/CoCreate-file-server/commit/c9f859168beebad80df3e46de9cc74a43bbc11b2))
|
|
16
|
+
|
|
1
17
|
## [1.18.3](https://github.com/CoCreate-app/CoCreate-file-server/compare/v1.18.2...v1.18.3) (2025-05-01)
|
|
2
18
|
|
|
3
19
|
|
package/package.json
CHANGED
|
@@ -1,18 +1,10 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@cocreate/file-server",
|
|
3
|
-
"version": "1.18.
|
|
3
|
+
"version": "1.18.5",
|
|
4
4
|
"description": "A simple file-server component in vanilla javascript. Easily configured using HTML5 data-attributes and/or JavaScript API.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"file-server",
|
|
7
|
-
"cocreate",
|
|
8
|
-
"low-code-framework",
|
|
9
|
-
"no-code-framework",
|
|
10
|
-
"cocreatejs",
|
|
11
|
-
"cocreatejs-component",
|
|
12
|
-
"cocreate-framework",
|
|
13
|
-
"no-code",
|
|
14
7
|
"low-code",
|
|
15
|
-
"collaborative-framework",
|
|
16
8
|
"realtime",
|
|
17
9
|
"realtime-framework",
|
|
18
10
|
"collaboration",
|
package/src/index.js
CHANGED
|
@@ -26,9 +26,9 @@ class CoCreateFileSystem {
|
|
|
26
26
|
this.sitemap = sitemap;
|
|
27
27
|
}
|
|
28
28
|
|
|
29
|
-
async send(req, res, crud, organization,
|
|
29
|
+
async send(req, res, crud, organization, urlObject) {
|
|
30
30
|
try {
|
|
31
|
-
const hostname =
|
|
31
|
+
const hostname = urlObject.hostname;
|
|
32
32
|
|
|
33
33
|
let data = {
|
|
34
34
|
method: "object.read",
|
|
@@ -72,12 +72,12 @@ class CoCreateFileSystem {
|
|
|
72
72
|
});
|
|
73
73
|
}
|
|
74
74
|
|
|
75
|
-
let parameters =
|
|
75
|
+
let parameters = urlObject.searchParams;
|
|
76
76
|
if (parameters.size) {
|
|
77
77
|
console.log("parameters", parameters);
|
|
78
78
|
}
|
|
79
79
|
|
|
80
|
-
let pathname =
|
|
80
|
+
let pathname = urlObject.pathname;
|
|
81
81
|
|
|
82
82
|
if (pathname.endsWith("/")) {
|
|
83
83
|
pathname += "index.html";
|
|
@@ -86,7 +86,17 @@ class CoCreateFileSystem {
|
|
|
86
86
|
if (!directory.includes(".")) pathname += "/index.html";
|
|
87
87
|
}
|
|
88
88
|
|
|
89
|
-
|
|
89
|
+
const bcp47Regex = /^\/([a-zA-Z]{2,3}(?:-[a-zA-Z0-9]{2,8})+)\//;
|
|
90
|
+
const match = pathname.match(bcp47Regex);
|
|
91
|
+
let lang, langRegion;
|
|
92
|
+
if (match) {
|
|
93
|
+
langRegion = match[1];
|
|
94
|
+
lang = langRegion.split("-")[0]; // Get just the base language (e.g., 'en', 'es', 'fr')
|
|
95
|
+
let newPathname = pathname.replace(langRegion, lang);
|
|
96
|
+
data.$filter.query.pathname = { $in: [newPathname, pathname] };
|
|
97
|
+
} else {
|
|
98
|
+
data.$filter.query.pathname = pathname;
|
|
99
|
+
}
|
|
90
100
|
|
|
91
101
|
let file;
|
|
92
102
|
if (
|
|
@@ -99,12 +109,15 @@ class CoCreateFileSystem {
|
|
|
99
109
|
"/manifest.webmanifest",
|
|
100
110
|
"/service-worker.js"
|
|
101
111
|
].includes(pathname)
|
|
102
|
-
)
|
|
112
|
+
) {
|
|
103
113
|
file = await getDefaultFile(pathname);
|
|
104
|
-
else
|
|
114
|
+
} else {
|
|
115
|
+
file = await crud.send(data);
|
|
116
|
+
}
|
|
105
117
|
|
|
118
|
+
// --- Wildcard fallback ---
|
|
106
119
|
if (!file || !file.object || !file.object[0]) {
|
|
107
|
-
pathname =
|
|
120
|
+
pathname = urlObject.pathname;
|
|
108
121
|
let lastIndex = pathname.lastIndexOf("/");
|
|
109
122
|
let wildcardPath = pathname.substring(0, lastIndex + 1);
|
|
110
123
|
let wildcard = pathname.substring(lastIndex + 1);
|
|
@@ -137,8 +150,9 @@ class CoCreateFileSystem {
|
|
|
137
150
|
}
|
|
138
151
|
|
|
139
152
|
let src;
|
|
140
|
-
if (file["src"])
|
|
141
|
-
|
|
153
|
+
if (file["src"]) {
|
|
154
|
+
src = file["src"];
|
|
155
|
+
} else {
|
|
142
156
|
let fileSrc = await crud.send({
|
|
143
157
|
method: "object.read",
|
|
144
158
|
host: hostname,
|
|
@@ -179,11 +193,14 @@ class CoCreateFileSystem {
|
|
|
179
193
|
src = Buffer.from(src, "base64");
|
|
180
194
|
} else if (contentType === "text/html") {
|
|
181
195
|
try {
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
)
|
|
196
|
+
file.urlObject = urlObject;
|
|
197
|
+
if (langRegion) {
|
|
198
|
+
file.langRegion = langRegion;
|
|
199
|
+
}
|
|
200
|
+
if (lang) {
|
|
201
|
+
file.lang = lang;
|
|
202
|
+
}
|
|
203
|
+
src = await this.render.HTML(file);
|
|
187
204
|
} catch (err) {
|
|
188
205
|
console.warn("server-side-render: " + err.message);
|
|
189
206
|
}
|
|
@@ -200,11 +217,41 @@ class CoCreateFileSystem {
|
|
|
200
217
|
|
|
201
218
|
function sendResponse(src, statusCode, headers) {
|
|
202
219
|
try {
|
|
220
|
+
let cacheControl;
|
|
221
|
+
if (statusCode >= 400) {
|
|
222
|
+
cacheControl = "no-cache, no-store, must-revalidate";
|
|
223
|
+
} else if (
|
|
224
|
+
file &&
|
|
225
|
+
file["cache-control"] !== undefined &&
|
|
226
|
+
file["cache-control"] !== null
|
|
227
|
+
) {
|
|
228
|
+
const val = file["cache-control"];
|
|
229
|
+
if (
|
|
230
|
+
typeof val === "number" ||
|
|
231
|
+
/^\s*\d+\s*$/.test(val)
|
|
232
|
+
) {
|
|
233
|
+
// If it's numeric (number or numeric string) treat it as max-age.
|
|
234
|
+
cacheControl = `public, max-age=${String(
|
|
235
|
+
val
|
|
236
|
+
).trim()};`;
|
|
237
|
+
} else {
|
|
238
|
+
// use the value verbatim (allow full Cache-Control strings like "no-cache" or "public, max-age=600")
|
|
239
|
+
cacheControl = val;
|
|
240
|
+
}
|
|
241
|
+
} else {
|
|
242
|
+
cacheControl =
|
|
243
|
+
organization["cache-control"] ||
|
|
244
|
+
"public, max-age=3600";
|
|
245
|
+
}
|
|
246
|
+
|
|
247
|
+
// Always override/set Cache-Control header so the response aligns with the file metadata/defaults
|
|
248
|
+
headers["Cache-Control"] = cacheControl;
|
|
249
|
+
|
|
203
250
|
if (src instanceof Uint8Array) {
|
|
204
251
|
src = Buffer.from(src);
|
|
205
252
|
} else if (Buffer.isBuffer(src)) {
|
|
206
|
-
|
|
207
|
-
|
|
253
|
+
// Buffer is fine to send — don't bail out here (previous code returned early)
|
|
254
|
+
// keep src as-is
|
|
208
255
|
} else if (typeof src === "object") {
|
|
209
256
|
src = JSON.stringify(src);
|
|
210
257
|
}
|