@cocreate/file-server 1.18.8 → 1.18.9
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 +7 -0
- package/package.json +1 -1
- package/src/index.js +31 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,3 +1,10 @@
|
|
|
1
|
+
## [1.18.9](https://github.com/CoCreate-app/CoCreate-file-server/compare/v1.18.8...v1.18.9) (2025-10-11)
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
### Bug Fixes
|
|
5
|
+
|
|
6
|
+
* add theme detection and handling for preferred color scheme in responses ([484a37c](https://github.com/CoCreate-app/CoCreate-file-server/commit/484a37c3f35b397a3baff0d9dc62c338a0135903))
|
|
7
|
+
|
|
1
8
|
## [1.18.8](https://github.com/CoCreate-app/CoCreate-file-server/compare/v1.18.7...v1.18.8) (2025-10-11)
|
|
2
9
|
|
|
3
10
|
|
package/package.json
CHANGED
package/src/index.js
CHANGED
|
@@ -30,6 +30,24 @@ class CoCreateFileSystem {
|
|
|
30
30
|
try {
|
|
31
31
|
const hostname = urlObject.hostname;
|
|
32
32
|
|
|
33
|
+
// --- determine preferred color scheme from browser headers ---
|
|
34
|
+
let theme;
|
|
35
|
+
const headerValue =
|
|
36
|
+
(req && req.headers && (
|
|
37
|
+
req.headers["sec-ch-prefers-color-scheme"] ||
|
|
38
|
+
req.headers["prefers-color-scheme"] ||
|
|
39
|
+
req.headers["x-prefers-color-scheme"] ||
|
|
40
|
+
req.headers["x-color-scheme"]
|
|
41
|
+
));
|
|
42
|
+
if (typeof headerValue === "string") {
|
|
43
|
+
// take first token, strip quotes, normalize
|
|
44
|
+
const token = headerValue.split(",")[0].trim().replace(/^"|"$/g, "").toLowerCase();
|
|
45
|
+
if (token === "dark" || token === "light") theme = token;
|
|
46
|
+
}
|
|
47
|
+
// optional: expose detected theme to clients / downstream code
|
|
48
|
+
if (theme) res.setHeader("X-Preferred-Color-Scheme", theme);
|
|
49
|
+
// --- end theme detection ---
|
|
50
|
+
|
|
33
51
|
let data = {
|
|
34
52
|
method: "object.read",
|
|
35
53
|
host: hostname,
|
|
@@ -239,12 +257,14 @@ class CoCreateFileSystem {
|
|
|
239
257
|
try {
|
|
240
258
|
let data = {};
|
|
241
259
|
|
|
260
|
+
// pass detected theme (may be undefined) into server-side renderer
|
|
242
261
|
src = await this.render.HTML(
|
|
243
262
|
file,
|
|
244
263
|
organization,
|
|
245
264
|
urlObject,
|
|
246
265
|
langRegion,
|
|
247
|
-
lang
|
|
266
|
+
lang,
|
|
267
|
+
theme
|
|
248
268
|
);
|
|
249
269
|
} catch (err) {
|
|
250
270
|
console.warn("server-side-render: " + err.message);
|
|
@@ -289,6 +309,16 @@ class CoCreateFileSystem {
|
|
|
289
309
|
|
|
290
310
|
// Always override/set Cache-Control header so the response aligns with the file metadata/defaults
|
|
291
311
|
headers["Cache-Control"] = cacheControl;
|
|
312
|
+
// Advertise that we accept the Sec-CH-Prefers-Color-Scheme client hint.
|
|
313
|
+
// After the browser sees this in a response it may include
|
|
314
|
+
// the Sec-CH-Prefers-Color-Scheme header on subsequent requests.
|
|
315
|
+
headers["Accept-CH"] = "Sec-CH-Prefers-Color-Scheme";
|
|
316
|
+
// optional: tell browser how long to remember this preference (seconds)
|
|
317
|
+
headers["Accept-CH-Lifetime"] = "86400";
|
|
318
|
+
// ensure caches/proxies vary responses by this hint
|
|
319
|
+
headers["Vary"] = headers["Vary"]
|
|
320
|
+
? headers["Vary"] + ", Sec-CH-Prefers-Color-Scheme"
|
|
321
|
+
: "Sec-CH-Prefers-Color-Scheme";
|
|
292
322
|
|
|
293
323
|
if (src instanceof Uint8Array || Buffer.isBuffer(src)) {
|
|
294
324
|
// Ensure binary data is sent as-is
|